3 ms·
I'd disagree here; I still think it's quite elegant. For example, in python, it would look something like from itertools import combinations magic_square
by chrisshroba 8y ago
I'd disagree here; I still think it's quite elegant. For example, in python, it would look something like
from itertools import combinations
magic_square = [2,7,6,
9,5,1,
4,3,8]
def did_user_win(moves):
# Convert moves to magic square values
magic_values = [magic_square[move] for move in moves]
# Check if any sum of three moves equals 15
for three_values in combinations(magic_values,3):
if sum(three_values) == 15: return True
return False
- laurentl 8y agoPoint taken. I love itertools :D