fork download
  1. #!/bin/bash
  2.  
  3. diophantine()
  4. {
  5. local i
  6. local n=$1
  7. [[ ${n} -eq 0 ]] && echo "${ilist[@]}" ||
  8. {
  9. for ((i = n; i > 0; i--))
  10. do
  11. ilist[${#ilist[@]}]=${i}
  12. diophantine $((n-i))
  13. done
  14. }
  15. unset ilist[${#ilist[@]}-1]
  16. }
  17.  
  18. read input
  19.  
  20. RE_POSITIVE_INTEGER="^[1-9]+$"
  21. [[ ! ${input} =~ ${RE_POSITIVE_INTEGER} ]] && echo "usage: $(basename $0) <Z+>" ||
  22. {
  23. declare -a ilist=
  24. diophantine ${input}
  25. }
  26. exit
Success #stdin #stdout 0.03s 5268KB
stdin
4
stdout
 4
 3 1
 2 2
 2 1 1
 1 3
 1 2 1
 1 1 2
 1 1 1 1