Been a while!
Just over a year since my last post, I never intended to leave it this long ???????? A lot has happened in that time but I’m back today with another short example of PowerShell wizardry.
Maybe that isn’t the correct term since I wrote the code… seems a bit boastful!
Anyway, I came across a Code Golf issue that I wanted to sink my teeth into ⛳
A lot of the Code Golf issues are too long, complex or just boring for me. Especially, with a full time day job and a family, it’s hard to find time. But I love PowerShell and love beating it into an ever shrinking golf hole when possible! ????
So I came across this issue, which was a super simple calculation really. The premise was creepy relationships. Basically, describing relationships with a large age gap as creepy…
Whilst I did fail to get the code down to Python or C# levels, I think I did pretty good at just 60 bytes. You can view my submission here, but I will explain it in this post too.
For all golfing submissions, I like to get the basic premise first to make sure I understand the issue and can solve it. This was it’s easier to debug later on. Also you feel like a wizard removing bytes and shortening the code.
This is what I had first come up with:
This came out at 68 bytes. Not good enough, even with removing extra lines etc it wasn’t going to cut it.
So I option for the ever popular nameless function instead and to call it using the footer.
The above is how my code finished and what I submitted to Code Golf.
I’m happy with it. I can’t find a way to make it smaller but I’m sure someone will! ????
PowerShell, 60 bytes
$c={param($a,$b)[math]::max($a,$b)/2+7-gt[math]::min($a,$b)}
Thanks for reading!