4 ms·
I sat down for 2 minutes and wrote a brute-force solution that ran the 10k scenario in 400ms in python. Hint: you only need two loops.
by klyrs 5y ago
I sat down for 2 minutes and wrote a brute-force solution that ran the 10k scenario in 400ms in python. Hint: you only need two loops.
- milansuk 5y agoI wrote it in C with just one loop: for(i=0; i <= 10000; i+=37) and one condition: if(i > 0 && i%13==0 && i%19==0) and it takes only 0.000003 sec.
- klyrs 5y agoI was referring to the beer/meat/bread problem, but yeah. Brute force is ruthlessly effective for small problems.
- shoo 5y agoif all the inputs are constants and don't depend on program input, it'd be interesting to disassemble that to see if the compiler solved the problem at compile time and generated a "load <constant_precomputed_solution>" you may not necessarily be timing what you think you are timing
- throwawaygh 5y ago> brute-force solution... Hint: you only need two loops. Well, yes, there are all sorts of tricks, including the use of a solver :) In my earlier post, read "brute-force" as "full enumeration". The comment was about dev's intuitions re: the time required to fully enumerate a space; ie when is it worth thinking about anything other than the stupidest solution possible.