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

2

u/EddieTheHead14 May 09 '15

What's the big deal guys, these are simple one-liners, right?

l = [55,556,5,1,2,9]
l2 = ['a','b','c','d','e','f']

# Problem 1
print reduce(lambda x, y: x+y, [k for k in l])

# Problem 2
print [x for y in zip(l, l2) for x in y]

# Problem 3
print map(lambda n:(lambda q, *a: q(q, *a))(lambda fib, n: n if n < 2 else fib(fib, n-1)+fib(fib, n-2), n), range(10)) # Replace 10 with 100 for first 100 fib elements

# Problem 4
print("".join(list(reversed(sorted([str(s) + "_" for s in l])))).replace("_",""))

# Problem 5
from itertools import product;exec('for ___ in (product(["+", "-", ""], repeat=8)):\n\tif(eval("".join(str(_)+__ for (_,__)in(zip([i for i in range(1,10)],___ + ("",))))) == list((map(lambda x: x**2, [10])))[0]): print( "".join(str(_) + __ for (_, __) in (zip([i for i in range(1,10)], ___ + ("",)))) + " = %d"%(list((map(lambda x: x**2, [10])))[0],))')