Sort by

recency

|

20 Discussions

|

  • + 0 comments

    I can't understand what "optimally" means.

  • + 0 comments

    IIXXIIIIII if my turn is first how can i win if i and my friend knockdown all two pins which are adjacent to each other

    II - my turn XX -skipped II - his turn II - myturn II -his turn

  • + 1 comment

    Here is Bowling Pins problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-bowling-pins-problem-solution.html

    • + 0 comments

      Took a look at your python solution:
      While it is fine and fast, it doesn't use recursion.
      (I guess, all this problems in the 'Recursion' category are meant as an exercise how to make proficient use of recursion.)

      Here is some recursive solution in python:

      from functools import cache, reduce
      from operator import xor
      
      def mex(seq):
          vals, ret = set(seq), 0
          while ret in vals: ret += 1
          return ret
      @cache
      def nim(run):
          reachable = []
          reachable.extend(nim(i) ^ nim(run-i-1) for i in range(0,(run+1)//2))
          reachable.extend(nim(i) ^ nim(run-i-2) for i in range(0,run//2))
          return mex(reachable)
      
      def isWinning(n, config):
          # Return WIN or LOSE depending on whether you will win        
          runs = list(map(len, config.replace("X", ' ').split()))
          return "WIN" if reduce(xor, map(nim, runs)) else "LOSE"
      
  • + 0 comments

    Hello! I've left my Java 8 solution here in case anyone has trouble.

    Just keep in mind: - GrundyNumbers. - Minimum Excludant. - GrundyNumber of multiple games is the XOR of the grundy numbers of the games. - You only have to evaluate a state once.

  • + 1 comment

    Hey, I'm trying to solve this problem. I studied the combinational game theory but I find something confusing. If i have three pins. III mex{1,2} = 0 means LOSE. But I can knock down the middle pin and it will be IXI for the next player he/she can only knock either the left or right so I will it will be a WIN. Am I implementing the game theory wrong or...?

    • + 0 comments

      III mex{0,1,2} = 3 means Win. Since mex of grundy numbers of all sub games. IXX = 1, IIX =2, IXI =0. You missed the grundy number of state IXI.