[{"element_type":"text","content":"\n        \u003cp style=\"text-align: center;\"\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp style=\"text-align: center;\"\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp style=\"text-align: center;\"\u003e\u003cspan\u003e\u003cem\u003e\u003cstrong\u003eI think prime numbers are like life. They are very logical but you could never work out the rules, even if you spent all your time thinking about them \u003c/strong\u003e\u003c/em\u003e- \u003cstrong class=\"w3-text-black w3-medium\"\u003eMark Haddon, The Curious Incident of the Dog in the Night-Time\u003c/strong\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"w3-text-black w3-medium\"\u003eAt some point, I realize I consider the Circuit Playground kind of a multi-tool - sensors, inputs, sound output, control of motors and more... actually, maybe more like Doctor Who's\u0026nbsp;\u003ca href=\"https://en.wikipedia.org/wiki/Sonic_screwdriver\" target=\"_blank\"\u003eSonic Screwdriver\u003c/a\u003e....\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"w3-text-black w3-medium\"\u003eThis week I worked to reconfigure my CPX to search for \u003ca href=\"https://en.wikipedia.org/wiki/Prime_number\" target=\"_blank\"\u003eprime numbers \u003c/a\u003ebecause... why not? With my memory of the Sieve of Eratosthenes it took no time to find \u003ca href=\"https://www.geeksforgeeks.org/python-program-for-sieve-of-eratosthenes/\" target=\"_blank\"\u003ePython code\u003c/a\u003e to adapt for CircuitPython. In fact the code pretty much ran fine from the start.\u0026nbsp;\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"w3-text-black w3-medium\"\u003eFirst though, I made a version for Makecode - essentially using the Python code as a model. And then I made the CircuitPython version - actually\u0026nbsp;\u003cem\u003etwo\u003c/em\u003e versions. More on that later. (And, yes, there is a NeoTrinkey version as well).\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"w3-text-black w3-medium\"\u003eIt is all in this repository :\u0026nbsp;\u003ca href=\"https://github.com/mrklingon/Eratosthenes/\" target=\"_blank\"\u003eEratosthenes\u003c/a\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eESieve.js - MakeCode/Javascript for finding all primes \u0026lt; 1000\u003cspan\u003e\u0026nbsp;\u003c/span\u003e\u003ca href=\"https://makecode.com/_H5qFx46rYF1c\"\u003ehttps://makecode.com/_H5qFx46rYF1c\u003c/a\u003e\u003cspan\u003e\u0026nbsp;\u003c/span\u003efor Makecode version\u003c/li\u003e\n\u003cli\u003eESieve.py - CircuitPython for finding all primes \u0026lt; 1000 - copy to code.py\u003c/li\u003e\n\u003cli\u003eESievePlus.py - CircuitPython for finding all primes \u0026lt; 8000 - copy to code.py\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eAll three of the above will flash colored lights while searching for the prime numbers. When done, A will pick a random prime and display it, first in binary, then digit-by-digit in decimal version. Pressing B will step through all of the primes it found, displaying in binary. Touch A1 to display the last random prime it found in the random selection from pressing A.\u003c/p\u003e\n\u003cp\u003eThe coding of binary values uses the ten neopixels - Green for 1's and Blue for 0's\u003c/p\u003e\n\u003cp\u003eNeoPixel:\u0026nbsp;\u003cstrong\u003e 0\u0026nbsp; \u0026nbsp; 1\u0026nbsp; \u0026nbsp; 2\u0026nbsp; \u0026nbsp; 3\u0026nbsp; \u0026nbsp; 4\u0026nbsp; \u0026nbsp; \u0026nbsp;5\u0026nbsp; \u0026nbsp; 6\u0026nbsp; \u0026nbsp; \u0026nbsp; 7\u0026nbsp; \u0026nbsp; \u0026nbsp;8\u0026nbsp; \u0026nbsp; 9\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eValue:\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; \u003cstrong\u003e1\u0026nbsp; \u0026nbsp; 2\u0026nbsp; \u0026nbsp; 4\u0026nbsp; \u0026nbsp;8\u0026nbsp; \u0026nbsp;16\u0026nbsp; \u0026nbsp;32\u0026nbsp; 64\u0026nbsp; 128 256 512\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe digit-by-digit display of a number lights up yellow pixels to show a value, with the rest of the pixels blue (so for 0 they all are blue).\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eneosieve.py - neotrinkey version (copy to code.py)\u003c/li\u003e\n\u003cli\u003encount.py - support file for neosieve.py\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eNeoTrinkey version. It finds all primes \u0026lt; 1000. First it flashes colored lights while searching, then, when done, touching pad #1 will display a random prime digit by digit with binary coding. Touching pad #2 will redisplay the last random prime found.\u003c/p\u003e\n\u003cp\u003eThe \"digits\" displayed use the binary coding I had in the\u003ca href=\"https://adafruit-playground.com/u/mrklingon/pages/neotrinkey-rrpn-calculator-the-extra-r-is-for-ridiculous\" target=\"_blank\"\u003e RRPN Calculator \u003c/a\u003eproject:\u003c/p\u003e\n      ","metadata":{}},{"element_type":"image_url","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/125/large1024/binary.jpg?1725065495","metadata":{"alt":"Binary","caption":"NeoTrinkey Binary Values"}},{"element_type":"text","content":"\n  \n  \n  \n  \n        \u003cp\u003eAll of the Circuit Python versions (neotrinkey or Circuit Playground), if connected to Mu or a similar IDE, will print information to the REPL.\u003c/p\u003e\n\u003cp\u003eCode based on\u003cspan\u003e\u0026nbsp;\u003c/span\u003e\u003ca href=\"https://www.geeksforgeeks.org/python-program-for-sieve-of-eratosthenes/\"\u003ehttps://www.geeksforgeeks.org/python-program-for-sieve-of-eratosthenes/\u003c/a\u003e\u003cspan\u003e\u0026nbsp;\u003c/span\u003e- MakeCode version written from scratch recreating the algorithm followed in that sample Python code.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eChallenges\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIt seemed ... paltry to ONLY do the primes \u0026lt; 1000\u0026nbsp;\u003cem\u003ebut\u003c/em\u003e\u003cspan\u003e\u0026nbsp;\u003c/span\u003ecreating a Boolean array of more than 1000 ran into memory limitations. To fix that, in ESievePlus.py, instead of an array of Booleans,\u0026nbsp; I created an array of 1000 8 bit numbers, initially set to 255 (11111111 in binary) and wrote functions to clear bits (indicating NOT prime) and another to test whether individual bits were 1 (prime) or 0 (not prime).\u003c/p\u003e\n\u003cp\u003eThis introduced another problem - numbers greater than 1023 need more than 10 bits to display - so I modified the showbin() routine to shift all the pixels when displaying the higher bits.\u003c/p\u003e\n\u003cp\u003eNote: Since it takes a\u0026nbsp;\u003cem\u003ewhile\u003c/em\u003e to display hundreds of prime numbers when you push the B button (over a thousand for the ESievePlus.py version!) - the A button is an easy way to sample the primes that were found.\u003c/p\u003e\n      \n\n\n\n","metadata":{}},{"element_type":"image_url","content":"https://quotefancy.com/media/wallpaper/3840x2160/4782981-Paul-Erd-s-Quote-God-may-not-play-dice-with-the-universe-but.jpg","metadata":{"alt":"God","caption":"God may not play dice with the universe....."}}]