Skip to main content
added 724 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h

Explanation

Putting the cards face up under another pile is a red herring. We might as well remove them from the game and keep playing until the current pile is empty. So that's what I'm doing: the code simply plays the game until the current pile is empty and then checks if any cards are left.

q~    e# Read and evaluate input.
(     e# Pull off the first (current) pile.
{     e# While the current pile is non-empty...
  (\  e#   Pull off the top card and swap with the remaining pile.
  a   e#   Wrap the pile in an array.
  @+  e#   Prepend it to the list of piles
  1$  e#   Copy the drawn card.
  ff- e#   Subtract it from all all remaining cards.
  m<  e#   Rotate the stack to the left by the drawn card
  (   e#   Pull off the top pile as the new current pile.
}h
*     e# The top pile is empty. Joining the other piles with it, flattens them.
!     e# Logical not, turns an empty array into 1 and a non-empty array into 0.

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h

Putting the cards face up under another pile is a red herring. We might as well remove them from the game and keep playing until the current pile is empty. So that's what I'm doing: the code simply plays the game until the current pile is empty and then checks if any cards are left.

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h

Explanation

Putting the cards face up under another pile is a red herring. We might as well remove them from the game and keep playing until the current pile is empty. So that's what I'm doing: the code simply plays the game until the current pile is empty and then checks if any cards are left.

q~    e# Read and evaluate input.
(     e# Pull off the first (current) pile.
{     e# While the current pile is non-empty...
  (\  e#   Pull off the top card and swap with the remaining pile.
  a   e#   Wrap the pile in an array.
  @+  e#   Prepend it to the list of piles
  1$  e#   Copy the drawn card.
  ff- e#   Subtract it from all all remaining cards.
  m<  e#   Rotate the stack to the left by the drawn card
  (   e#   Pull off the top pile as the new current pile.
}h
*     e# The top pile is empty. Joining the other piles with it, flattens them.
!     e# Logical not, turns an empty array into 1 and a non-empty array into 0.
added 5097 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h

Putting the cards face up under another pile is a red herring. We might as well remove them from the game and keep playing until the current pile is empty. So that's what I'm doing: the code simply plays the game until the current pile is empty and then checks if any cards are left.

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h

Putting the cards face up under another pile is a red herring. We might as well remove them from the game and keep playing until the current pile is empty. So that's what I'm doing: the code simply plays the game until the current pile is empty and then checks if any cards are left.

added 5097 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 2323 21 bytes

q~{({(\a@+1$ff-m<_0=m<(}gsh*!

[Run all test cases.][1] (You'll have to copy them in yourself, because they're too long for a permalink.)Run all test cases.

If the assignment of truthy and falsy was the opposite I could save a whopping 53 bytes:

q~{((\a@+1$ff-m<}h

[1]: http://cjam.aditsu.net/#code=qN%2F%7B'%2C-%3AQ%3B%0A%0AQ~%7B((%5Ca%40%2B1%24ff-m%3C_0%3D%7Dgs!%0A%0A%5Do%7D%2F

CJam, 23 bytes

q~{((\a@+1$ff-m<_0=}gs!

[Run all test cases.][1] (You'll have to copy them in yourself, because they're too long for a permalink.)

If the assignment of truthy and falsy was the opposite I could save a whopping 5 bytes:

q~{((\a@+1$ff-m<}h

[1]: http://cjam.aditsu.net/#code=qN%2F%7B'%2C-%3AQ%3B%0A%0AQ~%7B((%5Ca%40%2B1%24ff-m%3C_0%3D%7Dgs!%0A%0A%5Do%7D%2F

CJam, 23 21 bytes

q~({(\a@+1$ff-m<(}h*!

Run all test cases.

If the assignment of truthy and falsy was the opposite I could save 3 bytes:

q~{((\a@+1$ff-m<}h
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975
Loading