Below you will find pages that utilize the taxonomy term “Python”
The McNuggets Problem
My son, now 25, was a McNuggets fan. Can you blame him? They’re delicious. He’s always been into numbers and puzzles, so I introduced him to the McNuggets problem when he was about 10.
This classic puzzle was a fun way to keep him occupied and teach him programming. The problem is simple: McDonald’s used to sell Chicken McNuggets in 6, 9, and 20 packs. What is the largest number of McNuggets you cannot buy using these package sizes?
Back to the basics with BASIC (and Python): Binary Search
Back to the basics with basic
Let’s say for a moment that we’ve got an ordered list of numbers.
1,3,5,7,9,11,13,15,17,19,21,23,25
There are 13 values here and we want to check if the number 25
is in this list.
One way to do this would be to loop over each element in the list and check to see if it matches what we’re looking for.
In BASIC, we’d do something like
A Gentle Introduction to LFSRs
What is an LFSR?
An LFSR is a Linear Feedback Shift Register. It’s a simple way of generating a sequence of numbers that look random.
Used in cryptography and in generating pseudo-random numbers, they are interesting because they are so simple. Shift bits and feed a few of them back into the sequence. That’s it.
Important note: LFSRs are not cryptographically secure on their own. ESPECIALLY 8-bit LFSRs. More on that in the next post on this topic.
A gentle introduction to two's complement
I was recently on a video call with a friend, throwing around some ideas for a new product. I mentioned adding large signed numbers in assembly and using two’s complement. He asked me what two’s complement was. I was a little surprised that he didn’t know. He’s been a Java programmer for more than 30 years. Java and Python programmers (and others like gasp Commodore / MicroSoft BASIC) don’t have a native unsigned integer type. The language takes care of the details for you.
MOS paper tape format
I built the world’s worst paper tape reader some weeks ago. It works pretty okay on anything with a USR-style port like a KIM-1 clone or a VIC-20.
It at least attempts to live up to the world’s worst name. Paper tape was (and is) an interesting medium. Sure it’s hard to work with and fragile, but it also has the advantage of being slow. I mean, what’s not to like??!!!
A visual 100 Door Problem solution in Python
Last year, we did the 100 door problem on many platforms in BASIC and Assembly language.
The 100 door problem is:
- There are 100 closed doors in a row.
- You walk past the doors 100 times (100 passes)
- The first time, visit every door. If the door is closed, open it. If it is open, close it. In programming, you’d probably call this toggling the door so let’s call it that.
- The second time, ONLY visit every 2nd door and toggle it. (door 2, 4, 6, etc)
- The third time, ONLY visit every 3rd door and toggle it. (door 3, 6, 9, etc)
Keep going through this loop over and over until you get to the loop where there’s only the last door.
Permutations of 1 to 9 in Python, BASIC, and 6502 Assembly
Someone asked me this week if I would help him with a graph theory problem on 8-Bit machines. The first task was to get all permutations of 1 to 9. Since the total permutations is 9! (362,880) I knew this would take a while.
Learning without learning, the standard library problem
There are no shortcuts to pretty much anything worth doing. If you fail to learn the basics, then when you get to more advanced things, the basics will feel like black magic, and the thing you’re working on will only make sense on the surface.