A single line of Basic sends readers into a labyrinth
slate.com
slate.com
yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash
Source and credit: http://stackoverflow.com/a/13612327
I can't believe I've programmed for 15 years without knowing about this.
for (;;) { write-host -n (get-random ╱,╲) }
Obviously this requires a font supporting those characters. MS Mincho seems to serve well: http://www.microsoft.com/typography/fonts/font.aspx?FMID=206
for (;;) { write-host -n (get-random /,\) }
It's kind of nice with _ and | too : for (;;) { write-host -n (get-random '_','|') }echo 'loop do print ["\u2571","\u2572"].sample end'|ruby
echo 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'|ruby
ruby -e 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end' ruby -e 'print %W{\u2571 \u2572}.sample while sleep 1e-3'
(Updated: Made 3 chars shorter.)And a shorter, but cheats, version:
yes|ruby -pe'$_=%W{\u2571 \u2572}.sample;sleep 1e-3'
My favorite overall balance of readability and shortness though is: ruby -e 'print %w{╱ ╲}.sample while sleep 0.01'The C64 had magic. I miss my old C64.
Lots of fun. Use it to make old stuff like this feel more authentic, or just run your builds in it and tell your housemates you're haxxing teh gibson.
TBH though the reason it doesn't feel the same is ultimately because you're not the person you were 20-30 years ago, whoever that was. Nothing to do with the code or its execution environment.
|| __ # (2 pipes, one space, 2 bars)
seems to work pretty well, tooI shortened it a bit:
Still not as elegant as the Basic version.
This is one of the big downsides of how javascript is implemented in the browsers these days. There is no simple way to redraw the screen. You have to turn your whole program into a state machine and work with timouts just to display something.
for(i=1;i<300;i++) document.write(i % 30 == 0 ? "<br>" : (Math.random()>0.5) ? '\u2571' : '\u2572');
A throttled run-forever version.
edit, slightly neater:
(function draw(i){ setTimeout(function (){ document.write(i%30==0 ? '<br>' : Math.random()>0.5 ? '\u2571':'\u2572'); draw(i+1); }, 100) }(1))
Beautiful statement. So much unintentional irony, and at the same time so very true in this context.
JS: for(i=0;i<1000;i++) document.write(['\u2571\u200B', '\u2572\u200B'][(Math.floor((Math.random()*2)))])
CSS: body {line-height: 1}
echo "# -*- coding: utf-8 -*-\\nfrom random import choice\\nwhile(True):\\n print(choice(\"╱╲\"), end='')" | python3
or python3 -c 'exec("from random import choice\nwhile(True):\n print(choice(\"╱╲\"), end='"''"')")'
(Oh, the fun of deeply nested quote escaping!)The exec/echo thing being required since we need multiple lines, because while ';' is the statement separator python barfs on "import foo; while (True): pass". Bug or spec?
Only simple statements may be separated by a ';', not compound statements.
This is a bit different than what you wrote. For example, "x=4" is a statement, and not an expression, but "x=4;y=5;z=6" is a valid Python line because assignment is a simple statement, and multiple simple statements may be separated by a ';'.
python3 -c "`echo -e 'import time\nwhile True:\n print(u"\u2571\u2572"[int(time.time() * 100)%2],end="")\n time.sleep(0.001)'`"
The neat thing about it is that the randomness comes from the inexactness of time.sleep python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))"
and it's shorter too !wm/sh -c 'load std mpexpr;while{}{unicode -t ${expr 2571 1 rand +}}'
perl6 -e 'loop { print <9585 9586>.roll.chr }'
In fact, perl6 -e 'loop { print <╱ ╲>.roll }' will work too if your terminal is set up properly.
while true; do c=(╱ ╲);printf ${c[RANDOM%2]}; sleep .0001; done
The cool thing was that I forgot to write the bounds check to make sure the ant stayed inside the framebuffer! So the ant would happily trundle off-screen, encounter arbitrary bits that were in that memory, and would often eventually return back on the screen from a different location. Or sometimes (probably due to encountering zeros offscreen) it would run a lap around the edge of the screen and then veer back inward.
Langton's Ant: http://en.wikipedia.org/wiki/Langtons_ant
http://chengsun.github.com/walk.html
I still am a "kid", and it amuses me that I'm making the same stuff on modern platforms that have already been done on DOS machines by kids like me.
Printers don't generate text. It looks like text, but it's really just ink on paper.
The point is that real labyrinths have properties these pseudo-labyrinths don't. To be specific:
> In colloquial English, labyrinth is generally synonymous with maze, but many contemporary scholars observe a distinction between the two: maze refers to a complex branching (multicursal) puzzle with choices of path and direction; while a single-path (unicursal) labyrinth has only a single, non-branching path, which leads to the center. A labyrinth in this sense has an unambiguous route to the center and back and is not designed to be difficult to navigate.
1. Attempt to faithfully simulate an underlying process. An example: procedurally generate canyons by simulating water flow and erosion. Dwarf Fortress tries to take this one to its logical conclusion, doing things like simulating thousands of years of history in order to decide where to place things.
2. Produce an algorithm that mimics a desired result without necessarily using a process even close to what produced the original. Often this involves attempting to capture patterns in the original without attempting to capture why those particular patterns arose. Many grammar-based methods take this approach, such as the classic "shape grammars" used in architecture, as do data-mining approaches.
This book looks at something closer to #2 from the perspective of procedural faithfulness. But it's a variant that was particularly popular in early algorithmic art: pick an algorithm that has interesting outputs, tweak it, and see what you can do with the results. So in a sense it's closer to #1 in that its macro-properties are emergent, rather than being specifically optimized for (it's not doing things like solving for path reachability).
If generating a city, for example, you could attempt any of these approaches. You could build a little artificial agent society where you simulate agents going to work, having families, buying houses, etc., and their actions produce a city. Or, you could play with hand-coded city-generation algorithms that produce interesting patterns, and go with one. Or, you could choose specific targets or constraints (maybe culled from databases of real city geometry) and use constraint-solving or genetic algorithms or generative machine-learning algorithms to produce the desired results. Different pros and cons.
It's something I've been thinking a bit about lately, because I've been trying to understand the landscape of systems that claim to do "automated game design" [1]. Much of the work takes a simulation-based approach: tries to come up with a theory of what makes a game "balanced" or "fun", and optionally also simulates a broader theory of game design, playtesting, and revision. But another approach is to view it as crafting generative spaces of game variants, which is more of a theory of how game structure can vary than a theory of why it varies, and gives a different (not clearly better or worse) angle on the problem.
[1] http://www.kmjn.org/notes/generating_mechanics_bibliography....
For instance, some spaces are clearly enclosed. i.e., there is a finite border outside which you cannot escape. Some paths seem to run on for a very long time. Are all paths enclosed? If so, given a random point on a randomly generated maze, what is the average area of an enclosure?
#include <stdio.h>
main() { for(;;) {printf(rand()%2 ? "╱":"╲"); if(rand()%100<1) putchar(' ');} }http://mitpress.mit.edu/books/10-print-chr2055rnd1-goto-10-0
Still, I would pay $9.99 for mobi or epub. PDF is inconvenient for the Kindle and the iPad. Converting with Calibre is a chore, and rarely yields good results.
The code itself is simple. CHR$(205.5 + RND(1)) becomes CHR$(205) or CHR$(206) depending on the random number. 205 generates a \ , and 206 generates a /.
10 PRINT MID$("/\",1.5+RND(1),1);:GOTO 10
Run it on another old-school computer, like an Apple II, and you won’t get the same transfixing result, for details that have to do with the Commodore 64’s character set, called PETSCII. main() { while (1) printf("%c", rand()%2 ? '/' : '\\'); }
Edit: Golfed my original snippet down, then put back original after mmphosis's identical translation. #include <stdio.h>
main() { for(;;) printf(rand()%2 ? "/" : "\\"); }void main() { while (1) printf("%c", "/\\"[rand()%2] ); }
perl -e '$ |= 1; binmode(STDOUT, ":utf8"); while (1) { print chr(9585.5 + rand()); select(undef, undef, undef, 0.01); }'10 PRINT TOCHAR 13.5 + RANDOM; GOTO 10 RUN
I prefer the hopelessly lost maze variant! :>
10 PRINT TOCHAR 222.5 + RANDOM; GOTO 10 RUN
(let loop () (display (list-ref '("╱" "╲") (random 2))) (loop))
Use `racket -e <expr>` tu run it directly, for Guile it should work with `guile -c <expr>` but it seems that the unicode charaters make it crash (however it works if you copy the line of code in Guile's REPL rather than on the command line with -c).var r = 0; function go(){setTimeout('document.write(r++ % 80 ? Math.round(Math.random()) ? "\\\\" : "/" : "<br>"); go()', 100)}; go();
This was actually a lot more difficult for me to write than I thought it would be. `document.write` blocks and also a browser doesn't wrap by default, hence the r variable.
This will, of course, nuke any page you happen to run it on. :)
P.S. Why is code formatted so badly on HN these days? Until that's fixed I'll just use normal formatting.
7C 00 20 D2 FF A1 85 29 01 E9 92 D0 F5
(Save this as a .prg file and run it in your favourite C64 emulator or on the real thing itself. Please note that the first two bytes are actually required by .prg file format to indicate load address. The actual code is 11 bytes).
For more information:
python -c 'import random; print "".join(random.choice(r"/\\") for i in range(80*24))' python -c 'import random; print "".join(random.choice([u"\u2571",u"\u2572"]) for i in range(80*24))'import java.util.Random;
public class Maze {
public static void main(String[] args) {
String[] blah = new String[] { "╱", "╲" };
Random rng = new Random();
for (;;) {
System.out.print(blah[rng.nextInt(2)]);
}
}
}while (1) echo rand (0,1) ? "╱" : "╲";
php -r 'while (1) echo rand (0,1) ? "╱" : "╲";'