6 kyu

Calculating Expected Utility

Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    Besides the annoying rounding issues it's great having these sort of katas with all of these theoretical concepts.

  • saudiGuy Avatar

    Python: Random tests are vulnerable to input modification

  • RealKenshiro Avatar
    1. Confusing description. For warriors who want to tackle this problem, please refer to https://nashpy.readthedocs.io/en/stable/discussion/strategies.html for a real example.
    2. Some very annoying rounding issues.
  • Voile Avatar

    The kata needs to be rewritten with assertApproxEquals instead of rounding 2 decimal places, because the tests keep hitting the rounding boundary with the random tests, which means floating point error is significant here.

  • user9644768 Avatar

    Ruby 3.0 should be enabled. KaTeX should be used.

  • Len512 Avatar

    Encountered rounding issues in the JS version. I had to try submitting several times before passing the tests (1 or 2 fails each time). For example :

    0.44499999999999995 Expected 0.45
    0.09499999999999993 Expected 0.09
    0.26499999999999996 Expected 0.26
    
    -0.325 Expected -0.32
    -0.375 Expected -0.38
    
  • Blind4Basics Avatar

    The description is awfully bad: please considere that every warrior didn't study such a field, so make it understandable.

    ... where each dimension has rows/columns corresponding to a single player's actions, each table entry contains a vector of utilities (a.k.a, payoffs or rewards) for each player. 
    The payoff table for Rock-Paper-Scissors is as follows:
    
     | R   |P   |S
    R| 0,0 |-1,1|1,-1 
    P|1,-1 | 0,0|-1,1
    S|-1,1 |1,-1| 0,0
    

    First, you don't say which one of the players is in row/column. Secondly, neither do you say how we are supposed to read those tuples.

    Which can be expressed in python as follows:
    
    utilities = [[0,-1,1],[1,0,-1],[-1,1,0]]
    

    ...there I was like... "WTF!?" => strictly speaking, you're telling that a list of lists of integers is the same as a list of lists of tuples of integers. That clearly needs to be explained, how you go from the first to the second (not that hard to figure out, but hell, that's your job to explain this, not the warroir).

    Edit: btw -> "can be expressed in python as..." -> make the description as much "language free" as possible.


    • It's not explained anywhere what p0 and p1 are!
    • about that, the sample tests aren't helpfull at all since they provide only integers. Would need to add one or two examples with floating point values This way, it could be more evident that they are probabilities...

    Description: ...

    -> that, we can already guess. What would be more useful is that you split the description in "Context" and "Task"

  • GiacomoSorbi Avatar

    Cool kata with some economy-flavor (I studied that), brilliant explanation and created by the most restless quoran I had the fortune to met? I'm game ;)

    If you don't mind, I will translate this nice work of yours into both JS and Ruby soon :)

    [I must admit I was almost certain that you would have gone for a list comprehension solution, must be my competitive glands firing all they have got :D]

    • GiacomoSorbi Avatar

      And JS translation just submitted, if you wish to approve it.

      I noticed that you didn't follow naming conventions in Python (using camel_case it should be expected_utility); I know I am nitpicky here, but kind users like bkaes-senpai made me understand the importance of commong guidelines, plus I can fix it for you if you wish; same goes for adding a bit of random tests, if you don't mind: creating them in JS was surely fun :)

      Edit: Ruby version delivered too :)

    • russelljjadams Avatar

      You know, I go through weird phases where camel_case feels right, and other times when it just looks ugly. But you're right, to be more Pythonic it should be expected_utility. And it would be helpful if you were to help add some tests. I wrote it rather late last night and I planned to go back through and add some more tests.

    • russelljjadams Avatar

      I know, I know. My argument is that it was really late when I started writing this kata, idk what I was thinking!

    • GiacomoSorbi Avatar

      Been there, done that too ;)

      You were really quick in fixing the kata; I also fixed the description with the camel case, and will add the random tests tomorrow; meanwhile thanks for approving my work and trusting me with more tests :)

      Edit: on a second thought, I preferred to finish the work now; if you wish, go for some test run and let me know if they are up to your standards; otherwise no problem in fixing them.