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

250

u/retsotrembla May 08 '15

Number 3 is tougher than it looks since once you get above the 91th Fibonacci number, 12200160415121876738, it doesn't fit in an unsigned 64-bit integer, so to solve it, you have to write a bignum package.

124

u/__Cyber_Dildonics__ May 08 '15

Just download and build boost mid interview bro

84

u/arianvp May 08 '15

AAaaaaand you're out of time.

145

u/Falmarri May 08 '15

Python supports arbitrarily large integers transparently

47

u/Magnap May 08 '15

As does Haskell.

33

u/philalether May 08 '15

As does Ruby.

130

u/flukshun May 08 '15

As does C.

just not in the expected way...

146

u/[deleted] May 08 '15

Actually completely expected. Just not desired.

→ More replies (12)
→ More replies (4)
→ More replies (2)
→ More replies (2)

4

u/EmperorOfCanada May 08 '15

This makes ProjectEuler way easier.

→ More replies (3)

43

u/matthieum May 08 '15

I think that if you point the 64-bits integer overflow issue, you pass the question.

→ More replies (1)

28

u/Transfuturist May 08 '15

First-order approximations! First-order approximations everywhere! Dx

148

u/retsotrembla May 08 '15

Any program can be arbitrarily sped up if it isn't required to provide the correct answer.

88

u/malloc_more_ram May 08 '15
int main(void) {
    return 0;
}

31

u/boo_ood May 08 '15

Speed it up more please

42

u/[deleted] May 08 '15

Just hang a paper note on the computer monitor saying "Success!". You don't even need to start the program or power up the computer then.

→ More replies (3)

0

u/[deleted] May 08 '15

[deleted]

→ More replies (1)

5

u/benihana May 08 '15
int main(void) { return 0; }

less whitespace = less air resistance.

→ More replies (2)

76

u/davros_ May 08 '15
int rand() {
  return 4; // chosen by fair dice roll
}

4

u/Soccer21x May 08 '15

I know we're all programmers here, but just in case

Relevant xkcd

→ More replies (2)
→ More replies (2)
→ More replies (2)

23

u/goomyman May 08 '15

lol apparently number is a terrible question... unless your looking for someone to bring this up. I know i would have missed that lol.

I bet the interview question guy failed this one too.

18

u/JavaSuck May 08 '15

Yes, but you only need to implement addition. Here is my attempt. It can be done in well under half an hour.

18

u/mdempsky May 08 '15 edited May 08 '15

You can simplify it a bit further.

Note that Fibonacci numbers grow slower than doubling (specifically, they grow by a factor of about 1.618), so the 100th Fibonacci number will be less than 2100. That means you can represent it with just 2 64-bit numbers x_0 and x_1.

To make printing the numbers a bit easier, instead of using x_0 + 264*x_1, you can just use x_0 + 1018*x_1.

You might be asked to show that 1036 > 2100 then. I generally remember that 103 ≈ 210, so 1036 ≈ 2120, which should be enough slack to argue it's >2100.

Note also that 1018 ≈ 260, which is why you know it will fit in a 64-bit integer.

→ More replies (1)
→ More replies (3)

0

u/[deleted] May 08 '15

[deleted]

10

u/retsotrembla May 08 '15

You are right: it's the 93, counting 0 as the zero'th. I was tired.

4

u/thetreat May 08 '15

Unacceptable. You're no longer allowed to call yourself a software engineer.

→ More replies (31)