Mind boggling card trick: Difference between revisions

Added 11l
(Add C)
(Added 11l)
Line 32:
Show output on this page.
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>//import random
V n = 52
V Black = ‘Black’
V Red = ‘Red’
V blacks = [Black] * (n I/ 2)
V reds = [Red] * (n I/ 2)
V pack = blacks [+] reds
random:shuffle(&pack)
 
[String] black_stack, red_stack, discard
L !pack.empty
V top = pack.pop()
I top == Black
black_stack.append(pack.pop())
E
red_stack.append(pack.pop())
discard.append(top)
print(‘(Discards: ’(discard.map(d -> d[0]).join(‘ ’))" )\n")
 
V max_swaps = min(black_stack.len, red_stack.len)
V swap_count = random:(0 .. max_swaps)
print(‘Swapping ’swap_count)
 
F random_partition(stack, count)
V stack_copy = copy(stack)
random:shuffle(&stack_copy)
R (stack_copy[count ..], stack_copy[0 .< count])
 
(black_stack, V black_swap) = random_partition(black_stack, swap_count)
(red_stack, V red_swap) = random_partition(red_stack, swap_count)
 
black_stack [+]= red_swap
red_stack [+]= black_swap
 
I black_stack.count(Black) == red_stack.count(Red)
print(‘Yeha! The mathematicians assertion is correct.’)
E
print(‘Whoops - The mathematicians (or my card manipulations) are flakey’)</lang>
 
{{out}}
<pre>
(Discards: B R B B R B R R R B R R R R B R B B R R B B R B B R )
 
Swapping 10
Yeha! The mathematicians assertion is correct.
</pre>
 
=={{header|AutoHotkey}}==
1,481

edits