Playing Pickomino
$begingroup$
In the game Pickomino, there are several tiles lying in the middle of the table, each with a different positive integer on them. Each turn, the players roll dices in a certain way and get a score, which is a nonnegative integer.
Now the player takes the tile with the highest number that is still lower or equal to their score, removing the tile from the middle and adding it to their stack. If this is not possible because all numbers in the middle are higher than the player's score, the player loses the topmost tile from their stack (which was added latest), which is returned to the middle. If the player has no tiles left, nothing happens.
The challenge
Simulate a player playing the game against themselves. You get a list of the tiles in the middle and a list of the scores that the player got. Return a list of the tiles of the player after all turns have been evaluated.
Challenge rules
- You can assume that the list with the tiles is ordered and doesn't contain any integer twice.
- You can take both lists of input in any order you want
- The output has to keep the order of the tiles on the stack, but you can decide whether the list is sorted from top to bottom or from bottom to top.
General rules
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Adding an explanation for you answer is recommended.
Example
(taken from the 6th testcase)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
First score is 22, so take the highest tile in the middle <= 22, which is 22 itself.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [22, 22, 23, 21, 24, 0, 22]
Next score is 22, so take the highest tile in the middle <= 22. Because 22 is already taken, the player has to take 21.
Middle: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 21]
Remaining scores: [22, 23, 21, 24, 0, 22]
Next score is 22, but all numbers <= 22 are already taken. Therefore, the player loses the topmost tile on the stack (21), which is returned into the middle.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [23, 21, 24, 0, 22]
Next scores are 23, 21 and 24, so the player takes these tiles from the middle.
Middle: [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21, 24]
Remaining scores: [0, 22]
The player busts and scores zero. Therefore, the tile with the number 24 (topmost on the stack) is returned into the middle.
Middle: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21]
Remaining scores: [22]
The last score is 22, but all tiles <= 22 are already taken, so the player loses the topmost tile on the stack (21).
Middle: [21, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Final Stack and Output: [22, 23]
Test cases
(with the topmost tile last in the output list)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [26, 30, 21]
Output: [26, 30, 21]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [35, 35, 36, 36]
Output: [35, 34, 36, 33]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23]
Output: [23]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores:
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23, 0]
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
Output: [22, 23]
Tiles: [1, 5, 9, 13, 17, 21, 26]
Scores: [6, 10, 23, 23, 23, 1, 0, 15]
Output: [5, 9, 21, 17, 13, 1]
Tiles:
Scores: [4, 6, 1, 6]
Output:
Sandbox
code-golf game
$endgroup$
add a comment |
$begingroup$
In the game Pickomino, there are several tiles lying in the middle of the table, each with a different positive integer on them. Each turn, the players roll dices in a certain way and get a score, which is a nonnegative integer.
Now the player takes the tile with the highest number that is still lower or equal to their score, removing the tile from the middle and adding it to their stack. If this is not possible because all numbers in the middle are higher than the player's score, the player loses the topmost tile from their stack (which was added latest), which is returned to the middle. If the player has no tiles left, nothing happens.
The challenge
Simulate a player playing the game against themselves. You get a list of the tiles in the middle and a list of the scores that the player got. Return a list of the tiles of the player after all turns have been evaluated.
Challenge rules
- You can assume that the list with the tiles is ordered and doesn't contain any integer twice.
- You can take both lists of input in any order you want
- The output has to keep the order of the tiles on the stack, but you can decide whether the list is sorted from top to bottom or from bottom to top.
General rules
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Adding an explanation for you answer is recommended.
Example
(taken from the 6th testcase)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
First score is 22, so take the highest tile in the middle <= 22, which is 22 itself.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [22, 22, 23, 21, 24, 0, 22]
Next score is 22, so take the highest tile in the middle <= 22. Because 22 is already taken, the player has to take 21.
Middle: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 21]
Remaining scores: [22, 23, 21, 24, 0, 22]
Next score is 22, but all numbers <= 22 are already taken. Therefore, the player loses the topmost tile on the stack (21), which is returned into the middle.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [23, 21, 24, 0, 22]
Next scores are 23, 21 and 24, so the player takes these tiles from the middle.
Middle: [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21, 24]
Remaining scores: [0, 22]
The player busts and scores zero. Therefore, the tile with the number 24 (topmost on the stack) is returned into the middle.
Middle: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21]
Remaining scores: [22]
The last score is 22, but all tiles <= 22 are already taken, so the player loses the topmost tile on the stack (21).
Middle: [21, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Final Stack and Output: [22, 23]
Test cases
(with the topmost tile last in the output list)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [26, 30, 21]
Output: [26, 30, 21]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [35, 35, 36, 36]
Output: [35, 34, 36, 33]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23]
Output: [23]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores:
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23, 0]
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
Output: [22, 23]
Tiles: [1, 5, 9, 13, 17, 21, 26]
Scores: [6, 10, 23, 23, 23, 1, 0, 15]
Output: [5, 9, 21, 17, 13, 1]
Tiles:
Scores: [4, 6, 1, 6]
Output:
Sandbox
code-golf game
$endgroup$
$begingroup$
If the middle pile is empty does that count as all it's members being higher than the score? I mean logically it does but I just want to be clear.
$endgroup$
– TRITICIMAGVS
3 hours ago
$begingroup$
Can we assume there are no tiles with a value of zero in the middle?
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
@EmbodimentofIgnorance It says "positive integer", so yes.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
Since the tiles are unique, would it be acceptable to take them as a bitmask?
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
In the game Pickomino, there are several tiles lying in the middle of the table, each with a different positive integer on them. Each turn, the players roll dices in a certain way and get a score, which is a nonnegative integer.
Now the player takes the tile with the highest number that is still lower or equal to their score, removing the tile from the middle and adding it to their stack. If this is not possible because all numbers in the middle are higher than the player's score, the player loses the topmost tile from their stack (which was added latest), which is returned to the middle. If the player has no tiles left, nothing happens.
The challenge
Simulate a player playing the game against themselves. You get a list of the tiles in the middle and a list of the scores that the player got. Return a list of the tiles of the player after all turns have been evaluated.
Challenge rules
- You can assume that the list with the tiles is ordered and doesn't contain any integer twice.
- You can take both lists of input in any order you want
- The output has to keep the order of the tiles on the stack, but you can decide whether the list is sorted from top to bottom or from bottom to top.
General rules
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Adding an explanation for you answer is recommended.
Example
(taken from the 6th testcase)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
First score is 22, so take the highest tile in the middle <= 22, which is 22 itself.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [22, 22, 23, 21, 24, 0, 22]
Next score is 22, so take the highest tile in the middle <= 22. Because 22 is already taken, the player has to take 21.
Middle: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 21]
Remaining scores: [22, 23, 21, 24, 0, 22]
Next score is 22, but all numbers <= 22 are already taken. Therefore, the player loses the topmost tile on the stack (21), which is returned into the middle.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [23, 21, 24, 0, 22]
Next scores are 23, 21 and 24, so the player takes these tiles from the middle.
Middle: [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21, 24]
Remaining scores: [0, 22]
The player busts and scores zero. Therefore, the tile with the number 24 (topmost on the stack) is returned into the middle.
Middle: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21]
Remaining scores: [22]
The last score is 22, but all tiles <= 22 are already taken, so the player loses the topmost tile on the stack (21).
Middle: [21, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Final Stack and Output: [22, 23]
Test cases
(with the topmost tile last in the output list)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [26, 30, 21]
Output: [26, 30, 21]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [35, 35, 36, 36]
Output: [35, 34, 36, 33]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23]
Output: [23]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores:
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23, 0]
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
Output: [22, 23]
Tiles: [1, 5, 9, 13, 17, 21, 26]
Scores: [6, 10, 23, 23, 23, 1, 0, 15]
Output: [5, 9, 21, 17, 13, 1]
Tiles:
Scores: [4, 6, 1, 6]
Output:
Sandbox
code-golf game
$endgroup$
In the game Pickomino, there are several tiles lying in the middle of the table, each with a different positive integer on them. Each turn, the players roll dices in a certain way and get a score, which is a nonnegative integer.
Now the player takes the tile with the highest number that is still lower or equal to their score, removing the tile from the middle and adding it to their stack. If this is not possible because all numbers in the middle are higher than the player's score, the player loses the topmost tile from their stack (which was added latest), which is returned to the middle. If the player has no tiles left, nothing happens.
The challenge
Simulate a player playing the game against themselves. You get a list of the tiles in the middle and a list of the scores that the player got. Return a list of the tiles of the player after all turns have been evaluated.
Challenge rules
- You can assume that the list with the tiles is ordered and doesn't contain any integer twice.
- You can take both lists of input in any order you want
- The output has to keep the order of the tiles on the stack, but you can decide whether the list is sorted from top to bottom or from bottom to top.
General rules
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Adding an explanation for you answer is recommended.
Example
(taken from the 6th testcase)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
First score is 22, so take the highest tile in the middle <= 22, which is 22 itself.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [22, 22, 23, 21, 24, 0, 22]
Next score is 22, so take the highest tile in the middle <= 22. Because 22 is already taken, the player has to take 21.
Middle: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 21]
Remaining scores: [22, 23, 21, 24, 0, 22]
Next score is 22, but all numbers <= 22 are already taken. Therefore, the player loses the topmost tile on the stack (21), which is returned into the middle.
Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [23, 21, 24, 0, 22]
Next scores are 23, 21 and 24, so the player takes these tiles from the middle.
Middle: [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21, 24]
Remaining scores: [0, 22]
The player busts and scores zero. Therefore, the tile with the number 24 (topmost on the stack) is returned into the middle.
Middle: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21]
Remaining scores: [22]
The last score is 22, but all tiles <= 22 are already taken, so the player loses the topmost tile on the stack (21).
Middle: [21, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Final Stack and Output: [22, 23]
Test cases
(with the topmost tile last in the output list)
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [26, 30, 21]
Output: [26, 30, 21]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [35, 35, 36, 36]
Output: [35, 34, 36, 33]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23]
Output: [23]
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores:
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23, 0]
Output:
Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
Output: [22, 23]
Tiles: [1, 5, 9, 13, 17, 21, 26]
Scores: [6, 10, 23, 23, 23, 1, 0, 15]
Output: [5, 9, 21, 17, 13, 1]
Tiles:
Scores: [4, 6, 1, 6]
Output:
Sandbox
code-golf game
code-golf game
asked 3 hours ago
Black Owl KaiBlack Owl Kai
6409
6409
$begingroup$
If the middle pile is empty does that count as all it's members being higher than the score? I mean logically it does but I just want to be clear.
$endgroup$
– TRITICIMAGVS
3 hours ago
$begingroup$
Can we assume there are no tiles with a value of zero in the middle?
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
@EmbodimentofIgnorance It says "positive integer", so yes.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
Since the tiles are unique, would it be acceptable to take them as a bitmask?
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
If the middle pile is empty does that count as all it's members being higher than the score? I mean logically it does but I just want to be clear.
$endgroup$
– TRITICIMAGVS
3 hours ago
$begingroup$
Can we assume there are no tiles with a value of zero in the middle?
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
@EmbodimentofIgnorance It says "positive integer", so yes.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
Since the tiles are unique, would it be acceptable to take them as a bitmask?
$endgroup$
– Arnauld
1 hour ago
$begingroup$
If the middle pile is empty does that count as all it's members being higher than the score? I mean logically it does but I just want to be clear.
$endgroup$
– TRITICIMAGVS
3 hours ago
$begingroup$
If the middle pile is empty does that count as all it's members being higher than the score? I mean logically it does but I just want to be clear.
$endgroup$
– TRITICIMAGVS
3 hours ago
$begingroup$
Can we assume there are no tiles with a value of zero in the middle?
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
Can we assume there are no tiles with a value of zero in the middle?
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
@EmbodimentofIgnorance It says "positive integer", so yes.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@EmbodimentofIgnorance It says "positive integer", so yes.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
Since the tiles are unique, would it be acceptable to take them as a bitmask?
$endgroup$
– Arnauld
1 hour ago
$begingroup$
Since the tiles are unique, would it be acceptable to take them as a bitmask?
$endgroup$
– Arnauld
1 hour ago
add a comment |
6 Answers
6
active
oldest
votes
$begingroup$
Haskell, 119 111 104 103 bytes
1 byte saved thanks to Ørjan Johansen
(#)=span.(<)
(a%(b:c))d|(g,e:h)<-b#d=(e:a)%c$g++h|g:h<-a,(i,j)<-g#d=h%c$i++g:j|1>0=a%c$d
(a%b)c=a
(%)
Try it online!
Assumes the tiles are sorted in descending order.
Not much fancy going on here. The first argument is the players pile, the second their scores and the third is the pile in the middle.
$endgroup$
1
$begingroup$
This cannot be right becausesort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
Save a byte with(#)=span.(<)
.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 159 bytes
n=>m=>{var s=new Stack<int>();foreach(var k in n){var a=m.Append(0).Except(s).Where(x=>x<=k).Max();if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);}return s;}
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 24 bytes
Oof! That didn't work out as well as I thought it would!
Takes input in reverse order.
®=Va§Z)Ì?NpVjZ:VpNo)n
N¤
Try it
$endgroup$
add a comment |
$begingroup$
Charcoal, 35 bytes
Fη«≔⌈Φ講κιι¿ι«≔Φθ⁻κιθ⊞υι»¿υ⊞θ⊟υ»Iυ
Try it online! Link is to verbose version of code. Explanation:
Fη«
Loop over the scores.
≔⌈Φ講κιι
Look for the highest available tile.
¿ι«
If it exists then...
≔Φθ⁻κιθ
... remove the tile from the middle...
⊞υι
... and add it to the stack.
»¿υ
Otherwise, if the stack is not empty...
⊞θ⊟υ
Remove the latest tile from the stack and return it to the middle.
»Iυ
Print the resulting stack from oldest to newest.
$endgroup$
add a comment |
$begingroup$
Perl 6, 89 bytes
{my@x;@^a;@^b>>.&{@x=|@x,|(keys(@a∖@x).grep($_>=*).sort(-*)[0]//(try ~@x.pop&&()))};@x}
Try it online!
I think there's a few more bytes to be golfed off this...
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 100 98 94 bytes
Takes input as (tiles)(scores)
. The tiles can be passed in any order.
t=>s=>s.map(x=>m[(g=_=>m[x]?x:g(x--))()?r.push(x)&&x:r.pop()]^=1,t.map(x=>m[x]=1,m=[r=]))&&r
Try it online!
Commented
t => s => // t = tiles; s = scores
s.map(x => // for each score x in s:
m[ // update the 'middle':
(g = _ => // g = recursive function which decrements x until
m[x] ? x : g(x--) // m[x] is set and returns the final value
)() ? // if x is not equal to 0 after that:
r.push(x) && x // push x in the stack r and yield x
: // else:
r.pop() // pop the last value from the stack
] ^= 1, // toggle the corresponding flag in m
t.map(x => // initialization of the 'middle': for each value x in t:
m[x] = 1, // set m[x]
m = [r = ] // the stack r is stored as the first entry of m,
// which ensures that g will always stop when x = 0
) // end of initialization
) && r // end of main loop; return r
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179588%2fplaying-pickomino%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Haskell, 119 111 104 103 bytes
1 byte saved thanks to Ørjan Johansen
(#)=span.(<)
(a%(b:c))d|(g,e:h)<-b#d=(e:a)%c$g++h|g:h<-a,(i,j)<-g#d=h%c$i++g:j|1>0=a%c$d
(a%b)c=a
(%)
Try it online!
Assumes the tiles are sorted in descending order.
Not much fancy going on here. The first argument is the players pile, the second their scores and the third is the pile in the middle.
$endgroup$
1
$begingroup$
This cannot be right becausesort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
Save a byte with(#)=span.(<)
.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
add a comment |
$begingroup$
Haskell, 119 111 104 103 bytes
1 byte saved thanks to Ørjan Johansen
(#)=span.(<)
(a%(b:c))d|(g,e:h)<-b#d=(e:a)%c$g++h|g:h<-a,(i,j)<-g#d=h%c$i++g:j|1>0=a%c$d
(a%b)c=a
(%)
Try it online!
Assumes the tiles are sorted in descending order.
Not much fancy going on here. The first argument is the players pile, the second their scores and the third is the pile in the middle.
$endgroup$
1
$begingroup$
This cannot be right becausesort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
Save a byte with(#)=span.(<)
.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
add a comment |
$begingroup$
Haskell, 119 111 104 103 bytes
1 byte saved thanks to Ørjan Johansen
(#)=span.(<)
(a%(b:c))d|(g,e:h)<-b#d=(e:a)%c$g++h|g:h<-a,(i,j)<-g#d=h%c$i++g:j|1>0=a%c$d
(a%b)c=a
(%)
Try it online!
Assumes the tiles are sorted in descending order.
Not much fancy going on here. The first argument is the players pile, the second their scores and the third is the pile in the middle.
$endgroup$
Haskell, 119 111 104 103 bytes
1 byte saved thanks to Ørjan Johansen
(#)=span.(<)
(a%(b:c))d|(g,e:h)<-b#d=(e:a)%c$g++h|g:h<-a,(i,j)<-g#d=h%c$i++g:j|1>0=a%c$d
(a%b)c=a
(%)
Try it online!
Assumes the tiles are sorted in descending order.
Not much fancy going on here. The first argument is the players pile, the second their scores and the third is the pile in the middle.
edited 1 hour ago
answered 2 hours ago
TRITICIMAGVSTRITICIMAGVS
34.5k10157369
34.5k10157369
1
$begingroup$
This cannot be right becausesort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
Save a byte with(#)=span.(<)
.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
add a comment |
1
$begingroup$
This cannot be right becausesort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
Save a byte with(#)=span.(<)
.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
1
1
$begingroup$
This cannot be right because
sort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
This cannot be right because
sort
is ascending. The TIO test case never hits that branch, though. I strongly recommend testing all cases every time when iterating like this.$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
@ØrjanJohansen Thanks! Fixed now. At least I don't have to import any longer!
$endgroup$
– TRITICIMAGVS
2 hours ago
$begingroup$
Save a byte with
(#)=span.(<)
.$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
Save a byte with
(#)=span.(<)
.$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
$begingroup$
@ØrjanJohansen Change made. Funny thing is I tried that earlier and thought that it added a byte.
$endgroup$
– TRITICIMAGVS
1 hour ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 159 bytes
n=>m=>{var s=new Stack<int>();foreach(var k in n){var a=m.Append(0).Except(s).Where(x=>x<=k).Max();if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);}return s;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 159 bytes
n=>m=>{var s=new Stack<int>();foreach(var k in n){var a=m.Append(0).Except(s).Where(x=>x<=k).Max();if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);}return s;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 159 bytes
n=>m=>{var s=new Stack<int>();foreach(var k in n){var a=m.Append(0).Except(s).Where(x=>x<=k).Max();if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);}return s;}
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 159 bytes
n=>m=>{var s=new Stack<int>();foreach(var k in n){var a=m.Append(0).Except(s).Where(x=>x<=k).Max();if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);}return s;}
Try it online!
edited 2 hours ago
answered 2 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
846118
846118
add a comment |
add a comment |
$begingroup$
Japt, 24 bytes
Oof! That didn't work out as well as I thought it would!
Takes input in reverse order.
®=Va§Z)Ì?NpVjZ:VpNo)n
N¤
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 24 bytes
Oof! That didn't work out as well as I thought it would!
Takes input in reverse order.
®=Va§Z)Ì?NpVjZ:VpNo)n
N¤
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 24 bytes
Oof! That didn't work out as well as I thought it would!
Takes input in reverse order.
®=Va§Z)Ì?NpVjZ:VpNo)n
N¤
Try it
$endgroup$
Japt, 24 bytes
Oof! That didn't work out as well as I thought it would!
Takes input in reverse order.
®=Va§Z)Ì?NpVjZ:VpNo)n
N¤
Try it
answered 2 hours ago
ShaggyShaggy
19.7k21667
19.7k21667
add a comment |
add a comment |
$begingroup$
Charcoal, 35 bytes
Fη«≔⌈Φ講κιι¿ι«≔Φθ⁻κιθ⊞υι»¿υ⊞θ⊟υ»Iυ
Try it online! Link is to verbose version of code. Explanation:
Fη«
Loop over the scores.
≔⌈Φ講κιι
Look for the highest available tile.
¿ι«
If it exists then...
≔Φθ⁻κιθ
... remove the tile from the middle...
⊞υι
... and add it to the stack.
»¿υ
Otherwise, if the stack is not empty...
⊞θ⊟υ
Remove the latest tile from the stack and return it to the middle.
»Iυ
Print the resulting stack from oldest to newest.
$endgroup$
add a comment |
$begingroup$
Charcoal, 35 bytes
Fη«≔⌈Φ講κιι¿ι«≔Φθ⁻κιθ⊞υι»¿υ⊞θ⊟υ»Iυ
Try it online! Link is to verbose version of code. Explanation:
Fη«
Loop over the scores.
≔⌈Φ講κιι
Look for the highest available tile.
¿ι«
If it exists then...
≔Φθ⁻κιθ
... remove the tile from the middle...
⊞υι
... and add it to the stack.
»¿υ
Otherwise, if the stack is not empty...
⊞θ⊟υ
Remove the latest tile from the stack and return it to the middle.
»Iυ
Print the resulting stack from oldest to newest.
$endgroup$
add a comment |
$begingroup$
Charcoal, 35 bytes
Fη«≔⌈Φ講κιι¿ι«≔Φθ⁻κιθ⊞υι»¿υ⊞θ⊟υ»Iυ
Try it online! Link is to verbose version of code. Explanation:
Fη«
Loop over the scores.
≔⌈Φ講κιι
Look for the highest available tile.
¿ι«
If it exists then...
≔Φθ⁻κιθ
... remove the tile from the middle...
⊞υι
... and add it to the stack.
»¿υ
Otherwise, if the stack is not empty...
⊞θ⊟υ
Remove the latest tile from the stack and return it to the middle.
»Iυ
Print the resulting stack from oldest to newest.
$endgroup$
Charcoal, 35 bytes
Fη«≔⌈Φ講κιι¿ι«≔Φθ⁻κιθ⊞υι»¿υ⊞θ⊟υ»Iυ
Try it online! Link is to verbose version of code. Explanation:
Fη«
Loop over the scores.
≔⌈Φ講κιι
Look for the highest available tile.
¿ι«
If it exists then...
≔Φθ⁻κιθ
... remove the tile from the middle...
⊞υι
... and add it to the stack.
»¿υ
Otherwise, if the stack is not empty...
⊞θ⊟υ
Remove the latest tile from the stack and return it to the middle.
»Iυ
Print the resulting stack from oldest to newest.
answered 1 hour ago
NeilNeil
80.4k744178
80.4k744178
add a comment |
add a comment |
$begingroup$
Perl 6, 89 bytes
{my@x;@^a;@^b>>.&{@x=|@x,|(keys(@a∖@x).grep($_>=*).sort(-*)[0]//(try ~@x.pop&&()))};@x}
Try it online!
I think there's a few more bytes to be golfed off this...
$endgroup$
add a comment |
$begingroup$
Perl 6, 89 bytes
{my@x;@^a;@^b>>.&{@x=|@x,|(keys(@a∖@x).grep($_>=*).sort(-*)[0]//(try ~@x.pop&&()))};@x}
Try it online!
I think there's a few more bytes to be golfed off this...
$endgroup$
add a comment |
$begingroup$
Perl 6, 89 bytes
{my@x;@^a;@^b>>.&{@x=|@x,|(keys(@a∖@x).grep($_>=*).sort(-*)[0]//(try ~@x.pop&&()))};@x}
Try it online!
I think there's a few more bytes to be golfed off this...
$endgroup$
Perl 6, 89 bytes
{my@x;@^a;@^b>>.&{@x=|@x,|(keys(@a∖@x).grep($_>=*).sort(-*)[0]//(try ~@x.pop&&()))};@x}
Try it online!
I think there's a few more bytes to be golfed off this...
answered 1 hour ago
Jo KingJo King
22.2k251115
22.2k251115
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 100 98 94 bytes
Takes input as (tiles)(scores)
. The tiles can be passed in any order.
t=>s=>s.map(x=>m[(g=_=>m[x]?x:g(x--))()?r.push(x)&&x:r.pop()]^=1,t.map(x=>m[x]=1,m=[r=]))&&r
Try it online!
Commented
t => s => // t = tiles; s = scores
s.map(x => // for each score x in s:
m[ // update the 'middle':
(g = _ => // g = recursive function which decrements x until
m[x] ? x : g(x--) // m[x] is set and returns the final value
)() ? // if x is not equal to 0 after that:
r.push(x) && x // push x in the stack r and yield x
: // else:
r.pop() // pop the last value from the stack
] ^= 1, // toggle the corresponding flag in m
t.map(x => // initialization of the 'middle': for each value x in t:
m[x] = 1, // set m[x]
m = [r = ] // the stack r is stored as the first entry of m,
// which ensures that g will always stop when x = 0
) // end of initialization
) && r // end of main loop; return r
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 100 98 94 bytes
Takes input as (tiles)(scores)
. The tiles can be passed in any order.
t=>s=>s.map(x=>m[(g=_=>m[x]?x:g(x--))()?r.push(x)&&x:r.pop()]^=1,t.map(x=>m[x]=1,m=[r=]))&&r
Try it online!
Commented
t => s => // t = tiles; s = scores
s.map(x => // for each score x in s:
m[ // update the 'middle':
(g = _ => // g = recursive function which decrements x until
m[x] ? x : g(x--) // m[x] is set and returns the final value
)() ? // if x is not equal to 0 after that:
r.push(x) && x // push x in the stack r and yield x
: // else:
r.pop() // pop the last value from the stack
] ^= 1, // toggle the corresponding flag in m
t.map(x => // initialization of the 'middle': for each value x in t:
m[x] = 1, // set m[x]
m = [r = ] // the stack r is stored as the first entry of m,
// which ensures that g will always stop when x = 0
) // end of initialization
) && r // end of main loop; return r
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 100 98 94 bytes
Takes input as (tiles)(scores)
. The tiles can be passed in any order.
t=>s=>s.map(x=>m[(g=_=>m[x]?x:g(x--))()?r.push(x)&&x:r.pop()]^=1,t.map(x=>m[x]=1,m=[r=]))&&r
Try it online!
Commented
t => s => // t = tiles; s = scores
s.map(x => // for each score x in s:
m[ // update the 'middle':
(g = _ => // g = recursive function which decrements x until
m[x] ? x : g(x--) // m[x] is set and returns the final value
)() ? // if x is not equal to 0 after that:
r.push(x) && x // push x in the stack r and yield x
: // else:
r.pop() // pop the last value from the stack
] ^= 1, // toggle the corresponding flag in m
t.map(x => // initialization of the 'middle': for each value x in t:
m[x] = 1, // set m[x]
m = [r = ] // the stack r is stored as the first entry of m,
// which ensures that g will always stop when x = 0
) // end of initialization
) && r // end of main loop; return r
$endgroup$
JavaScript (ES6), 100 98 94 bytes
Takes input as (tiles)(scores)
. The tiles can be passed in any order.
t=>s=>s.map(x=>m[(g=_=>m[x]?x:g(x--))()?r.push(x)&&x:r.pop()]^=1,t.map(x=>m[x]=1,m=[r=]))&&r
Try it online!
Commented
t => s => // t = tiles; s = scores
s.map(x => // for each score x in s:
m[ // update the 'middle':
(g = _ => // g = recursive function which decrements x until
m[x] ? x : g(x--) // m[x] is set and returns the final value
)() ? // if x is not equal to 0 after that:
r.push(x) && x // push x in the stack r and yield x
: // else:
r.pop() // pop the last value from the stack
] ^= 1, // toggle the corresponding flag in m
t.map(x => // initialization of the 'middle': for each value x in t:
m[x] = 1, // set m[x]
m = [r = ] // the stack r is stored as the first entry of m,
// which ensures that g will always stop when x = 0
) // end of initialization
) && r // end of main loop; return r
edited 30 mins ago
answered 2 hours ago
ArnauldArnauld
75.5k692317
75.5k692317
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179588%2fplaying-pickomino%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
If the middle pile is empty does that count as all it's members being higher than the score? I mean logically it does but I just want to be clear.
$endgroup$
– TRITICIMAGVS
3 hours ago
$begingroup$
Can we assume there are no tiles with a value of zero in the middle?
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
@EmbodimentofIgnorance It says "positive integer", so yes.
$endgroup$
– Ørjan Johansen
2 hours ago
$begingroup$
Since the tiles are unique, would it be acceptable to take them as a bitmask?
$endgroup$
– Arnauld
1 hour ago