Live data from Hacker News

Ask HN: What's your favorite elegant/beautiful algorithm?

news.ycombinator.com

411–420 of 507 posts

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#411

Earlier quoted context omitted.

`git bisect` is an indispensible git trick. You give it commit where you know the bug exists, and one where you know it doesn't and it'll use binary search to help you find where the bug came from. It's absolutely wonderful.

I always struggle to see why people bang on about git bisect. You need tests to make it work. If you have tests, why aren't you running them continuously? If you're running them continuously, why do you need git bisect?

Because your tests didn't have 100% coverage.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#412

Earlier quoted context omitted.

`git bisect` is an indispensible git trick. You give it commit where you know the bug exists, and one where you know it doesn't and it'll use binary search to help you find where the bug came from. It's absolutely wonderful.

I always struggle to see why people bang on about git bisect. You need tests to make it work. If you have tests, why aren't you running them continuously? If you're running them continuously, why do you need git bisect?

If the bug is a regression, you write the test after finding it, and execute it with git-bisect. If the test starts to pass, you have the commit where it will fail.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#413
post #174

Earlier quoted context omitted.

Any suggestions where I can read about the BitTorrent protocol?

I implemented a BitTorrent client as a sophomore in college, available here: https://github.com/war1025/Torrent It worked pretty well. Used it for several years until I started making real money and decided I could buy things rather than pirate them. I had only been coding for a year or two at that point, so it is probably filled with lots of odd choices, but it also isn't super optimized like I would guess the more…

[deleted]

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#414

Earlier quoted context omitted.

Nice in theory, but in practice you wouldn't implement it like that, especially if the words can be longer than your machine integer allows. Sorting and comparing is more elegant than invoking a BigNum library, imho (and has smaller footprint). This shows that theoretical elegance != implementation elegance.

The title asked for beautiful/elegant algorithms, not efficient ones! :)

In computing, inefficient algorithms are not beautiful.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#415

Earlier quoted context omitted.

`git bisect` is an indispensible git trick. You give it commit where you know the bug exists, and one where you know it doesn't and it'll use binary search to help you find where the bug came from. It's absolutely wonderful.

I always struggle to see why people bang on about git bisect. You need tests to make it work. If you have tests, why aren't you running them continuously? If you're running them continuously, why do you need git bisect?

Sure; if you never write code that contains bugs that your unit tests don't catch, then "git bisect" is probably useless to you.

As for the rest of us mere mortals, we sometimes write code that has bugs without discovering those bugs right away. In a complex system, it might not be easy to observe an incorrect behavior and immediately deduce the root cause. "git bisect" allows you to retroactively track down the commit that introduced a behavior change, even if it was something you didn't originally think to test for.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#419

Earlier quoted context omitted.

Or, for better time complexity (with a bit of extra space) making a map of char -> frequency and comparing the results.

That's Fourier transform!

Funny. :) But a Fourier transform is reversible.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#420
Xor Swap.... https://en.wikipedia.org/wiki/XOR_swap_algorithm

not because it's super practical ( and there are other variations using other operators )

I like it because it is super simple and when I first encountered it early on in my learning, it was really not immediately obvious why it worked. It's probably been the simplest piece of code that's surprised me.

Post reply on HN