You are on page 1of 1

PCPF EXPERIMENT NO – 10

AIM : Implementation of game of nim in Haskell by applying list processing.

THEORY :
List processing is a list of programming codes, including abstract data structure, used to calculate
specified variables in a certain order. A value may repeat more than once

Inspection and enumeration of static list structures are the only allowed list processing operations,
while item insertion, replacement and deletion operations are only allowed within dynamic lists
processing operations.

mapM_ is useful for executing something only for its side effects. For example, printing a string to
standard output doesn't return anything useful - it returns ( ). If we have a list of three strings, we
would end up accumulating a list [( ), ( ), ( )]. Building this list has a runtime cost, both in terms of
speed and memory usage, so by using mapM_ we can skip this step entirely.

Nim is a combinatorial game, where two players alternately take turns in taking objects from several
heaps. The only rule is that each player must take at least one object on their turn, but they may take
more than one object in a single turn, as long as they all come from the same heap.

Nim is the most well-known example of an impartial game, a game where both players have the same
moves all the time, and thus the only distinguishing feature is that one player goes first. It is also
completely solved, in the sense that the exact strategy has been found for any starting configuration.

Working of the nim game :


You can remove any number of stars from any row, but you have to remove at least 1 star. You cannot
remove stars from row 1 and 2 in the same turn. Person to remove last star wins.

CODE :

OUTPUT:

CONCLUSION:

You might also like