| Bytes | Lang | Time | Link |
|---|---|---|---|
| 039 | Curry PAKCS | 240114T201302Z | Kirill L |
| 023 | x8664 machine code | 240112T150133Z | m90 |
| 026 | APLDyalog Unicode | 231229T062213Z | Tbw |
| 127 | Scala | 231231T014704Z | 138 Aspe |
| 019 | Jelly | 231229T193526Z | Nick Ken |
| 030 | Retina 0.8.2 | 231229T133842Z | Neil |
| 049 | JavaScript ES6 | 231229T132209Z | Arnauld |
| 029 | Charcoal | 231229T084037Z | Neil |
| 070 | Python 3 | 231229T060001Z | l4m2 |
| 069 | Python 3 | 231229T060652Z | tsh |
Curry (PAKCS), 39 bytes
f(c:q)h=h:f q c
f(c:q)h=c:f q h
f""h=""
Takes the queue (starting from the current piece) as a string and piece in hold as a char. Basically, the code just describes what can happen during a move. Due to non-deterministic behavior, Curry just walks through all the possibilities, which is exactly what we need here.
x86-64 machine code, 23 bytes
B6 40 56 88 F2 A8 AA AC D0 EA 73 FA A4 75 F9 5E FE C6 71 EE 88 17 C3
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes:
- in RDI, an address at which to place the result, as multiple null-terminated byte strings run together, terminated with an empty string;
- in RSI, the address of the input, as a null-terminated byte string.
In assembly:
f:
mov dh, 64 # Set DH to 64.
# (This value will run from 64 to 127. The bottom six bits indicate
# when to switch the hold piece in, covering all possibilities.
# The top two bits are always 01.)
repeat:
push rsi # Save the value of RSI onto the stack.
mov dl, dh # Set DL to the value of DH.
.byte 0xA8 # Absorbs the next instruction into "test al, 0xAA".
switch:
stosb # Write AL to the output string, advancing the pointer.
lodsb # Read from the input string into AL, advancing the pointer.
nextpiece: # (AL will store the currently held piece.)
shr dl, 1 # Shift DL right by 1 bit. The bit shifted out goes into CF.
jnc switch # Jump if CF=0.
movsb # Add a byte from the input string to the output string,
# advancing both pointers.
jnz nextpiece # Jump if the last calculated value (DL) is nonzero.
pop rsi # Restore the value of RSI from the stack.
inc dh # Add 1 to DH.
jno repeat # Jump back, except when DH overflows from 127 to -128.
mov [rdi], dl # Add a null byte from DL to the output string.
ret # Return.
APL(Dyalog Unicode), 33,32,31,29,26 bytes SBCS
(,⍳6⍴2){1↓¯1∘⌽@(⍸1,⍺)⊢⍵}¨⊂
A tacit function which takes a string on the right in the order of held piece, current piece, queue.
Old Explanation (essentially the same)
(⍳64){1↓¯1∘⌽@(⍸~(7⍴2)⊤⍺)⊢⍵}¨⊂
⊂ # put the input in an array
# so the 'each' doesn't apply to it
{ }¨ # apply this dfn for each...
(⍳64) ⍺ # number between 0 and 63
7⍴2 # 2 2 2 2 2 2 2 so we can...
(7⍴2)⊤ # convert 7 binary digits
~ # bitwise not
⍸ # indices of 1s
(⍸~(7⍴2)⊤⍺) # all combinations of 0-6 that have a 0
@ ⊢⍵ # at those indices of the input...
¯1∘⌽ # shift the letters left by 1
1↓ # then drop the first letter
💎
Created with the help of Luminespire.
This works without recursion because we can take the composition of swaps (holding a piece) and get $$(0~d)(0~c)(0~b)(0~a) = (0~a~b~c~d)$$ in permutation notation. So we take all possible selections of places to hold, add a 0 to each, and permute the input using ¯1∘⌽@, rotating the selected indices by 1.
Scala, 127 bytes
A port of @l4m2's Python answer in Scala.
127 bytes, it can be golfed more.
Golfed version. Attempt This Online!
type L[C]=List[C]
def f[C<:Char](x:L[C],y:L[C]=Nil):L[L[C]]=x match{case h::n::t=>f(n::t,y:+h):::f(h::t,y:+n);case _=>List(y);}
Ungolfed version. Attempt This Online!
object Main {
def f(x: List[Char], y: List[Char] = List()): List[List[Char]] = x match {
case head :: next :: tail => f(next :: tail, y :+ head) ::: f(head :: tail, y :+ next)
case _ => List(y)
}
def main(args: Array[String]): Unit = {
val result = f(List('O', 'T', 'Z', 'S', 'L', 'J', 'I'))
println(result)
}
}
Jelly, 19 bytes
W;Ɱ2ṗ6¤œ-ị@¥\€œ-Ɲ€Y
A full program that takes a string as its argument (held, current, five next) and prints the 64 possibilities to STDOUT.
Explanation
W | Wrap in a list
;Ɱ | Concatenate to each of:
2ṗ6¤ | - 2 Cartesian power 6 (i.e. all lists length 6 of 1s and 2s)
¥\€ | For each of these, reduce using the following, collecting up intermediate results:
œ-ị@ | - Set difference between the current set of pieces and the one found at the index of the right argument (either the first or second)
œ-Ɲ€ | Set difference of neighbours for each of these outputs
Y | Join with new lines
Retina 0.8.2, 30 bytes
+%`(.),(.)
$2$1,$'¶$`$1$2,
.,
Try it online! Takes the hold piece as the first input and the current piece and next queue as a single string as the second input, separated by a comma. Explanation:
(.),(.)
$2$1,$'¶$`$1$2,
Match the hold piece and the current piece and create two new positions, one by playing the current piece and one by playing the hold piece.
+%`
Repeat the above separately on each position until queue is empty.
.,
Delete the hold piece and separator from each result.
JavaScript (ES6), 49 bytes
Expects (queue, held_piece), where the first item in the queue is the current piece.
f=([c,...a],h,o="")=>c?f(a,h,o+c)+[,f(a,c,o+h)]:o
Charcoal, 32 29 bytes
⊞υSFS≔ΣEυ⟦⭆κ⁺μ×ι¬ν⁺ικ⟧υEυ⮌✂ι¹
Attempt This Online! Link is to verbose version of code. Takes the hold piece as the first input and the current piece and next queue as a single string as the second input. Explanation:
⊞υS
Start with the hold piece and no played pieces.
FS
Loop over the queue.
≔ΣEυ⟦⭆κ⁺μ×ι¬ν⁺ικ⟧υEυ
For each position, create two positions, one playing the current piece and one holding it and playing the hold piece. Note that the piece is played at the start of the string, so the played pieces are currently in reverse order.
⮌✂ι¹
Print the played pieces of the positions in the correct order.
Python 3, 70 bytes
f=lambda x,y=[]:x[1:]and f(x[1:],y+x[:1])+f(x[:1]+x[2:],y+[x[1]])or[y]
Python 3, 66 bytes by tsh
f=lambda a,o='':a[1:]and f(a[1:],o+a[0])+f(a[0]+a[2:],o+a[1])or[o]
I'm not sure if I understood correctly,
Python 3, 69 bytes
f=lambda x,y,*a:a and[p+j for p,q in[x+y,y+x]for j in f(q,*a)]or[x,y]
Input 7 chars, output str.