home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1987 December / Ahoy_Magazine_87-12_1987_Double_L.d64 / Added Diff. 64 (.txt) < prev    next >
Encoding:
Commodore BASIC  |  1987-01-01  |  691 b   |  22 lines

  1. 1 rem ==================================
  2. 2 rem    commodares problem #44-1 :
  3. 3 rem      added difficulty
  4. 4 rem    solution by
  5. 5 rem      jim lostetter
  6. 6 rem ==================================
  7. 20 input"[147]show all combinations that add up to";n
  8. 30 f=f+1:iff>n/2thenprintc;"combinations":end
  9. 40 m=f+1:l(0)=f:ls=f:gosub100
  10. 50 l(l)=l(l)+1:ls=ls+1:ifl(0)+f>n then30
  11. 60 if l>0 and l(1)>l(0) then l=0:ls=l(l):goto 50
  12. 70 gosub 100:ms=m:gosub 100:ms=0:ifl(l)<=m then 50
  13. 80 l=l+1:l(l)=m+1:ls=ls+l(l) :if ls+f<=n then 70
  14. 90 l=1:ls=l(l)+l(0):goto 50
  15. 100 rem subroutine
  16. 110 fs=n-ls-ms :if fs<f or fs/f<>int(fs/f) then return
  17. 120 for p=f to fs step f:printf;:next:ifms=0 then 140
  18. 130 for p=m to ms step m:print m;:next
  19. 140 for p=l to 0 step-1:print l(p);:next:print:c=c+1
  20. 150 if ms=0 then return
  21. 160 ms=ms+m:goto 110
  22.