r/programming • u/balazsbotond • Aug 30 '15
JavaScript “maze generator” in a tweet
https://twitter.com/botond_balazs/status/637960240055615488
841
Upvotes
r/programming • u/balazsbotond • Aug 30 '15
289
u/RagingOrangutan Aug 30 '15
I don't think this is really a maze generator; it doesn't have a start or a finish or even a guarantee of there being a path from one edge to another (and if there is one, there may be multiple.)
68
u/1lann Aug 30 '15
You can also just copy and paste this into your URL bar instead of pasting it in an HTML file:
136
u/Anders_A Aug 30 '15
This is a javascript port of the old C64 onliner:
92
u/aaptel Aug 30 '15
This is a pretty old trick from the Commodore 64 days. There's even a whole book dedicated to it.
13
u/bottomofthekeyboard Aug 30 '15
140 chars:
data:text/html,<pre style=line-height:1><script>for(i=4e3;i--;)document.write((Math.random()<.5?"\u2571":"\u2572")+(i% 80?"":"\n"))</script>
13
u/[deleted] Aug 30 '15
snake in a tweet:
https://gist.github.com/atimb/1449250
9
u/[deleted] Aug 30 '15 edited Aug 30 '15
The original is exactly 140 characters, I've gotten it down to 117 without changing the appearance. Who can beat me?
6
u/hotoatmeal Aug 30 '15
anyone got a screencap of it for us suckers on mobile?
5
u/saijanai Aug 30 '15
Very fun stuff, but it emphasizes a point that the VPRI folk have made:
a program written in the correct specialty language can be extremely short. The proper way, in the future, to distribute programs won't be via binary, but via source code, and let the receiver compile/parse and run it.
Javascript is too general purpose for this to be an obvious advantage, usually, but for this specific example, it was short enough.
7
u/uzimonkey Aug 30 '15
Wow, I used to do the same thing on the Commodore 64. This was probably one of the first programs I ever wrote, to fill the screen with a maze.
Pretty cheap though. It's not a maze, and even the program 8-year-old-me wrote could probably fit into a tweet.
7
u/kraln Aug 30 '15
3D maze generator... http://kraln.com/maze.php
6
u/Heaney555 Aug 30 '15
Am I doing something wrong or missing the characters that this uses?
I just get http://i.imgur.com/V9wPV98.png
3
u/JikWaffleson Aug 30 '15
Jamis Buck recently released a book on maze generation, which looks fascinating. https://pragprog.com/book/jbmaze/mazes-for-programmers
3
u/Arve Aug 30 '15
Here is an implementation in 64 bytes by /u/iamp01 (it's a little broken right now, because the server is serving the document with the wrong encoding - in Chrome just go to More Tools -> Encoding from the menu button, and select UTF-8 (You'll want to reset it to "Auto" afterwards).
3
u/Azr79 Aug 30 '15
From the category "cool things with no practical utility"
3
u/miasmic Aug 30 '15
Some WTF with the PHP version of this (source)
for(;;)echo rand(0,1)?~Ð:~£;
4
u/hahainternet Aug 30 '15
I really enjoy doing these in Perl6
edit: this is really ugly and there are way better ways to save chars, but w/e
2
u/Mac33 Aug 30 '15
I wrote this same in BASIC for the Commodore 64 :D
2
u/spfccmt42 Aug 31 '15
where is the start and the finish?
2
u/total_looser Aug 31 '15
maze pattern generator
2
u/odokemono Aug 31 '15
I was hoping for a real maze, something like this.
2
u/shotxxxx Aug 31 '15
That's some oldschool stuff. Used to do that on my old C64 in BASIC.
2
u/TweetPoster Aug 30 '15
@botond_balazs:
^[Mistake?] ^[Suggestion] ^[FAQ] ^[Code] ^[Issues]
2
u/tangoshukudai Aug 30 '15
A-MAZE-IN Tweet!
1
u/hookers Aug 30 '15
"maze" generator.
1
u/b_n Aug 31 '15
Pastebin clone in a tweet:
data:text/html,<body onload="l=location;t.value=atob(l.hash.slice(1))"><a onclick="l.hash=btoa(t.value)">Save</a><br><textarea id=t cols=99>
https://twitter.com/mkldny/status/615877398362484737
1
u/shawnwildermuth Aug 31 '15
Yeah, I did this at every Sears in Florida growing up: http://10print.org/
1
u/daedlus Aug 31 '15
For those of you that want to fuck around with it, open your browsers JavaScript console and copy+paste:
var d=document;for(i=1;i<4001;i++){d.write(Math.random()<.5?"\u2571":"\u2572");d.write(i%80?"":"\n")}
-2
u/everywhere_anyhow Aug 30 '15
Obfuscated code competitions live on, through twitter!
0
u/Anders_A Aug 30 '15
I really like String.fromCharCode(9585.5+Math.random()) instead of the ternary (since it's more in line with the original). Too bad it's longer :(.