Created
March 19, 2012 18:09
-
-
Save bjornharrtell/2122201 to your computer and use it in GitHub Desktop.
This works! :) and is now a one-liner! :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ((delta & 7) > 4) rightOf else leftOf |
lolz untested coffescript version:
turn = (first, second) -> if Math.abs(delta) >= 4 then first() else second()
if delta > 0 then turn [rightOf, leftOf]... else turn [leftOf,rightOf]...
Testing on expression "delta & 7 > 4" should also work:
print ' 0'
print ' 7 1'
print '6 2'
print ' 5 3'
print ' 4'
def left_or_right(delta):
if delta == 0: return ''
elif delta & 7 > 4: return 'left'
return 'right'
for start in range(8):
for goto in range(8):
print start, goto, left_or_right(goto - start)
It sure does, which also shortens the code in question to a one liner. Great work Peter! Reminds me that I want to understand bitwise operations better.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shorted down by death of the curly braces... could some functional magic be applied too?