Skip to content

Instantly share code, notes, and snippets.

@bjornharrtell
Created March 19, 2012 18:09
Show Gist options
  • Save bjornharrtell/2122201 to your computer and use it in GitHub Desktop.
Save bjornharrtell/2122201 to your computer and use it in GitHub Desktop.
This works! :) and is now a one-liner! :)
if ((delta & 7) > 4) rightOf else leftOf
@petersegerstedt
Copy link

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)

@bjornharrtell
Copy link
Author

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