{"id":17719,"date":"2025-01-17T10:29:33","date_gmt":"2025-01-17T15:29:33","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=17719"},"modified":"2025-07-26T11:05:31","modified_gmt":"2025-07-26T15:05:31","slug":"the-100-doors-problem-on-a-very-small-computer","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2025\/01\/17\/the-100-doors-problem-on-a-very-small-computer\/","title":{"rendered":"The 100 Doors Problem, on a very small computer"},"content":{"rendered":"\n<figure class=\"wp-block-video\"><video height=\"360\" style=\"aspect-ratio: 640 \/ 360;\" width=\"640\" controls src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/ZX81-100doors-1K.mp4\"><\/video><figcaption class=\"wp-element-caption\">The 100 Doors problem running on an (emulated) unexpanded ZX81<\/figcaption><\/figure>\n\n\n\n<p>I learned about this simple computer problem from Michael Doornbos: <a href=\"https:\/\/imapenguin.com\/2021\/08\/just-for-fun-the-100-door-problem-on-several-different-systems\/\">Just for fun, the 100 door problem on several different systems<\/a><\/p>\n\n\n\n<p>Yeah, it&#8217;s pretty neat to be able to do that on a Commodore VIC-20 with 5K of RAM. But how about a ZX81 with only 1K? With screen memory that moves around depending on how much stuff you have on the screen? No problem:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"360\" src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/100doors-1K-listing.png\" alt=\"ZX81 screendump showing program listing (program is listed at text elsewhere)\" class=\"wp-image-17717\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/100doors-1K-listing.png 640w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/100doors-1K-listing-320x180.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/100doors-1K-listing-160x90.png 160w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption class=\"wp-element-caption\">that&#8217;s it: that&#8217;s the whole program<\/figcaption><\/figure>\n\n\n\n<p>The tricky part is printing just enough to the screen that you have enough memory to store the array and still have enough memory for your program. I did that by printing four lines of &#8220;\ud83e\udf90&#8221; characters (CHR$ 136 on the ZX81, U+1FB90) and moving the cursor down just far enough that later output wouldn&#8217;t zap my data. The screen address (given by the <strong>D_FILE<\/strong> pointer at 16396) is used as an array of 100 characters.<\/p>\n\n\n\n<p>The ZX81&#8217;s (non-ASCII) character set has a nice quirk that Space is CHR$ 0, and inverse video Space (&#8220;\u2588&#8221;) is at CHR$ 128. So you can use NOT to toggle the value.<\/p>\n\n\n\n<p>Here&#8217;s the program listing, with Unicode characters:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n   10 REM 100DOORS1K SCRUSS 2025\n  20 FOR I=1 TO 128\n  30 PRINT &quot;\ud83e\udf90&quot;;\n  40 NEXT I\n  50 PRINT AT 3,0;&quot;\ud83e\udf90&quot;\n  60 LET D=PEEK 16396+PEEK 16397*256\n  70 FOR J=1 TO 100\n  80 POKE D+J,0\n  90 NEXT J\n 100 FOR I=1 TO 100\n 110 FOR J=I TO 100 STEP I\n 120 POKE D+J,128*NOT PEEK (D+J)\n 130 NEXT J\n 140 NEXT I\n 150 FOR I=1 TO 100\n 160 IF PEEK (D+I) THEN PRINT I,\n 170 NEXT I\n<\/pre><\/div>\n\n\n<p>The ZX81 program image plus the listing in zmakebas format is included here: <\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-87c19ada-b905-4647-bd5b-10131f4ade44\" href=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/100doors-1K.zip\">100doors-1K<\/a><a href=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2025\/01\/100doors-1K.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-87c19ada-b905-4647-bd5b-10131f4ade44\">Download<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I learned about this simple computer problem from Michael Doornbos: Just for fun, the 100 door problem on several different systems Yeah, it&#8217;s pretty neat to be able to do that on a Commodore VIC-20 with 5K of RAM. But how about a ZX81 with only 1K? With screen memory that moves around depending on [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[2062,2556,2099,3338],"class_list":["post-17719","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-basic","tag-retrocomputing","tag-sinclair","tag-zx81"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4BN","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=17719"}],"version-history":[{"count":3,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17719\/revisions"}],"predecessor-version":[{"id":17883,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17719\/revisions\/17883"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=17719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=17719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=17719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}