fork(1) download
  1. def print_sums(target, current_sum=0, current_numbers=[]):
  2. if current_sum == target:
  3. print(" + ".join(map(str, current_numbers)), "=", target)
  4. for i in range(1, target+1):
  5. if current_sum + i <= target:
  6. print_sums(target, current_sum + i, current_numbers + [i])
  7. return
  8.  
  9. print_sums(5)
  10.  
Success #stdin #stdout 0.03s 9608KB
stdin
add $s0, $t2, $s0
stdout
1 + 1 + 1 + 1 + 1 = 5
1 + 1 + 1 + 2 = 5
1 + 1 + 2 + 1 = 5
1 + 1 + 3 = 5
1 + 2 + 1 + 1 = 5
1 + 2 + 2 = 5
1 + 3 + 1 = 5
1 + 4 = 5
2 + 1 + 1 + 1 = 5
2 + 1 + 2 = 5
2 + 2 + 1 = 5
2 + 3 = 5
3 + 1 + 1 = 5
3 + 2 = 5
4 + 1 = 5
5 = 5