{"id":252,"date":"2006-12-22T14:09:22","date_gmt":"2006-12-22T14:09:22","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/12\/22\/pathological-programming-in-a-circular-queue\/"},"modified":"2006-12-22T14:09:22","modified_gmt":"2006-12-22T14:09:22","slug":"pathological-programming-in-a-circular-queue","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2006\/12\/22\/pathological-programming-in-a-circular-queue\/","title":{"rendered":"Pathological Programming in a Circular Queue"},"content":{"rendered":"<p>Today, I&#8217;m going to show you a very simple, very goofy little language called <a href=\"http:\/\/esoteric.voxelperfect.net\/files\/sceql\/\">&#8220;SCEQL&#8221;<\/a>, which standards for &#8220;slow and clean esoteric queue language&#8221;. It&#8217;s based on nothing but a circular queue<br \/>\nof numbers with nothing but 8 commands. It&#8217;s not one of the more exciting languages, but it can<br \/>\nbe a lot of fun to figure out how to make the circular queue do what you want it to.<\/p>\n<p><!--more--><\/p>\n<p>In SCEQL, you&#8217;ve got a circular queue of bytes. You can&#8217;t *ever* remove anything from the queue. You can alter values on the queue; move things from the front to the back; and add things to it. But that&#8217;s it.<\/p>\n<p>The commands are:<\/p>\n<table>\n<tr>\n<th>Instruction<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td><code>=<\/code><\/td>\n<td>Rotate the byte at the front of the queue to the back of the queue<\/td>\n<\/tr>\n<tr>\n<td><code>-<\/code><\/td>\n<td>Decrement the byte at the front of the queue.<\/td>\n<\/tr>\n<tr>\n<td><code>_<\/code><\/td>\n<td>Increment the byte at the front of the queue.<\/td>\n<\/tr>\n<tr>\n<td><code><\/code><\/td>\n<td>Loop: if the byte at the front of the queue is not zero,<br \/>\ncontinue executing at the next instructions; otherwise, jump to<br \/>\nthe instruction after the matching &#8220;<code>\/<\/code>&#8220;. Roughly<br \/>\nequivalent to BrainFuck &#8220;[&#8220;.<\/td>\n<\/tr>\n<tr>\n<td><code>\/<code><\/td>\n<td>End loop: branch back to the matching \"\/\". Roughly equivalent<br \/>\nto BrainFuck \"]\".<\/p>\n<tr>\n<td><code>!<\/code><\/td>\n<td>Grow queue: append a new zero byte to the end of the queue.<\/td>\n<\/tr>\n<tr>\n<td><code>&amp;<\/code><\/td>\n<td>Input a byte, and append it to the end of the queue.<\/td>\n<\/tr>\n<tr>\n<td><code>*<\/code><\/td>\n<td>Output the byte at the front of the queue, and then<br \/>\nappend it to the end of the queue.<\/tr>\n<\/table>\n<p> So, how would we write \"Hello world\"? Not too hard, actually. We need to  know the<br \/>\nascii values of the characters. In bytes in ASCII\/UTF-8 encoding, \"Hello world\" is the<br \/>\nsequence of bytes: [72,101,108,108,111,32,87,111,114,108,100,10].<br \/>\nSo, we need to have a total of 12 bytes on the queue. It starts with one 0, so we need to add 11. Then we need to generate each of those numbers.<br \/>\n<code><br \/>\n!!!!!!!!!!!<br \/>\n________________________________________________________________________=<br \/>\n_____________________________________________________________________________________________________=<br \/>\n____________________________________________________________________________________________________________=<br \/>\n____________________________________________________________________________________________________________=<br \/>\n_______________________________________________________________________________________________________________=<br \/>\n________________________________=<br \/>\n_______________________________________________________________________________________=<br \/>\n_______________________________________________________________________________________________________________=<br \/>\n__________________________________________________________________________________________________________________=<br \/>\n____________________________________________________________________________________________________________=<br \/>\n____________________________________________________________________________________________________=<br \/>\n__________=<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n*<br \/>\n<\/code><\/p>\n<p> Neat, huh? How about something slightly less trivial? Input two numbers and add them together? It's surprisingly hard in SCEQL, because the input and output is all done in bytes. So printing numbers isn't particularly easy. In fact, it's a royal pain. So, of course, the<br \/>\nsolution is: <b>cheat!<\/b>.  I added two new instructions: \"&lt;\" to read a number from<br \/>\nthe input, and \"&gt;\" to print a number to the output. (You can grab the interpreter extended with those two instructions <a href=\"http:\/\/scienceblogs.com\/goodmath\/upload\/2006\/12\/scecl.c\">here<\/a>. With those extensions, a program<br \/>\nto input two integers, add them together, and print them out is:<br \/>\n<code><br \/>\n&lt;&lt;==_==-\/=&gt;<br \/>\n<\/code><\/p>\n<p> That is, input two numbers, and add them to the end of the queue. Circle past the zero that<br \/>\nwas the initial value on the queue. If the first of the two numbers isn't zero, then rotate the queue to the second number, increment it, rotate back to the first and decrement it, and branch<br \/>\nback to beginning of the loop. After ending the loop, rotate to the second number (the result),<br \/>\nand print it out.<\/p>\n<p> Just for kicks, here's a long program in SCECL: \"99 bottles of beer\".<\/p>\n<p><code><br \/>\n\"99 bottles of beer\" song in Sceql.<br \/>\nWritten by Keymaker.<br \/>\nUses UNIX nl (dec 10) in output.<br \/>\n_________!=_________!!===_=!===\\-\/==-==_=_==\/==-===_==\/=____<br \/>\n____________________________________________*====-\/\/===________<br \/>\n________________________________________*====-------------------<br \/>\n-----------------------------======_____________________________<br \/>\n___*====________________________________________________________<br \/>\n__________*====_____________*====_____*====*====--------*====---<br \/>\n----*====-\/======_==-==_=--==\/==-===_==\/====-=_=-===\/=-====<br \/>\n_=\/=\\-\/________________________________________________________<br \/>\n___________________________________________________________*====<br \/>\n-\/\/====________________________________*====___________________<br \/>\n____________________________________________________________*===<br \/>\n=---------*====-\/________________________________*====_________<br \/>\n_________________________________________________________*====__<br \/>\n_*====*====_____________*====-\/________________________________<br \/>\n*====___________________________________________________________<br \/>\n____________________*====-*====-\/______________________________<br \/>\n__*====_________________________________________________________<br \/>\n___________________________*====------------*====---*====-\/____<br \/>\n____________________________*====_______________________________<br \/>\n________________________________________________________*====---<br \/>\n-------------------*====___________*====*====-\/________________<br \/>\n____________________________*====------------*====-\/===-==_=_=<br \/>\n=\/==-===_==\/=________________________________________________*<br \/>\n====-\/\/===________________________________________________*====<br \/>\n------------------------------------------------======__________<br \/>\n______________________*====_____________________________________<br \/>\n_____________________________*====_____________*====_____*====*=<br \/>\n===--------*====-------*====-\/======_==-==_=--==\/==-===_==\/==<br \/>\n==-=_=-===\/=-====_=\/=\\-\/_____________________________________<br \/>\n________________________________________________________________<br \/>\n______________*====-\/\/====________________________________*====<br \/>\n________________________________________________________________<br \/>\n_______________*====---------*====-\/___________________________<br \/>\n_____*====______________________________________________________<br \/>\n____________*====___*====*====_____________*====-\/_____________<br \/>\n_________________________________*====-\/__________*====________<br \/>\n________________________________________________________________<br \/>\n__*====_____________*====__________*====------*====-\/__________<br \/>\n______________________*====_____________________________________<br \/>\n__________________________________________*====-*====---------*=<br \/>\n===-\/________________________________*====_____________________<br \/>\n_______________________________________________*====___________*<br \/>\n====________*====---------*====-\/______________________________<br \/>\n__*====_________________________________________________________<br \/>\n________*====_____________*====----------*====-\/_______________<br \/>\n_________________*====__________________________________________<br \/>\n______________________________________*====---------------*====_<br \/>\n_________________*====*====-\/________________________________*=<br \/>\n===_____________________________________________________________<br \/>\n____________*====___________*====-\/____________________________<br \/>\n____*====_______________________________________________________<br \/>\n__________*====_________________*====---*====______*====-------*<br \/>\n====----------*====-\/__________________________________________<br \/>\n__*====------------*====-\/====-=_=_===\/==-===_==\/=_===\\-\/==-<br \/>\n==-=\/==-=-==_=_==\/===-==_===\/====\\-\/===-=_________=\/==\/=====<br \/>\n_=-==_=_==\/==-===_==\/====-=_=_===\/=-====_=\/=\\-\/=-=-==_=_==<br \/>\n\/==-===_==\/=________________________________________________*=<br \/>\n===-\/\/===________________________________________________*====-<br \/>\n-----------------------------------------------==\/=____________<br \/>\n________________________________________________________________<br \/>\n_________________________________*====_*====-\/_________________<br \/>\n_______________*====____________________________________________<br \/>\n_________________________________*====__*====___*====-----------<br \/>\n--*====-\/\/===________________________________*====_____________<br \/>\n_____________________________________________________*====______<br \/>\n_______*====_____*====*====--------*====-------*====-\/======_==<br \/>\n-==_=--==\/==-===_==\/====-=_=-===\/=-====_=\/=\\-\/_____________<br \/>\n________________________________________________________________<br \/>\n______________________________________*====-\/\/====_____________<br \/>\n___________________*====________________________________________<br \/>\n_______________________________________*====---------*====-\/___<br \/>\n_____________________________*====______________________________<br \/>\n____________________________________*====___*====*====__________<br \/>\n___*====-\/________________________________*====________________<br \/>\n_______________________________________________________________*<br \/>\n====-*====-\/________________________________*====______________<br \/>\n________________________________________________________________<br \/>\n______*====------------*====---*====-\/_________________________<br \/>\n_______*====____________________________________________________<br \/>\n___________________________________*====----------------------*=<br \/>\n===___________*====*====-\/_____________________________________<br \/>\n_________*====-\/__________*====*====-\/===-==_=_==\/==-===_==\/<br \/>\n====-==_=_==\/===-==_===\/====\/<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, I&#8217;m going to show you a very simple, very goofy little language called &#8220;SCEQL&#8221;, which standards for &#8220;slow and clean esoteric queue language&#8221;. It&#8217;s based on nothing but a circular queue of numbers with nothing but 8 commands. It&#8217;s not one of the more exciting languages, but it can be a lot of fun [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[92],"tags":[],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-44","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}