6 kyu

T.T.T.44: A game of Grab the "red envelope"(抢红包游戏)

Description
Loading description...
Puzzles
Games
  • Please sign in or sign up to leave a comment.
  • ejini战神 Avatar

    Manage to come across this kata during CNY eve,which is a blessing for the upcoming year!

    PS: ~~~ 新年快乐 恭喜发财 红包拿来 (❁´◡`❁) 🐇👲🧧

  • Voile Avatar

    I don't think any of the tests is correct in this kata:

    Currently the fixed tests and the reference solution expect this:

    1. Add money
    2. If this is not first turn, update lucky guy
    3. Deduct money from lucky guy
    4. If someone is bankrupt(?), end the game
    

    Which is completely different from what is stated in the descriptions. The lucky man sequence in the first example is 1,3,2,3 (the 1 comes from the beginning), which happens to be the same in both cases because 1,3,2,(-3-) is the same as 1,(-3-),2,3 (where (-x-) means ignore that number). They are, of course, different in the second example (the stated procedure ends at turn 38) and mostly different in the random tests.

    The correct procedure should be this (as mentioned by myjinxin in the comments below):

    1. Deduct money from lucky guy
    2. Add money
    3. Update lucky guy
    4. If someone is bankrupt(?), end the game
    

    That also means you'll have to recompute the fixed tests, rewrite the descriptions and invalidate all solutions so far, but that's probably not a big deal.

    • myjinxin2015 Avatar

      I think there is no problem with the fixed tests and the reference solution. What's your correct results of the fixed tests? ;-)

    • Voile Avatar

      The result of the second fixed test using the stated procedure is [946.4, 2237, 2361.5, 2390.2, 2064.9].

      Here's a step-by-step log:

      Turn | Lucky guy | Money this round | Total money
      0 0 [ 44.1, 24.4, 8, 2.4, 21.1 ] [ 1944.1, 2024.4, 2008, 2002.4, 2021.1 ]
      1 4 [ 18.2, 14.5, 8.1, 21.5, 37.7 ] [ 1862.3, 2038.9, 2016.1, 2023.9, 2058.8 ]
      2 4 [ 21.6, 2.6, 6.6, 25.4, 43.8 ] [ 1883.9, 2041.5, 2022.7, 2049.3, 2002.6 ]
      3 0 [ 44.2, 19.6, 10.2, 9.2, 16.8 ] [ 1928.1, 2061.1, 2032.9, 2058.5, 1919.4 ]
      4 1 [ 10.8, 39.4, 21, 1.4, 27.4 ] [ 1838.9, 2100.5, 2053.9, 2059.9, 1946.8 ]
      5 4 [ 5.3, 37.2, 2.1, 5.7, 49.7 ] [ 1844.2, 2037.7, 2056, 2065.6, 1996.5 ]
      6 4 [ 11.3, 22.9, 21.5, 19.9, 24.4 ] [ 1855.5, 2060.6, 2077.5, 2085.5, 1920.9 ]
      7 1 [ 15.3, 41.5, 15.9, 2.9, 24.4 ] [ 1870.8, 2102.1, 2093.4, 2088.4, 1845.3 ]
      8 0 [ 42.8, 4.8, 5, 8.4, 39 ] [ 1913.6, 2006.9, 2098.4, 2096.8, 1884.3 ]
      9 0 [ 34.9, 2.2, 31.6, 5.7, 25.6 ] [ 1848.5, 2009.1, 2130, 2102.5, 1909.9 ]
      10 0 [ 45.7, 7.5, 19.6, 9.8, 17.4 ] [ 1794.2, 2016.6, 2149.6, 2112.3, 1927.3 ]
      11 4 [ 11.9, 17.4, 3.4, 9.2, 58.1 ] [ 1706.1, 2034, 2153, 2121.5, 1985.4 ]
      12 0 [ 29.8, 23.4, 18, 9.4, 19.4 ] [ 1735.9, 2057.4, 2171, 2130.9, 1904.8 ]
      13 2 [ 13.8, 4.8, 33.8, 17, 30.6 ] [ 1649.7, 2062.2, 2204.8, 2147.9, 1935.4 ]
      14 0 [ 44.1, 17.4, 13.6, 9.7, 15.2 ] [ 1693.8, 2079.6, 2118.4, 2157.6, 1950.6 ]
      15 2 [ 6.6, 9, 38.8, 8.9, 36.7 ] [ 1600.4, 2088.6, 2157.2, 2166.5, 1987.3 ]
      16 4 [ 2.4, 23.9, 7.2, 16.5, 50 ] [ 1602.8, 2112.5, 2064.4, 2183, 2037.3 ]
      17 0 [ 48.5, 9.2, 21.5, 6.1, 14.7 ] [ 1651.3, 2121.7, 2085.9, 2189.1, 1952 ]
      18 1 [ 9, 34.5, 27, 9.3, 20.2 ] [ 1560.3, 2156.2, 2112.9, 2198.4, 1972.2 ]
      19 4 [ 34.2, 16.7, 3.3, 1.1, 44.7 ] [ 1594.5, 2072.9, 2116.2, 2199.5, 2016.9 ]
      20 0 [ 46.3, 2.9, 21, 1.8, 28 ] [ 1640.8, 2075.8, 2137.2, 2201.3, 1944.9 ]
      21 1 [ 20.9, 34.8, 8.6, 1.1, 34.6 ] [ 1561.7, 2110.6, 2145.8, 2202.4, 1979.5 ]
      22 0 [ 36, 18.4, 21.6, 6.5, 17.5 ] [ 1597.7, 2029, 2167.4, 2208.9, 1997 ]
      23 4 [ 11.2, 13, 19.3, 21, 35.5 ] [ 1508.9, 2042, 2186.7, 2229.9, 2032.5 ]
      24 4 [ 31, 4.7, 11.8, 9.6, 42.9 ] [ 1539.9, 2046.7, 2198.5, 2239.5, 1975.4 ]
      25 0 [ 49.1, 4.4, 1.8, 20.7, 24 ] [ 1589, 2051.1, 2200.3, 2260.2, 1899.4 ]
      26 4 [ 16.2, 9.9, 10.1, 23.3, 40.5 ] [ 1505.2, 2061, 2210.4, 2283.5, 1939.9 ]
      27 0 [ 50.4, 10.1, 12.5, 12.1, 14.9 ] [ 1555.6, 2071.1, 2222.9, 2295.6, 1854.8 ]
      28 0 [ 42.2, 22.9, 9.3, 11.5, 14.1 ] [ 1497.8, 2094, 2232.2, 2307.1, 1868.9 ]
      29 0 [ 39.4, 21.8, 10.2, 6, 22.6 ] [ 1437.2, 2115.8, 2242.4, 2313.1, 1891.5 ]
      30 4 [ 10.7, 6.1, 23.8, 19.6, 39.8 ] [ 1347.9, 2121.9, 2266.2, 2332.7, 1931.3 ]
      31 0 [ 31.9, 7.6, 15.9, 22.6, 22 ] [ 1379.8, 2129.5, 2282.1, 2355.3, 1853.3 ]
      32 0 [ 36.5, 25, 20.1, 2.5, 15.9 ] [ 1316.3, 2154.5, 2302.2, 2357.8, 1869.2 ]
      33 0 [ 49.7, 25.1, 5.6, 2.2, 17.4 ] [ 1266, 2179.6, 2307.8, 2360, 1886.6 ]
      34 0 [ 48.7, 11.9, 4.6, 1.4, 33.4 ] [ 1214.7, 2191.5, 2312.4, 2361.4, 1920 ]
      35 0 [ 38.1, 9.1, 13.5, 8.5, 30.8 ] [ 1152.8, 2200.6, 2325.9, 2369.9, 1950.8 ]
      36 0 [ 44.6, 6.8, 7.2, 4.2, 37.2 ] [ 1097.4, 2207.4, 2333.1, 2374.1, 1988 ]
      37 0 [ 43.2, 10.2, 17.8, 1.4, 27.4 ] [ 1040.6, 2217.6, 2350.9, 2375.5, 2015.4 ]
      38 4 [ 5.8, 19.4, 10.6, 14.7, 49.5 ] [ 946.4, 2237, 2361.5, 2390.2, 2064.9 ]
      
    • myjinxin2015 Avatar

      OK. Code and tests Changed.

      Issue marked resolved by myjinxin2015 8 years ago
  • mikalai-sauchanka Avatar

    For me picking the lucky-man description is confusing... According to the solutions, the first 'grab' is ignored (the lucky-man is starting to be picked from the 1st 'grab'). So right now:

     for [18.5,20,21.5,19,21],[22.3,55,11,8,4.7] -> [ 1940.8, 1975, 2032.5, 2027, 2025.7 ]
    

    notice that after the first grab the lucky-man should be index 2, instead it's 1 (picked from the next grab).

  • smile67 Avatar

    This comment has been hidden.

    • myjinxin2015 Avatar

      no computer now, can not test your code. in my code, I round them at the last step.

    • smile67 Avatar

      This comment has been hidden.

    • myjinxin2015 Avatar

      what's the last s in the var line mean?

    • smile67 Avatar

      This comment has been hidden.

    • myjinxin2015 Avatar

      Oh, I see what's happening...

      The difference lies in the understanding of the "lucky man".

      I mean people who get the most money at each round is the "lucky man". But in your code, it seems choose the person who has the Maximum total amount.

      Perhaps my description is not clear enough, now you can understand what I mean?

    • smile67 Avatar

      Yes, you are right;-)... So i will change the code and see what happens;-)! Many thanks and perhaps it's really a point for your description (or maybe i was too quick again;-))...

      Question marked resolved by smile67 9 years ago
    • myjinxin2015 Avatar

      perhaps I should add something to this point ;-)

    • smile67 Avatar

      Can test it later again, just on the way to sports;-)...

    • smile67 Avatar

      This comment has been hidden.

    • myjinxin2015 Avatar

      modified the description to:

      The game is over? No, this is just the beginning. They need to elect a person to continue the process above. In the red envelopes of last round, who grabbed the most money in the red envelopes($100), who was called the "lucky man". The "lucky man" needs to send the next red envelope with the same total amount($100) and the same pieces(5).

      Is this more clear? I don't know if my grammar and expressions are correct, because of my bad English ;-)

    • myjinxin2015 Avatar

      just a easy way, for example: at one round, send $100, five person grab: [44.1,24.4,8,2.4,21.1], the man who grabed 44.1 is the "lucky man". he need send $100 at next round.

    • smile67 Avatar

      What means "with the same pieces", you mean the next array of pieces always of same amount (5)? The one who was lucky man can never be lucky man on next stage, because of "-100"?? Or isn't it counted here?

    • myjinxin2015 Avatar

      you should elect "lucky man" first, and then send the next $100. you reduce the $100(it's the money of next round) in front of elect, so you ignore the possibility that this person will continue to be a "lucky man"(his money always be negative number).

    • smile67 Avatar

      Have it now, was not so easy to understand, wait a moment and i give you the solution... I'm not at home, so it's a little bit difficult;-)....

    • myjinxin2015 Avatar

      the process is:

      send $100
      --->five man grab money([44.1,24.4,8,2.4,21.1])
      --->elect "lucky man"(first man grab $44.1, so he is the "lucky man", because he grab the most money of $100,
          in fact, he is the "unlucky man", because the last $100 is also send by him)
      --->send the next $100
      --->five man grab money([18.2,14.5,8.1,21.5,37.7])
      --->37.7 === lucky man
      --->and so on...
      
    • smile67 Avatar

      Code works now... Sorry for the delay, as days before always cw errors and timeouts, so difficult to test and submit the solution. It's was not so easy, i think (for me) the description wasn't clear in some simple points. So here the questions/answers really helped;-)! It's important to say, that the choice of the "lucky man" only depends on the input arrays and nothing more, i think... (i was calculating something, which was wrong)

    • smile67 Avatar

      So see you later on... just doing my sports now;-)!

    • myjinxin2015 Avatar

      See you later, Mr.eight-packs ;-)

    • smile67 Avatar

      Yes, just back again;-)... so i think i should say "good night" to you;-)! Thanks again for your help, the problem wasn't the kata, but the description (for me), so nice to see the many tries of different solutions;-)... Perhaps it helps others to solve it!