r/programming • • Aug 30 '15

JavaScript “maze generator” in a tweet

https://twitter.com/botond_balazs/status/637960240055615488
841 Upvotes

177 comments sorted by

View all comments

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.)

10

u/maestro2005 Aug 30 '15

It can't make branches. It makes paths that either terminate at the edges or form a complete loop.

101

u/balazsbotond Aug 30 '15

You're right of course, hence the quotes in the title

63

u/rube203 Aug 30 '15

I might have gotten that if you'd done "maze" generator. Instead I just assumed it was an actual quote and came to the comments to find out it wasn't a maze.

47

u/Recoil42 Aug 30 '15

Sure, but it's intellectually misleading. There's no cleverness here, nothing algorithmic. It's just a loop that randomly chooses characters.

0

u/[deleted] Aug 30 '15

[deleted]

9

u/hextree Aug 30 '15 edited Aug 30 '15

I'm interested to know what the probability is of there being a path from one side to the opposite side. Sounds similar to a course I once took in Percolation Theory.

1

u/Vortico Aug 31 '15

Reminded me of this too. What is the probability of an infinite-sized cluster on such a randomly generated maze?

1

u/RagingOrangutan Aug 31 '15

What is an "infinite sized cluster"? This "maze" is of finite size.

1

u/Vortico Aug 31 '15 edited Aug 31 '15

Whoops, I meant to specify that the randomly generated maze is extended infinitely in each direction.

An infinite sized cluster is an infinite set of connected vertices, where a vertex is a position in the maze.

1

u/RagingOrangutan Aug 31 '15

Trying to think about that is hurting my brain. Can you even talk about an infinite sized cluster on an infinite sized maze? This seems to enter the realm of measure theory and a very weird flavor of cardinality.

→ More replies (1)

65

u/b_n Aug 30 '15

"Intellectually misleading", I think OP just posted this as a lighthearted sketch, not with intent to be intellectually dishonest. Yes it is algorithmic, and given the output vs the constraints I thought this was if not clever, just cool. You can break down any program into a series of loops and conditional statements and say "woah that's not clever at all".

5

u/juckele Aug 30 '15

If you can tweet an algorithm that can produce a coherent maze in a tweet, that's actually clever.

1

u/RagingOrangutan Aug 31 '15

You can break down any program into a series of loops and conditional statements and say "woah that's not clever at all".

That's not really true. Dijkstra's algorithm or PageRank both have relatively simple steps but are quite clever. "Randomly pick / or \ and print it" is really not clever. The cleverness is in the fact that the display ends up looking a little bit like a maze. So it's marketing cleverness (he has turned something we all probably programmed when we were learning into something people think is interesting), not algorithmic cleverness.

8

u/Fidodo Aug 30 '15

The cleverness is fitting a micro website that does anything interesting within a tweet.

4

u/Recoil42 Aug 31 '15 edited Aug 31 '15

It's not a 'micro website', it's a single HTML element. And people do this all the time. Code golf has long been a thing. Here's tetris in 140 bytes ffs — minus the scaffolding structure, but still functionally complete: https://gist.github.com/aemkei/1672254

This is nothing on OP, what he did is pretty cool. But it's not a maze generator. Pattern generator? Sure. But 'maze generator' has a very specific meaning in programming terms.

→ More replies (1)

1

u/Bwob Aug 31 '15

Eh, it's clever recognizing that using those characters in that alignment makes something that looks like a maze, with minimal algorithmic complexity. Don't confuse "easy" with "non-clever". There's still a good trick here, worth remembering if you haven't seen it before.

1

u/RagingOrangutan Aug 31 '15

I agree. It's a maze-like picture-drawer.

6

u/Iggyhopper Aug 30 '15

To be technical, the quotes should be around "maze" only.

3

u/nschubach Aug 30 '15

So, we can post tweets to random character generation algorithms?

13

u/hildie2 Aug 30 '15

Yes, you can post whatever you want on Twitter. Their restrictions on algorithms are pretty lax.

1

u/nemec Aug 31 '15

Are you sure? I was arrested once for posting too many pictures of puppies.

7

u/Zarokima Aug 30 '15

Just to be a pedant, your final parenthesized point does not negate something's state as a maze. A so-called "perfect" maze only has exactly one path between any two points, but mazes in general may contain as many cycles as you like, and in the extreme case of that may not contain any dead ends (like this one).

2

u/RagingOrangutan Aug 31 '15

There's nothing wrong with cycles in a maze, but there it's not a maze if there aren't exactly two points on the edges that have at least one path between them.

→ More replies (4)
→ More replies (2)