This is a magic card trick using a binary method to guess a 16-bit number. In this game, the user will try to guess a number, and the system will help determine that number based on their selections from five cards.
In this system, the Binary Magic Card Trick uses 5 cards to display 16-bit data. The user will mentally select a number, and the system will try to determine that number based on their selections.
-
Card Distribution:
- 5 cards are used, and each card contains a set of numbers. Each card represents a specific bit of the binary number.
- id 1: Represents the first bit of the binary number.
- id 2: Represents the second bit.
- id 4: Represents the third bit.
- id 8: Represents the fourth bit.
- id 16: Represents the fifth bit.
- 5 cards are used, and each card contains a set of numbers. Each card represents a specific bit of the binary number.
-
Card Selection:
- Each card contains several numbers that belong to a specific binary bit. For instance:
- id: 1 contains numbers like [1, 3, 5, 7, 9] (numbers where the first bit is 1).
- id: 2 contains numbers like [2, 3, 6, 7, 10] (numbers where the second bit is 1), and so on.
- Each card contains several numbers that belong to a specific binary bit. For instance:
-
User Selection:
- The user thinks of a number and selects the cards that contain their number. If the number appears in the card, the user will select that card; otherwise, they won't.
-
Binary Conversion:
- Based on the user's selections, the system will form a binary number by adding the bits from the selected cards. For example:
- If the user selects cards with id 1, id 2, id 8, and id 16, the binary number will be:
11111which equals31.
- If the user selects cards with id 1, id 2, id 8, and id 16, the binary number will be:
- Based on the user's selections, the system will form a binary number by adding the bits from the selected cards. For example:
-
Number Output:
- Finally, the system will convert the binary number into the actual number that the user was thinking of.
- Step 1: Display 5 cards to the user, each with a set of numbers.
- Step 2: The user mentally picks a number.
- Step 3: The system shows the cards and asks the user to select the ones containing their number.
- Step 4: Based on the user's selection, the system generates a binary number.
- Step 5: The system converts the binary number into the corresponding actual number.
This algorithm allows the system to guess a number using a simple binary method.
To simulate this, the following steps will occur:
- The user selects cards based on the numbers that they mentally choose.
- The system then generates a binary number from the cards selected.
- Finally, the system converts the binary number into the corresponding number.
For example, if the user selects cards with id 1, id 2, id 8, and id 16, the binary number formed will be: 11111, which equals 31.
Let’s take the case where the user thinks of the number 31.
-
The system shows 5 cards containing the numbers:
- Card 1: Contains numbers like [1, 3, 5, 7, 9].
- Card 2: Contains numbers like [2, 3, 6, 7, 10].
- Card 4: Contains numbers like [4, 5, 6, 7, 12].
- Card 8: Contains numbers like [8, 9, 10, 11, 12].
- Card 16: Contains numbers like [16, 17, 18, 19, 20].
-
The user selects the cards based on their chosen number 31:
- Card 1 (id 1): Selected.
- Card 2 (id 2): Selected.
- Card 4 (id 4): Selected.
- Card 8 (id 8): Selected.
- Card 16 (id 16): Selected.
-
The binary number formed is:
11111which equals31. -
The system successfully identifies that the user thought of the number 31.
Let’s take the case where the user thinks of the number 17.
-
The system shows 5 cards:
- Card 1: Contains numbers like [1, 3, 5, 7, 9].
- Card 2: Contains numbers like [2, 3, 6, 7, 10].
- Card 4: Contains numbers like [4, 5, 6, 7, 12].
- Card 8: Contains numbers like [8, 9, 10, 11, 12].
- Card 16: Contains numbers like [16, 17, 18, 19, 20].
-
The user selects the cards based on their chosen number 17:
- Card 1 (id 1): Selected.
- Card 2 (id 2): No selection.
- Card 4 (id 4): No selection.
- Card 8 (id 8): No selection.
- Card 16 (id 16): Selected.
-
The binary number formed is:
10001which equals17. -
The system successfully identifies that the user thought of the number 17.
This game allows users to use their own mental calculations to play and let the system guess their thought number using simple binary-based logic. It is an interactive and engaging game that illustrates the power of binary number systems in a practical way.
I was inspired by this video of Rafa and basically built this game. I had some free time and had some fun.
To get started with the project, follow these steps:
-
Clone the repository:
git clone https://github.com/rafeuddaraj/Binary-Magic.git
-
Navigate into the project directory:
cd Binary-Magic -
Install dependencies:
pnpm install
-
Start the development server:
pnpm dev
-
Open your browser and go to
http://localhost:3000.
We welcome contributions from everyone! To contribute:
- Fork this repository to your GitHub account.
- Clone your forked repository to your local machine.
git clone https://github.com/rafeuddaraj/Binary-Magic.git
- Create a new branch for your changes:
git checkout -b feature/my-awesome-feature
- Make your changes and commit them:
git add . git commit -m "Add feature: My awesome feature"
- Push your changes to your forked repository:
git push origin feature/my-awesome-feature
- Create a Pull Request (PR) from your forked repository to the main repository.
- Write clear and concise commit messages.
- Follow the existing code style.
- Make sure to add tests for new features or bug fixes.
