Live data from Hacker News

Ask HN: What is the most beautiful piece of code you've ever read?

news.ycombinator.com

211–220 of 394 posts

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#211
Didn't see anyone mentioned these two pearls:

C (K&R) program that calculates PI number by measuring circle that is its code: https://en.wikipedia.org/wiki/International_Obfuscated_C_Cod...

Perl one-liner that checks if a number is prime: perl -lne '(1x$_) =~ /^1?$|^(11+?)\1+$/ || print "$_ is prime"'

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#212
The code for the "A Mind is born" 256 byte Demo. It produces quite a neat music sequence and visuals. The code doesn't have a code equivalent but the binary version is understandable. This post is 256 bytes. https://linusakesson.net/scene/a-mind-is-born/

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#213
post #59

I like this bit of JavaScript for uniquifying an array: array.filter((item, index, arr) => arr.indexOf(item) === index) It works because indexOf returns the index of the first occurrence of the item, so you're asking whether this occurrence is the first occurrence.

I like this neat little code to filter out falsy values:

  array.filter(Boolean)

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#214
post #81

Earlier quoted context omitted.

I love the SQLite guy. His own version control, his own DB engine; you can tell from the site that he’s an individualist!

He mentioned on a podcast that he even uses his own text editor.

This reminds me of Chuck Moore (inventor of Forth). He designs his own CPUs, using his own CAD package, written in the programming language he invented!

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#215
post #23

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

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 ever read?

#216
post #23

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

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 ever read?

#217

Earlier quoted context omitted.

I dunno. The security ramifications of those few lines of code make me squirm. It's like looking at a very beautifully constructed foot gun. I wonder how much damage that code has caused.

At the time the code was written, the security ramifications were not quite the same as they are now. Even now, I would suggest that there are times where such a construction would be just fine.

Nit, but an important one: the security ramifications were just as large than as now, they were just largely unknown at the time.

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#219

Earlier quoted context omitted.

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.

What is a maze? One could argue that if the user perceives a maze, then it produces a maze.

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 ever read?

#220
post #66

I began coding in IBM/LCSI PC Logo. The first line of code I ever wrote was: FD 100 That's the "hello, world" of turtle graphics in Logo. While probably not as beautiful as the several splendid examples posted in this thread, that simple line of code changed my world. I could make stuff happen in an otherwise mostly blank monochrome CRT display. Until then I had seen CRTs in televisions where I had very little contro…

Oh man, PC Logo takes me back down the memory lane. We were introduced to PC Logo in 4th grade, that's about 9 years ago. I instantly fell in love with it. The amount of power I had over the computer - ordering it to draw what I want, how I want was really exciting. My father had installed Kubuntu on our home computer which had an amazing suite of educational applications, including KTurtle which was (almost) the sam…

I clicked on your blog and all the images are gray exclamation marks :(
Post reply on HN