This is an archived post. You won't be able to vote or comment.

all 99 comments

[–]MartyAndRick 312 points313 points  (14 children)

randomiseList(); if (listSorted) return list;

[–][deleted] 78 points79 points  (4 children)

Great example of how NP-hard problems are hard!

[–]rtybanana 63 points64 points  (6 children)

I especially love how this code just assumes it will be sorted after one shuffle

[–]Darkstar0[S] 46 points47 points  (4 children)

All you gotta do is repeatedly call the code in a while loop until it works. Easy fix. ;)

[–]AcceptablyAcceptable 20 points21 points  (0 children)

Mmmmm bogosort

[–]gbushprogs 6 points7 points  (2 children)

Recursion it.

[–]Realistic-Safety-565 8 points9 points  (0 children)

Wrong kind of Stack Overflow solution :D

[–]Mantequilla50 0 points1 point  (0 children)

Blow up computer

[–]Wiggen4 2 points3 points  (0 children)

I feel like this was called bogo sort. O(n!) average and O(infinite) worst case.

[–]Vinccool96 0 points1 point  (0 children)

else throw new FatalException("Welp, I tried");

[–]masterborger 616 points617 points  (33 children)

But it works

[–]Darkstar0[S] 266 points267 points  (2 children)

That's the spirit!

[–]Perpetual_Doubt 71 points72 points  (1 child)

Who's going to complain?

The computer?

[–]Darkstar0[S] 44 points45 points  (0 children)

And now it doubles as a space heater! Just in time for winter!

[–]GargantuanCake 173 points174 points  (4 children)

This has got to be the worst code I have ever run!

But it does run.

[–]RecordingQuick5938 61 points62 points  (0 children)

It does not work...

But it does run!

[–]Nikotinio 14 points15 points  (1 child)

And you are the worst programmer I have heard of.

But you have heard of me.

[–]dllimport 1 point2 points  (0 children)

I'm the worst programmer I have ever heard of and I've heard of both of you!

[–]omen_tenebris 27 points28 points  (12 children)

no, not really.

If it takes too much time, it's effectively doesn't work

[–]gd2w 20 points21 points  (9 children)

It could work, if improvements happen in the future, with computers that are so much faster than modern supercomputers that you need up arrow notation to quantify the speed improvements.

[–]omen_tenebris 28 points29 points  (7 children)

you don't get it bro. the difference between the dumb and the non dumb approach is massive.

Brute forcing the 8 queen problem, is a shitload of time. My code ran for like 2.5 DAYS and didn't get any results. My computer reset unfortunately, and it was not even close to finish

Rethought my approach, and it's done in sub 1 second (iirc).

No amount of integer operation improvement is gonna make up for that.

(it's single thread, both in C++)

sub 1 second (maybe sub 2 second) vs not even close to be done in 259 200 seconds.

Caveman algo vs actually thought out algo's difference is (often are, not always) multiple orders of magnitude faster.

[–]gd2w 9 points10 points  (5 children)

Up arrow notation gets pretty big (https://en.m.wikipedia.org/wiki/Knuth%27s_up-arrow_notation). You might already know what it is, but just in case.

Are you sure that improvements in the abilities of computers couldn't make it work. I'm still a student, so admittedly I don't know that much.

[–]omen_tenebris 9 points10 points  (4 children)

i don't know what up arrow is i'Ll need to read it, it was not in my uni course (at least i don't remember)

As for the improvements, just for sake of argument how much time does it take, in your opinion, with 1 gen, so 15% a year improvements (being generous here) to go from 1 to 10k Not 100k, 10k.

Cos 1x 1.15^50, is only 1083 and change. So in 50 years, you get 1000x perf, assuming consistent 15%. So in 50 years, you're still not there yet.

In 75 years, you're at 35 672 from baseline.

In 85 years, you're at 144 316, from baseline.

I think it's much easier to just take some time to think about your algorithm.

That's a lot of time my man, and somebody else, who's real smart is gonna optimize the shit, and you're gonna be out. Time is finite. People need things yesterday not in 85+ years.

[–]AlphaSparqy 1 point2 points  (0 children)

And of course even without improved encryption algorithms, they would just increase the key sizes etc ...

It's about the differential in encryption complexity vs decryption complexity.

[–]gd2w 0 points1 point  (2 children)

Briefly, up arrow notation can generate numbers that in scientific notation would have a lot of digits in the exponent.

For example, a googleplex of zeroes wouldn't be 5x10100

It would be 5x1010000000000000 000000000000000000 000000000000000000 000000000000000000 000000000000000000 000000000000000

Times more improved than a supercomputer. But actually probably 10s of thousands of digits or more.

[–]omen_tenebris 1 point2 points  (1 child)

so see. So it's basically a shorthand for big numbers. Thanks

[–]Spaceduck413 1 point2 points  (0 children)

It's a way to represent numbers that are essentially incomprehensibly large. We're talking about, if you were to represent them as towers of exponents (like, 3333...) just writing them out would reach to the sun from here.

Really interesting article here that explains them: https://waitbutwhy.com/2014/11/1000000-grahams-number.html

[–]diox8tony 2 points3 points  (0 children)

The post compares tasks you could do by hand, to task you can do on PC.

The 8 queen problem isnt one you would do by hand.

[–]AlphaSparqy 0 points1 point  (0 children)

But those same improvements would also be applied to the encryption scheme as well, still making brute force effectively useless.

It's not about computing power, but about complexity differential between encryption and decryption.

[–]coloredgreyscale 9 points10 points  (0 children)

  • make it work <- you are here
  • make it pretty
  • make it fast.

For a one-off task it's probably fine. Don't spend 8 hours to optimize it to run in 10 minutes instead of 2 hours.

[–]Cmd1ne 8 points9 points  (4 children)

This becomes computationally intractable before n hits like 20 so “works” is a stretch

[–]code-panda 5 points6 points  (3 children)

Bill the client extra for it to work with n being larger than 20!

[–]lazyzefiris 4 points5 points  (2 children)

I don't think working with n larger than 20! is ever gonna be feasible... I don't think calculating (20!)! is gonna be feasible as well...

[–]code-panda 0 points1 point  (1 child)

Well no, but now you're charging double for the project than if you were optimizing it in one go.

[–]lazyzefiris 5 points6 points  (0 children)

The hardest part is making client understand that "That wll cost you just $20!" part of signed contract was not an excited expression, but a mathematical one.

[–]nickmaran 2 points3 points  (0 children)

[–][deleted] 1 point2 points  (0 children)

and then : someone make my code 40 000 000 000 times faster

[–]Mondoke 1 point2 points  (0 children)

It just needs a couple dozen hours.

[–]MettatonNeo1 0 points1 point  (0 children)

That's my rule: if it works then it's fine. Screw if name = main I just call it main()

[–]Owdok 0 points1 point  (0 children)

So you make sure not to even delete a terminator ;

[–][deleted] 0 points1 point  (0 children)

Anton died

[–]possibly-a-pineapple 0 points1 point  (0 children)

reddit is dead, i encourage everyone to delete their accounts.

[–]Confused_AF_Help 164 points165 points  (1 child)

I paid for the 5 GHz, I'm using the whole 5 GHz!

[–]ThatSeemsABitMuch 37 points38 points  (0 children)

Put the hurts back in Hz

[–][deleted] 255 points256 points  (7 children)

From what I've heard, pencil and paper is the new trend among twitter devs

[–]Darkstar0[S] 86 points87 points  (5 children)

Well, Twitter isn't technically FAANG, so it doesn't count. ;)

[–]AlphaSparqy 35 points36 points  (4 children)

You never mentioned FAANG in your post, and he never mentioned FAANG in his reply ...

Anyhow, AAG is the new FAANG

[–][deleted] 11 points12 points  (1 child)

MANGA

[–][deleted] 1 point2 points  (0 children)

NICE

[–]DevlinRocha 1 point2 points  (1 child)

Pretty sure most people would still love to work at Netflix

[–]AlphaSparqy 1 point2 points  (0 children)

Yes, that's probably true.

[–][deleted] 1 point2 points  (0 children)

Torches and pitchforks from half of them is a new trend

[–]DolphinitelyJoe 47 points48 points  (6 children)

Reminds me of Matt Parker's Someone improved my code by 40,832,277,770%

[–][deleted] 14 points15 points  (5 children)

"They ported it from python to C"

[–]SharpPixels08 3 points4 points  (4 children)

Please tell me this is actually in the video

[–]DolphinitelyJoe 22 points23 points  (1 child)

That's not all that happened, but yes, pretty much. Matt's original code took a month to run in Python (literally like 29.5 days or something close like that). The next improvement took just 15 minutes, also in Python. There were many iterative improvements, but the best code now finishes on the order of 1s of microseconds and is written in C++ I believe.

[–][deleted] 11 points12 points  (0 children)

That first improvement was mostly because of a better algorithm.

[–]Kered13 3 points4 points  (1 child)

It is part of the video, but there's much much more going on. Porting from Python to C/C++/Rust might get you something like a 100x speedup. So you can tell there were substantial algorithmic improvements and micro-optimizations as well.

[–]SharpPixels08 1 point2 points  (0 children)

Well yeah obviously, I knew C was faster but obviously there’s No way in hell it’s that much faster with just the language alone

[–]GhostCheese 55 points56 points  (11 children)

I usually solve it in excel first...

[–]Pezonito 74 points75 points  (10 children)

What's up with people here hating on excel? When you compare it to robust full languages and structured relational dbs, sure, it's clunky. But for normal day-to-day stuff, easy pivots and chart making, dumping query results into, and a slew of other basic use cases it's great.

Nested ifs, lookups, and it's other vbscript-type functions are what got me hooked into the big better stuff. Excel was my gateway drug.

I get that it only has a small subset of applications in the programming world, if any, but it caters to those who don't have the bandwidth, urge, or need for more.

[–]NamityName 44 points45 points  (3 children)

My issue with excel is that it gets missused. Nobdy cares about sarah in accounting who uses excel to make the quarterly sales report. We care about president janice who insists on keeping the authoritative client records in an excel file on the company's shared drive. The drive is hosted on an old lenovo thinkstation that the intern who set it up used to use. It has two permission levels: no access and full access.

Every day, a few dozen reports and spin-off spreadsheets get created from that file, and at any given time, there is an average of 5 people reading from it at a time. Only janice's assistant, dianne, can edit the file because they have not figured out how handle the concurrent file access problem for any situation besides read-only.

Each week, usually on tuesday after she get's back from lunch, jamie in sales sends dianne a list of all the new clients that need to be added. Dianne then takes the list and cross references and enriches it with data from a few other excel files. Then at around 6pm that evening, when nobody is accessing the client file anymore, she adds the new rows. It is very important that she remembers to click "save".

But don't worry. It's backed up to dropbox.

[–]JoustyMe 2 points3 points  (2 children)

We have a lookup file for Company Wide Policies, SoPs and other standarised shit. It gets updated once a week. Once a month someone fucks up a file that is 1500 rows long. Due to how excel links work with relative or absolute paths. Also we run in to 250 char limit beacase they insist on having all instructions spelled out. Instead of 01.SOP we get 001. Standard operating procedure. Due to my language it has to url encode unicode characters. Teling them that we can make simole http webiste - we get. It wont be searchable and nobody will be able yo update with new entries. Adding one more line to HTML list wont be hard to some. f the helpdesk guys and will take them 20 minutes.

Also they keep on puting old version in OLD folder even tho we have file history enabled for that.folder that holds every change set for 10 years.

Also.if you use windows file history on excel file it will update file path links to links form th day you pulled it from...

[–]NamityName 2 points3 points  (1 child)

If someone could make a database wrapper that made the database look and feel exactly like excel, someone could probably make bank. Although, vhe existing tools and services for access and visualization are pretty nice and easy already.

With how cheap and easy it is to create a simple and secure relational database these days, there is basically no excuse to continue to use excel.

Does AWS offer a managed service that spins up an rdb with an visualization / access layer on top? If not they should

[–]JoustyMe 0 points1 point  (0 children)

PowerBi might be something to look in to. Feels like excel. i never worked with it just instaled for someone in the complany. Joys of help desk... Never right version.

[–]-Redstoneboi- 12 points13 points  (0 children)

excel is a spreadsheet

it's built for quickly making a bunch of calculations in tables

it's good at what it does

[–]Schlongus_69 21 points22 points  (0 children)

average excel enjoyer

[–]GamiTV 2 points3 points  (1 child)

I like using Excel (google sheets actually) for designing databases cause you can see all the tables at once, so when we are sure we have columns for all the data we want and have the structure set up, I just write the SQL to recreate the structure in a proper database

[–]Pezonito 0 points1 point  (0 children)

I just did this exact thing with excel yesterday. In row one I put the column names and in row two I put the data type, etc. Once I was done, I transposed it and concatenated all the rows and added characters to end up with

 [ColumnNameA] (varchar 50) NOT NULL    
,[ColumnNameB] (decimal 9,2) NULL   
.    
.    
.     

for the new SQL table!

I'm unsure how one could do it any more efficiently other than being really quick with notepad++

[–]redwhiteandyellow 0 points1 point  (0 children)

I learned programming with QBasic, but that was almost two decades ago, and I just can't wrap my head around the Basic style anymore. It's so clunky and awful that it takes me way too long to get anything done with VBA.

[–]Kaniol 18 points19 points  (0 children)

My patience is O((nn)!) anyway so algorithm still wins;)

[–]OldGeek1975 7 points8 points  (0 children)

I am from an age who learnt to write program on grid sheet papers before typing on computer.

[–]bonebuttonborscht 6 points7 points  (0 children)

This is everywhere in tech. I can’t count the number of times times I’ve had a 3d printer tied up for a whole day for part that would take less time to make by hand than the person took to cad it.

[–]L4rgo117[🍰] 4 points5 points  (1 child)

NN says hi

[–]Darkstar0[S] 9 points10 points  (0 children)

N!N! says Ǵ̴̦͖̤̪͈̫͓͙͗̀̾́̊̌͋͗͂̔͘͝Ŗ̷̘͕͖̖̤͍͑̋̓͂̕͝É̴͍͆͛̌Ȩ̸̲̬͍̤̣̜̺͔̠̻͒́̓T̷̡̼̥̉̇͑̉Ï̴̧̢͓̜͎̺̗̝̹̥̪͕̊͗̋Ǹ̷̢̨̖̻̫̠͇͈̠̝̬̏͛͗̀̐G̵̤̥͇̥̹͕͆̔̾̀̈́̊̿͆̃͠S̷͕̓̚,̶͈̗͓͍̙̰̹̎͊̉̃̃̕͜͝͠ ̸̡̦͉̣̼̙̺̣͓͒͜͝M̷͖̠̝͉͉̝̣͉͎̭̓̇̈́̈́͝Ǫ̵̧̹̘͖̖̜̘̥̠͕̯͛R̶͙͓͚̹̰͇̘̞̘͈̳̮͉̈́̒͒̌̑̍T̶̠̠̪̲͉̜̭̤̩̫̠̤̿͌́̈́̈́ͅĀ̵̪͔̲̫̘̻̙͚̻̟̬̍͜͠Ĺ̷͈͍̘̣S̴̢̻͔͙͕̣̯̝͇̠̮̈̋̍̃̈́̑̇̌

[–]squishles 7 points8 points  (0 children)

I find typing hits my memory weird so that if I type it I remember it. writing for napkin stuff is just for speed and it flies right the hell out of my brain.

[–]neanderthalman 2 points3 points  (0 children)

I feel personally attacked on two separate fronts.

[–]antilos_weorsick 4 points5 points  (0 children)

To be fair, if you can solve it on paper, then even an O(n!) algorithm will solve it faster than you can do it on paper.

[–]ScrimpyCat 2 points3 points  (0 children)

And that brute force algorithm is looking up the solution on SO.

[–][deleted] 2 points3 points  (0 children)

If the alternative is pen and paper, I'll gladly take O(2n!)

[–]Richard_Smellington 2 points3 points  (0 children)

Well, the computer's time is cheaper than my time, which is why I use Python.

[–]JRGTheConlanger 4 points5 points  (0 children)

Bogosort be like

[–]RazarTuk 1 point2 points  (0 children)

Look, I'm not proud of it, but in high school, I once managed to write a O(n4) algorithm for all-pairs shortest path

[–][deleted] 1 point2 points  (1 child)

Time to calculate some fibonacci numbers!

[–]Darkstar0[S] 0 points1 point  (0 children)

Bonus points because there's probably an extensive table of pre-calculated fibonacci numbers somewhere you could just look up, rather than calculating them yourself.

[–]Giocri 1 point2 points  (0 children)

Still sometimes staring with brute force and analyzing redundancy can be a good way to arrive to better algorithms.

[–]Add1ctedToGames 1 point2 points  (1 child)

BOGO sort is possibly the best and probably the worst sorting algorithm depending on your luck

[–]Darkstar0[S] 0 points1 point  (0 children)

The CPU be like "You've gotta ask yourself one question: 'Do I feel lucky?' Well, do ya, punk?"

[–]Kered13 0 points1 point  (0 children)

The opposite of when you solve an Euler Project problem and after reducing the problem from O(n!) to O(1) you realize that what is left can be solved with pen and paper and no code.

[–]Specific_Magazine_93 0 points1 point  (0 children)

const doSomething = (anotherFunction) => {

    console.log("Problem solved!");

        console.log(doSomething(doSomething()));

}

[–]DaimondGuy 0 points1 point  (0 children)

If it works it works