News for hackers. Stuff that matters.
Re:Ask HN: What is the most beautiful piece of code you've e... by vatys on Sunday October 27, 2019 @11:32PM (#21374030)
For me it's a BASIC one-liner which generates mazes

  10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10
I found this specific one via slashdot[1], but something similar, which I've never managed to find/replicate, was used to generate mazes on the Atari 800 XL at my school when I was a kid.

[1] https://developers.slashdot.org/story/12/12/01/1847244/how-d...

Re:Ask HN: What is the most beautiful piece of code you've e... by th0ma5 on Monday October 28, 2019 @12:00AM (#21374132)
Re:Ask HN: What is the most beautiful piece of code you've e... by flohofwoe on Monday October 28, 2019 @09:20AM (#21376671)
Re:Ask HN: What is the most beautiful piece of code you've e... by codecritic on Monday October 28, 2019 @01:30AM (#21374521)
No, it does not generate a maze. It generates a random sequence of \s and /s, that can trigger a maze being generated in a typical user's mind.

This is the art of illusion.

Re:Ask HN: What is the most beautiful piece of code you've e... by henkslaaf on Monday October 28, 2019 @03:48AM (#21375023)
What is a maze? One could argue that if the user perceives a maze, then it produces a maze.
Re:Ask HN: What is the most beautiful piece of code you've e... by tenebrisalietum on Monday October 28, 2019 @06:55AM (#21375827)
> One could argue that if the user perceives a X, then it produces a X.

This can be stretched to turn anything into anything else. For example, why can't this comment be a maze? In that case 10 REM; 20 END is my even shorter, more elegant maze program because I see a maze in it.

Some constraints that are typically implied when people say "computer generated mazes":

- They are solvable (have a start and end)

- OR they loop endlessly with no dead ends.

- Walls and spaces consume 1 element on the grid.

- No space on the grid is surrounded by all 4 NWSE walls.

Re:Ask HN: What is the most beautiful piece of code you've e... by coldtea on Monday October 28, 2019 @11:28AM (#21377802)
>>One could argue that if the user perceives a X, then it produces a X. >This can be stretched to turn anything into anything else. For example, why can't this comment be a maze?

Because unlike the one-liner nobody perceives it as a maze, so the "this can be stretched to turn anything into anything else" argument is tenuous...

Re:Ask HN: What is the most beautiful piece of code you've e... by alanbernstein on Monday October 28, 2019 @07:38AM (#21376012)
I believe your third criterion is actually met by this generator. The grid is just tilted 45 degrees.
Re:Ask HN: What is the most beautiful piece of code you've e... by mygo on Monday October 28, 2019 @12:11PM (#21378232)
> This can be stretched to turn anything into anything else. For example, why can't this comment be a maze?

Name one person who perceives your comment as a maze.

It must be perceived as a maze by people for it to apply.

As it stands, I’m not sure if people perceive your comment as a maze.

Maybe theoretically there’s a nonzero number of people who perceive the comment as a maze. But unless your audience is those few people, there wouldn’t be much utility in it. In the OP’s example this maze perception is not only highly widespread but it’s also leveraged for a particular intended effect.

[dead]
Re:Ask HN: What is the most beautiful piece of code you've e... by maxerickson on Monday October 28, 2019 @10:16AM (#21377193)
The idea that words used in specific contexts can't have clear meanings is the more tedious thing.
Re:Ask HN: What is the most beautiful piece of code you've e... by ljm on Monday October 28, 2019 @04:36AM (#21375209)
Never expected to find myself on the path to enlightenment after reading a line of BASIC.
Re:Ask HN: What is the most beautiful piece of code you've e... by lmilcin on Monday October 28, 2019 @06:48AM (#21375791)
Maze has a starting point and a goal. The goal must be reachable from the start.
Re:Ask HN: What is the most beautiful piece of code you've e... by Intermernet on Monday October 28, 2019 @08:07AM (#21376137)
Only if you want to give the occupant of the maze a chance to escape :-)
Re:Ask HN: What is the most beautiful piece of code you've e... by wincy on Monday October 28, 2019 @09:26AM (#21376739)
So this would be more of a labyrinth than a maze?
Re:Ask HN: What is the most beautiful piece of code you've e... by cyphar on Monday October 28, 2019 @10:01AM (#21377056)
No, a labarynth is a single twisting route without branches. A maze has branches and thus can have dead-ends. Both must have an entry and exit point (technically mazes may have more than one exit and entry, but most don't).
Re:Ask HN: What is the most beautiful piece of code you've e... by Someone on Monday October 28, 2019 @01:31PM (#21379287)
That’s open for debate. https://en.wikipedia.org/wiki/Labyrinth:

”Although early Cretan coins occasionally exhibit branching (multicursal) patterns

[…]

both logic and literary descriptions make it clear that the Minotaur was trapped in a complex branching maze

[…]

In English, the term labyrinth is generally synonymous with maze. As a result of the long history of unicursal representation of the mythological Labyrinth, however, many contemporary scholars and enthusiasts observe a distinction between the two.”

Re:Ask HN: What is the most beautiful piece of code you've e... by jedberg on Monday October 28, 2019 @10:42AM (#21377418)
> a labarynth is a single twisting route without branches. A maze has branches and thus can have dead-ends.

I was today years old when I learned this.

Re:Ask HN: What is the most beautiful piece of code you've e... by tromp on Monday October 28, 2019 @09:39AM (#21376858)
Re:Ask HN: What is the most beautiful piece of code you've e... by misterman0 on Monday October 28, 2019 @06:58AM (#21375842)
Jeopardy this: Only then can you realize, there is no maze.
Re:Ask HN: What is the most beautiful piece of code you've e... by mojuba on Monday October 28, 2019 @07:37AM (#21376007)
Everything is an illusion. \s and /s are just liquid crystal pixels on the screen, filtering some light. However it's easier to say that if something has a name and you can identify it, then it's probably that thing. I see a maze it means it's a maze :)
Re:Ask HN: What is the most beautiful piece of code you've e... by coldtea on Monday October 28, 2019 @11:29AM (#21377821)
>I see a maze it means it's a maze :)

I'd suggest to not go bar-hopping in Thailand with that mindset...

Re:Ask HN: What is the most beautiful piece of code you've e... by Zhyl on Monday October 28, 2019 @12:12PM (#21378237)
Nice to see a bit of casual transphobia on hackernews.
Re:Ask HN: What is the most beautiful piece of code you've e... by coldtea on Monday October 28, 2019 @01:00PM (#21378831)
Nice to see confusing a joke reference to a regional fact (as to things that can seem X but be Y) with transphobia. Anybody told you that merely referencing trans women in Thailand is opposing them? Projecting much?
Re:Ask HN: What is the most beautiful piece of code you've e... by Zhyl on Monday October 28, 2019 @01:18PM (#21379104)
I'm amazed that you're defending that comment.
Re:Ask HN: What is the most beautiful piece of code you've e... by coldtea on Monday October 28, 2019 @02:41PM (#21380122)
Well, I am amazed that one can be so rude.

First, you come blazing with accusations of transphobia, because of a joking mention of Thailand's ladyboy scene, to challenge the parents' notion that everything is WYSIWYG. Do you even know me? Or you have a hobby of randomly assuming things about people you don't know?

Second, when I don't take that quietly, you add the above comment about having the gal to defend myself, going for the "This animal is extremely vicious. When attacked, it defends itself" angle...

Perhaps you can go even lower against some stranger on the internet, but you wont be getting any replies from me in this thread.

Re:Ask HN: What is the most beautiful piece of code you've e... by oliv__ on Monday October 28, 2019 @11:08PM (#21383974)
Good on you for standing for what you say. I personally didn't see any transphobia in your comment, what you said is merely a joke on a fact of that part of the world. The "phobia" was added on by Zhyl
Re:Ask HN: What is the most beautiful piece of code you've e... by Zhyl on Tuesday October 29, 2019 @09:03AM (#21386621)
The transphobia isn't related to the 'fact' about Thailand. If anything, the fact that it's a reference point is the reason why the sentiment is distasteful. The implication/joke is:

* A person goes into a bar in Thailand, sees what they think is a girl and are surprised to find that things are not what they seem.

Broken down:

* Person sees a girl

* It is not a girl

* This is a bad thing

Now, it would be easy to claim (as indeed you and GP seem to be doing) that this isn't a slur on the second party in this encounter. It's a fact of the world. They exist. OP, the person who is saying that 'things are what they seem to be' would probably not want to find themselves in a situation where they making an assumption that the person is female.

The fact that this is negative can be seen in the 'I hope you don't' words which set the tone and are the basis of most of the sarcasm. I have to say that even if GP had picked a different example, I don't like this kind of comment anyway. It's a bitter, jabby comment that I don't think furthers discussion and overall makes HN a more negative and uncomfortable place to be.

So an assumption I made, which of course is debatable, is that the setting of 'bar' implies a romantic or sexual intent on the first party. GP will probably deny or refute this, but really without this implication there isn't much of a joke to speak of. "I spoke to this girl and it turned out she was a dude! What larks we had!".

GP seems to be making this claim in this comment:

>Nice to see confusing a joke reference to a regional fact (as to things that can seem X but be Y) with transphobia. Anybody told you that merely referencing trans women in Thailand is opposing them? Projecting much?

If it was 'merely referencing' then it wouldn't be a joke. 'Merely referencing' would we to reword the comment as:

"Things are not always what they seem, like commonly accepted phenomena of Thaiwanese ladyboys".

I mean, not much different, and still in poor taste for a thread that is about beautiful code, but the tone of the comment is completely changed. It's now no longer a jab at the PC, but using a counterexample to illustrate a point.

And why is suggesting that someone being shocked to discover a ladyboy transphobic anyway? Basically, it boils down to the fact that trans people have to suffer against stigma that they're somehow 'out to trick' people and that unassuming straight males need to 'watch out'. This comment is a prime example of this. It's literally a warning. Sure, it's mild transphobia, but it's perpetuating this stigma and I feel like Hackernews generally, and this thread specifically, are not really places for this kind of comment.

I normally wouldn't write this much out about this topic, but GP seemed very upset about their comment being called transphobic. Note, I didn't call them transphobic at all. I didn't actually make any comment about them, their person, their intent or anything. Just that the comment was 'casual transphobia' which I firmly believe that it is.

Let's break down the rest of their comment:

>Well, I am amazed that one can be so rude.

In both cases they use my own words back to me. I'm not sure why. It seems to be a mix of defensiveness and sarcasm. I don't actually think I was being rude - certainly no ruder than they were being to who they were commenting to. I felt that their original comment was snide.

>First, you come blazing with accusations of transphobia

I called the comment transphobic. Addressed above.

>to challenge the parents' notion that everything is WYSIWYG

Not very well.

>Do you even know me? Or you have a hobby of randomly assuming things about people you don't know?

This is incredibly defensive. Especially the second part. It's not enough to call out transphobia, they have to then pile on unfounded accusations of 'randomly assuming things about people' I don't know. I think the irony of this is amazing. They're literally accusing me of doing exactly what they're doing. It's like a bad girlfriend stereotype. (If you want to do some whataboutism, why not pick apart the inherent sexism of that comment? I'll give you a starter for 10 by lampshading it).

>econd, when I don't take that quietly, you add the above comment about having the gal to defend myself, going for the "This animal is extremely vicious. When attacked, it defends itself" angle...

So GP edited this comment a couple of times. Originally this was basically all there was. 'Having the gal' to defend themselves is a laugh. There was no self reflection, no admission that what they wrote could have been seen as transphobic. Just immediately jump to a victim paradox. 'Poor old me being attacked by nasty SJW just for merely mentioning ladyboys. Is it a crime? What did I do wrong????'

>Perhaps you can go even lower against some stranger on the internet, but you wont be getting any replies from me in this thread.

I mean I love this sign off. It's the reason I knew I had gotten to them and the reason I didn't reply. They didn't want to hear it. It was clear they weren't going to learn, and in fact they're telling me that they don't want a response anyway. I love the way that they're so deep in the role of the victim that they think I'm going to go off and harass more strangers. It's a lovely thought, but I don't do that. I just calls em as I sees em.

So anyway, I'm glad that you don't see the transphobia, but I don't think I was wrong to call them out on what I saw as implied transphobia.

Re:Ask HN: What is the most beautiful piece of code you've e... by rebuilder on Monday October 28, 2019 @04:17AM (#21375136)
Is the user then not amazed?
Re:Ask HN: What is the most beautiful piece of code you've e... by zaarn on Monday October 28, 2019 @06:15AM (#21375646)
A maze does not have to be solvable.
Re:Ask HN: What is the most beautiful piece of code you've e... by misterman0 on Monday October 28, 2019 @07:05AM (#21375874)
Re:Ask HN: What is the most beautiful piece of code you've e... by jointpdf on Monday October 28, 2019 @12:23AM (#21374254)
There’s actually an entire book on this at: https://10print.org/
Re:Ask HN: What is the most beautiful piece of code you've e... by nacs on Monday October 28, 2019 @11:44AM (#21377954)
324 page book originating from 1 line of code! Amazing.
Re:Ask HN: What is the most beautiful piece of code you've e... by barbs on Monday October 28, 2019 @01:10AM (#21374453)
Was kinda hoping the maze on the left was procedurally generated.
Re:Ask HN: What is the most beautiful piece of code you've e... by zmix on Monday October 28, 2019 @01:07AM (#21374437)
This book is some nice addition to "Computer Culture".
Re:Ask HN: What is the most beautiful piece of code you've e... by tyingq on Monday October 28, 2019 @06:32AM (#21375731)
Perl version if you don't have a BASIC interpreter handy:

perl -C -e 'print chr(9585.5+rand) while 1'

Re:Ask HN: What is the most beautiful piece of code you've e... by pcvarmint on Monday October 28, 2019 @09:09PM (#21383421)

  Wide character in print at -e line 1.
Re:Ask HN: What is the most beautiful piece of code you've e... by tyingq on Monday October 28, 2019 @10:18PM (#21383733)
Oh, Windows maybe? add:

binmode(STDOUT);

To the front.

Unicode on languages made before it existed is...argh.

Re:Ask HN: What is the most beautiful piece of code you've e... by symplee on Monday October 28, 2019 @12:30AM (#21374283)
What is the probability that it prints a completable[0] maze?

Expressed in terms of line width (w) and number of lines (n).

[0] Where there's a valid path from the first line to the last.

Re:Ask HN: What is the most beautiful piece of code you've e... by scrollaway on Monday October 28, 2019 @01:01AM (#21374404)
1/2^n, I believe (where n is the number of lines after the first one, otherwise 1/2^n+1). So halved every time: 100% with 1 line, 50% with 2 lines, 25% with 3 lines, and so on. Width is irrelevant (you can do this in your head comparing w=1 n=2 to w=2 n=2 for example).

Edited for clarity and accuracy.

Re:Ask HN: What is the most beautiful piece of code you've e... by Const-me on Monday October 28, 2019 @03:04AM (#21374869)
One line, not completable:

    /\/\/\/\
Also, I don't believe it doesn't depend on width. I think with constant height, the probability of completable one should increase with width, and become almost 1 for very large widths.
Re:Ask HN: What is the most beautiful piece of code you've e... by scrollaway on Monday October 28, 2019 @03:13AM (#21374900)
Hm, good points, looks like I need more sleep. Looking at the video again, a path is valid if two slashes follow each other, with the same pattern shifted by 1 the line below.

But I wasn't treating /\ as an invalid on the first line. Eg thinking of:

    /\/\/\/\
    \\//////
    /\\\\\\\ … and so on
(Using the /\ pattern, paths can go back up and come back down, so this requires a lot more thought than I instinctively put into it)
Re:Ask HN: What is the most beautiful piece of code you've e... by ssdsa on Monday October 28, 2019 @04:07AM (#21375093)
This, as a WebGL shader in shadertoy: https://www.shadertoy.com/view/ld23DW
Re:Ask HN: What is the most beautiful piece of code you've e... by Waterluvian on Monday October 28, 2019 @12:05AM (#21374154)
Oh wow this is a cool loop closure. I wrote a CHIP 8 emulator to learn stuff and my main test rom was this program. I walked through the bytecode very slowly as I learned and debugged and repeatedly wondered how the heck the program was so tiny.
Re:Ask HN: What is the most beautiful piece of code you've e... by zmix on Monday October 28, 2019 @12:57AM (#21374389)
Wow! This is really cool. I just entered it quickly in a C64 emulator and it ran, creating a maze. Not sure, whether it would be a solvable one, but it is interesting to note, that the paths are really connected!
Re:Ask HN: What is the most beautiful piece of code you've e... by tasuki on Monday October 28, 2019 @03:37AM (#21374986)
> the paths are really connected!

What do you mean by that?

Re:Ask HN: What is the most beautiful piece of code you've e... by zmix on Monday October 28, 2019 @12:26PM (#21378398)
The paths make sense. I.e. you got uninterrupted lines, surrounded by walls, so it is a real maze and not just a lookalike or partial maze. Oh, and it's a-maze-ing! :-)
Re:Ask HN: What is the most beautiful piece of code you've e... by tasuki on Tuesday October 29, 2019 @05:31AM (#21385355)
I'm still not sure what you mean. It just prints / and \ randomly. What is a maze lookalike and partial maze? Would you mind sharing any examples?
Re:Ask HN: What is the most beautiful piece of code you've e... by kwoff on Monday October 28, 2019 @09:32PM (#21383547)
If we define "elegant" as getting a lot done with a little, another BASIC (kinda..) one: https://linusakesson.net/scene/a-mind-is-born/ (The last part of the song is so great, too.)
Re:Ask HN: What is the most beautiful piece of code you've e... by _jon_ on Monday October 28, 2019 @04:30AM (#21375189)
The mysterious maze algorithm of Atari game Entombed: https://www.bbc.com/future/article/20190919-the-maze-puzzle-...
Re:Ask HN: What is the most beautiful piece of code you've e... by ElCapitanMarkla on Monday October 28, 2019 @10:10AM (#21377144)
That was great, thanks
Re:Ask HN: What is the most beautiful piece of code you've e... by lasagna_coder on Monday October 28, 2019 @10:53AM (#21377509)
while [ 1 ]; do for i in `seq 1 80`; do printf "\xE2\x95\xB$(( ( RANDOM % 2 ) + 1 ))"; done; printf "\n"; done
Re:Ask HN: What is the most beautiful piece of code you've e... by gpsx on Monday October 28, 2019 @11:42AM (#21377934)
That is very cool, but does it produce no branches?
Re:Ask HN: What is the most beautiful piece of code you've e... by morazow on Monday October 28, 2019 @06:37AM (#21375746)
ohh wow,

I remember being fascinated with Pascal program that makes snow fall.

Basically, it was white dots on a blue background in an infinite loop. :)

Re:Ask HN: What is the most beautiful piece of code you've e... by cr0sh on Monday October 28, 2019 @12:15PM (#21378256)
Somewhere I have a copy of a BASIC program I typed into my TRS-80 Color Computer as a kid, from an issue of K-Power magazine.

I don't recall if it was one of the full issues, or one of the "insert issues" found within Family Computing of the era.

It was a special kind of "snow fall" generator; IIRC, there were only a couple of versions, one for the Apple IIe and the other for the PCjr - I likely used the PCjr version for the conversion since the BASIC language was nearly identical between the PCjr and my CoCo 2.

What was special was that it managed to seemingly move hundreds of pixels relatively rapidly on the screen; now, this might not seem like such a feat, but it really was considering we're talking about a computer system running an interpreted BASIC program, with a max speed below 1 MHz in standard mode (0.89 MHz - there was a so-called "speedup poke" that "doubled" the speed - POKE 65495,0 if anyone cares).

I don't recall what trick it used - or if it really used anything special at all - but I do remember being impressed by that bit of code.

Re:Ask HN: What is the most beautiful piece of code you've e... by Shinchy on Monday October 28, 2019 @06:15AM (#21375643)
I love it!