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

28

u/lord_braleigh May 08 '15

The digits must stay in order.

0

u/[deleted] May 08 '15

[deleted]

3

u/jlt6666 May 08 '15

A language with eval makes it far easier. Or just call out to bash :)

4

u/yanetut May 08 '15

Bash? Did someone say bash?

#!/bin/env bash

function prob5() {
  if [[ $# -eq 1 ]]; then
    [[ $(($1)) -eq 100 ]] && echo $1
  else
    local exp="$1" ; shift
    local dig="$1" ; shift

    prob5 "$exp + $dig" "$@"
    prob5 "$exp - $dig" "$@"
    prob5 "$exp$dig" "$@"
  fi
}

prob5 1 2 3 4 5 6 7 8 9
→ More replies (0)