https://www.cs.princeton.edu/courses/archive/spr09/cos333/be...
Ask HN: What is the most beautiful piece of code you've ever read?
291–300 of 394 posts
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#292NEW 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…
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#293I 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…
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#294This 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"
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?
#295Earlier 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 :(
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?
#297Earlier 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?
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#298John 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....
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#299For 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-...
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#300The 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…
fibs = 0 : scanl (+) 1 fibs