Skip to content

Instantly share code, notes, and snippets.

@higaki
Created August 25, 2016 01:50
Show Gist options
  • Save higaki/236c6ca435336f1c4aec48db34b27162 to your computer and use it in GitHub Desktop.
Save higaki/236c6ca435336f1c4aec48db34b27162 to your computer and use it in GitHub Desktop.
def jangkeng(you, comp)
(you - comp + 4) % 3 - 1;
end
rock, paper, scissors = 0, 1, 2
win, lose, draw = 1, -1, 0
matches = [
# [you, comp, judge]
[rock, rock, draw],
[rock, scissors, win],
[rock, paper, lose],
[paper, paper, draw],
[paper, rock, win],
[paper, scissors, lose],
[scissors, scissors, draw],
[scissors, paper, win],
[scissors, rock, lose],
]
matches.map{|you, com, judge| jangkeng(you, com) == judge}.all? # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment