r/programming • • May 08 '15

Five programming problems every Software Engineer should be able to solve in less than 1 hour

https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k Upvotes

2.1k comments sorted by

View all comments

Show parent comments

1

u/serrimo May 08 '15

As a wild guess, I think it shouldn't take more than a few milliseconds to do this.

15

u/allak May 08 '15 edited May 08 '15

yep

 [11:12][~] time ./test_perl_5.pl
 1+2+3-4+5+6+78+9=100
 1+2+34-5+67-8+9=100
 1+23-4+5+6+78-9=100
 1+23-4+56+7+8+9=100
 12+3+4+5-6-7+89=100
 12+3-4+5+67+8+9=100
 12-3-4+5-6+7+89=100
 123+4-5+67-89=100
 123+45-67+8-9=100
 123-4-5-6-7+8-9=100
 123-45-67+89=100

 real    0m0.267s
 user    0m0.217s
 sys     0m0.046s

(i wonder if it is correct ...)

1

u/s-mores May 08 '15

Hey! I did it in Perl, too. With 1-4 being solvable by one-liners in Perl it was fun to spend some time figuring out the most sensible way of throwing arrays around in #5.

How did you build the brute force tree or traverse it btw?

1

u/allak May 08 '15

I made a pastebin of the source in my other comment; as I've said, it's a disgusting mix of brute force and too much cleverness, but I was actually timing myself, and manged to do all five under one hour, so in this sense it was a success (number 5, that is; number 4 was wrong).

→ More replies (0)