Live data from Hacker News

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

news.ycombinator.com

291–300 of 394 posts

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

#292
post #108

NEW 10 PRINT "HELLO" 20 GOTO 10 30 END RUN I remember typing this on an ASR-33 and being amazed. I made a computer do that. Then I hit Ctrl-C and learned how to make a paper tape with a "here is" leader, turning the paper punch off, then typing "LIST" and turning it back on before hitting RETURN. A PDP-11/10 with 16K and 3 20mA TTYs connected, no disks, no storage except paper tape. I've still got that paper tape som…

Had a KSR-33 wired up to a Synertek single-board 6502 kit... never did get the paper tape working, but man was it weirdly cool to be typing on a 50 pound behemoth to put numbers in the 2kB memory of a 6 ounce PC board.

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

#293
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…

For all you Logo fans out there, you should really play "Duskers". It's Logo meets Aliens.

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

#294

This is very common in Elm but it blew my mind after years of programming in Python. In Python it is very easy to raise an IndexError by getting an element from a list by index that doesn't exist. eg. # python names = [] names[0] # In Elm you are forced to always consider this possibility. # Elm names = [] case List.head names of Just name -> name Nothing -> "empty"

This always felt weird to me given that Python does a good job with dict:

    d = {}
    assert(d.get("blah"), None)
I was impressed by Rust the first time I run into:

    let mut last;
      for i in &[1, 2, 3] {
          last = i;
      }   
    println!("{}", last);

  >> borrow of possibly uninitialized variable: `last`

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

#295
post #220

Earlier quoted context omitted.

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 :(

Wayback Machine to the rescue: https://web.archive.org/web/20121023081714/https://kturtleco...

I recommend adding bookmarklets for Wayback Machine: https://en.wikipedia.org/wiki/Help:Using_the_Wayback_Machine...

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

#296

  ,[.,]
When it comes to the weird and wonderful world of esoteric programming languages, the above Brainfuck program is pretty elegant. It's a basic implementation of the echo program: printing back what the user inputs.

The complete language consists of eight single-character commands. The four used in the echo program is:

, – accept one byte of input and store it at the current memory cell

. – output the byte at the current memory cell

[ – if the value of the current memory cell is zero, jump forward to the command after the matching ]

] – if the value of the current memory is nonzero, jump back to the command after the matching [

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

#297
post #281

Earlier quoted context omitted.

Maze has a starting point and a goal. The goal must be reachable from the start.

So this would be more of a labyrinth than a maze?

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

#298
post #144
post #7

John Carmack's Fast Inverse Square Root: https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overv... . The first time I really and truly felt that people approach problems differently from how I, by default, go about them.

it's the antithesis of maintainable code. But given that one is unlikely to want to change from calculating the inverse square root to inverse cube root or any other variation....

it's a NUMBER - there's zero maintenance required for a number of constant value.

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

#299
post #166
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...

The mysterious maze algorithm of Atari game Entombed: https://www.bbc.com/future/article/20190919-the-maze-puzzle-...

That was great, thanks

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

#300
post #24

The one that blew my mind when I was in college was a simplified version of quicksort in Haskell. It's just so elegant and clean. quicksort :: Ord a => [a] -> [a] quicksort [] = [] quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) where lesser = filter ( = p) xs Now surely someone may come along and point out how this isn't a true quicksort[0] because it doesn't partition the elements in place, but…

When it comes to Haskell, this function that generates all the fibonacci numbers did it for me:

  fibs = 0 : scanl (+) 1 fibs
Post reply on HN