Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They asked the subjects to write a Rock Paper Scissors game in python. Then asked programmers to mark what people did. They unfortunately didn't provide the source code the subjects wrote.

From what I've seen online this is done with an if/else tree which is very far from a good solution.

The way I would model this is with a group [0]. Something you can't possibly see without a very substantial background in mathematics.

Programming has as much to do with learning a programming language as novel writing has to do with learning punctuation.

[0] in Python3.6+:

    import random

    class hand:
        wins = {'r': {'r': 'r', 'p': 'p', 's': 'r'},
                'p': {'r': 'p', 'p': 'p', 's': 's'},
                's': {'r': 'r', 'p': 's', 's': 's'}}
        def __init__(self):
            self.value = random.choice(list(hand.wins.keys()))
        def assign(self):
            value = input("enter r, p or s: ")
            assert value in hand.wins.keys()
            self.value = value
        def __mul__(self, other):
            return hand.wins[self.value][other.value]
    
    if __name__ == "__main__":
        for i in range(10):
            h1 = hand()
            h2 = hand()
            print(f"{h1.value} * {h2.value} = {h1 * h2}")


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: