Guess My Number Racket Style
| This project was an independent personal coding project (with GUI) undertaken by the author. You can find the project by clicking the Github icon. -> |
Author's Note
Racket was the first language I learned to code with - unless you count HTML, but let's be honest, nobody ever does. With Information Technology being one of my favourite subjects at school, it was a bit disappointing coding and programming were never part of it.
Read more about an introduction to Racket in my previous post: click here.
Concept
There was this one trick where you think of a number and you'd be shown the cards below asking you if your number was on the particular card. After going through all six cards, your number would be guessed accurately.

Guess My Number Cards
I was initially obsessed with finding out how this works and after I learnt the trick to it, I started applying it everywhere.
The trick behind guessing the numbers are the first numbers on the card - the top left numbers (circled in red above). If the number you're thinking of is on the card, add the circled number of the respective cards, and you'll eventually have your number.
For example, if you're thinking of 11, it appears on cards 1, 2 and 8 (top-left, top-middle, bottom-left). If you add those numbers together, you get the number you thought of:
1 + 2 + 8 = 11.
This is also a close representation of working with binary numbers. We can represent the six cards as six consecutive zeroes (000000) as the default state. Again using the example of 11, for every card the number appears on, change the 0 to 1, starting from the right.
001011 is what we end up with, which also translates to 11.
Design and Development
While learning to program in Racket, I thought it would be cool to implement it in Racket. I used the same concept of the cards and used a list for the numbers.
If the number you're thinking of is on the card, append the "card value" to the list. After the six cards, add the values and display the answer. Simple!
Evaluation
Racket GUI: Guess My Number

0 comments:
Post a Comment