Code Golf: Creepy Relationships!

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:

https://gist.github.com/IT-Delinquent/930f8aff2cbb5c6704c590425fcdad09

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.

https://gist.github.com/IT-Delinquent/1d39173e2652714beb6e0ef7c3ef42a7

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)}

Try it online!

Thanks for reading!

Leave a Comment

Your email address will not be published. Required fields are marked *

email popup image
Mark Harwood
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
Subscribe
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
Fill Out This Form, And I Will Be In Touch Shortly
Contact form image
I'll Be In Touch Soon