Weekend geek challenge

Here’s a fun little challenge from Kevin Avila:

Write a function that takes an int parameter. When passed a 1, it returns 3. When passed a 3, return 1. 

Now write it again, but avoid any of the approaches you used in the first function

Repeat for as long as you have free time.

I’ve gisted my “went as long as I could before kids coming home from school prevented me from continuing” here.


  • https://gist.github.com/dkerzig/2877dd2a880fb3dad449

    With foo8 as a homage to the current NSHipster-Article 😀

    • You got the foo0 right off the top. Took me to f9 to get that one. I think your foo9 is especially beautiful. Well done.

  • Actually my first guess was “-1*(n-2)+2” but then I saw the simplification!