March 28, 2024, 06:05:35 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Puzzlet #35

Started by GWS, September 09, 2015, 04:13:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi,

Are you ready for another puzzle from Dave Ellis's collection ..  :)

This one is to find an integer which can be divided by any n from 1 to 16, and always leave the
remainder n - 1.


' Puzzlet #035.
' Find an integer which can be divided by
' any n from 1 to 16 and always leave the
' remainder n - 1.
' By Dave Ellis. (slightly modified GWS)

def flag1, flag2: int
def numerator, denominator, remainder: int

numerator = 31
flag1 = 0
openconsole
print "Searching ..."

do
' outer loop controls numerator
denominator = 16
flag2 = 0
do
' inner loop controls denominator
remainder = numerator % denominator
if (remainder = denominator - 1)
denominator = denominator - 1
else
flag2 = 1
endif
until (flag2 | denominator < 2)
if (denominator < 2)
flag1 = 1
else
numerator = numerator + 16
endif
until flag1

PrintResult

print: print "Press any key to exit ..."
do: until inkey$ <> ""
closeconsole
end

sub PrintResult
' pretty printer
def i: int
print
for i = 1 to 16
print ltrim$(str$(numerator)) + "/",
print i,
if (i < 10)
print " ",
endif
print "= ",
print using ("######", int(numerator/i)),
print " remainder ",
print using ("##",i - 1)
next i

return



Best wishes, :)

Graham
Tomorrow may be too late ..