|
Post by bluatigro on Apr 13, 2020 6:21:44 GMT
puzle [ 1984 ] : give all the differend ways to give change for a euro
error : the code does not give all the coins of a change the code does not giva all posibility's
dim coin( 6 ) coin( 0 ) = 1 coin( 1 ) = 2 coin( 2 ) = 5 coin( 3 ) = 10 coin( 4 ) = 20 coin( 5 ) = 50
call change 5 , 100
end sub change high , rest if high < 0 or rest <= 0 then exit sub a = int( rest / coin( high ) ) for i = a to 1 step -1 rest = a * coin( high ) - i * coin( high ) print "(" ; coin( high ) ; ") * " ; i ; " , " ; call change high - 1 , rest print next i end sub
|
|
|
Post by bluatigro on Apr 13, 2020 7:47:06 GMT
update : try 2
error : more output but i do not think it is good
dim coin( 6 ) coin( 0 ) = 1 coin( 1 ) = 2 coin( 2 ) = 5 coin( 3 ) = 10 coin( 4 ) = 20 coin( 5 ) = 50
call change 5 , 100
end sub change high , rest if high < 0 then exit sub if rest = 0 then print : exit sub if coin( high ) = 1 then print "(1)*" ; rest else a = int( rest / coin( high ) ) for i = a to 1 step -1 r = rest - i * coin( high ) print "(" ; coin( high ) ; ")*" ; i ; " " ; call change high - 1 , r next i end if end sub
|
|