Sleight of Code
A Backbone.js magic trick
by Rafael Jacinto@rpdjacinto | Github | rafael.jacinto@hootsuite.com
The 27 Cards trick
- Found the trick on the Numberphile YouTube channel
- No trick decks, no sleight of hand, just math
-
Problem: Trying to crunch numbers and be entertaining at the same time produced undesirable results
Why can't a computer just do this?!
A Simpler Case
Consider the same trick, but with 2 piles and 8 total cards
A Simpler Case
Because of the way we deal the cards, we can predict where a given card will end up
(Simplified to 2 piles and 8 total cards)
The Magician's job
...is to place the volunteer's card at the position corresponding to their chosen number
The Technique
- Subtract 1 from the volunteer's number, convert to base 3
- The 3 digits tell you where to put the volunteer's chosen pile
- 0 - Top, 1 - Middle, 2 - Bottom
eg. Volunteer choses 9. 9 - 1 = 8 (base 3: 022) so the first chosen pile is placed on TOP, the second on BOTTOM, third on BOTTOM