Skip to main content
added 793 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

ES6, 57 bytes

a=>(g=n=>a.map((x,i)=>i&&x[3]==n&&++c&&g(i)),g(c=0),c>11) 

This works because only the cards on the bottom of piles 1-12 are relevant, and they need to form a directed graph back to pile 0. So, I count the number of piles whose bottom card is 30, then the number of piles whose bottom card was one of the piles I counted earlier, etc. If I reach 12 piles then the configuration is a winning one.

Outline proof:

The game always ends when you turn over the last 0, since that pile effectively has one fewer card than the others.

If the bottom cards on piles 1-12 form a directed graph to pile 0, then in order to clear pile 0, we have to clear all the piles whose last entry is 0, and so on recursively to all the piles we have to clear so that we can clear the piles whose last entry is 0, and so forth. The configuration is therefore a winning one.

If the cards on the bottom of piles 1-12 do not form a directed graph to pile 0, there must exist at least one cycle. No pile in this cycle can be cleared, since it depends on the previous pile in the cycle. (In the case of a cycle of length 2, this is a chicken-and-egg situation.) The configuration is therefore a losing one.

ES6, 57 bytes

a=>(g=n=>a.map((x,i)=>i&&x[3]==n&&++c&&g(i)),g(c=0),c>11) 

This works because only the cards on the bottom of piles 1-12 are relevant, and they need to form a directed graph back to pile 0. So, I count the number of piles whose bottom card is 3, then the number of piles whose bottom card was one of the piles I counted earlier, etc. If I reach 12 piles then the configuration is a winning one.

ES6, 57 bytes

a=>(g=n=>a.map((x,i)=>i&&x[3]==n&&++c&&g(i)),g(c=0),c>11) 

This works because only the cards on the bottom of piles 1-12 are relevant, and they need to form a directed graph back to pile 0. So, I count the number of piles whose bottom card is 0, then the number of piles whose bottom card was one of the piles I counted earlier, etc. If I reach 12 piles then the configuration is a winning one.

Outline proof:

The game always ends when you turn over the last 0, since that pile effectively has one fewer card than the others.

If the bottom cards on piles 1-12 form a directed graph to pile 0, then in order to clear pile 0, we have to clear all the piles whose last entry is 0, and so on recursively to all the piles we have to clear so that we can clear the piles whose last entry is 0, and so forth. The configuration is therefore a winning one.

If the cards on the bottom of piles 1-12 do not form a directed graph to pile 0, there must exist at least one cycle. No pile in this cycle can be cleared, since it depends on the previous pile in the cycle. (In the case of a cycle of length 2, this is a chicken-and-egg situation.) The configuration is therefore a losing one.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

ES6, 57 bytes

a=>(g=n=>a.map((x,i)=>i&&x[3]==n&&++c&&g(i)),g(c=0),c>11) 

This works because only the cards on the bottom of piles 1-12 are relevant, and they need to form a directed graph back to pile 0. So, I count the number of piles whose bottom card is 3, then the number of piles whose bottom card was one of the piles I counted earlier, etc. If I reach 12 piles then the configuration is a winning one.