The search for the “perfect” Advent Calendar using Python and Processing #Python
John Graham-Cumming posts about a search for the best randomization of doors on an Advent calendar to maximize distance between consecutively numbered doors.
I grew up with Advent Calendars, and they are very common in the UK. Shops across the country sell calendars with typically 24 doors on them, one for each day from December 1 to December 24. Behind each door is a small gift (usually chocolate or something similarly sweet and edible).
The numbers on the doors of the calendar are usually arranged somewhat haphazardly. Part of the fun each day is finding the next door to open. It’s the search for the chocolate that makes the calendars enjoyable. Here’s an example layout from an Advent Calendar that I bought in Paul in London:
This is an example of a very common 6×4 (and sometimes 4×6) layout for calendars. In this blog I’m going to develop code to find “pleasing” Advent Calendar layouts in the 6×4 shape. But first, here’s a little animation of the Paul calendar in action. What makes it “pleasing” is that the numbers don’t cluster together (mostly).
So, that calendar isn’t bad but it would be nice to generate a calendar where the numbers are spread about such that from day to day you have to hunt for the next number. The number you are searching for won’t be near yesterday’s number and if you see a number close to it then you are likely in the wrong place. That latter restriction adds a lot of pleasure because we are so used to seeing consecutive numbers that our brains instantly start looking nearby.
To do that I broke out the Python (I’m no Python expert so I appreciate Pythonistas who write in with improvements to my code).
Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, or even use Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for MakeCode, CircuitPython, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.
Python for Microcontrollers — Python snakes its way on the SparkFun SAMD21 Mini, Hackaday.io, 10k thanks, and Tim’s magazine #Python #Adafruit #CircuitPython @circuitpython @micropython @ThePSF @Adafruit
Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !