April 25, 2024, 02:01:52 PM

News:

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


Puzzlet #39

Started by GWS, March 28, 2014, 12:49:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi,

Here's an old program by Dave Ellis circa 2003, who coded a number of examples showing how to go about solving a variety of mathematical problems.

This is puzzlet #39 .. to find three amounts of money, such that their sum is $7.26 and their product
also $7.26.  All three amounts are greater than $1.00, and all three are different.


declare PrintResult()
def amnt1, amnt2, amnt3: int
def flag, product, sum: int
product = 7260000: 'product in cents
sum = 726: 'sum in cents
amnt1 = 101: 'minimum possible value
flag = 0
openconsole
print "Searching ...": print

do
amnt2 = amnt1 + 1
do
amnt3 = sum - amnt1 - amnt2
if amnt1 * amnt2 * amnt3 = product
flag = 1
else
amnt2 = amnt2 + 1
endif
until flag | amnt2 > 523
amnt1 = amnt1 + 1
until flag | amnt1 > 523

PrintResult()
print: print "Press any key ... ",
do: until inkey$ <> ""
closeconsole
end

sub PrintResult
' pretty printer ..
def res1, res2, res3: float
def res1$, res2$, res3$: string
def p$, s$, t$: string
res1 = (amnt1 - 1)/100
res2 = amnt2/100
res3 = amnt3/100
res1$ = "$" + ltrim$(str$(res1))
res2$ = "$" + ltrim$(str$(res2))
res3$ = "$" + ltrim$(str$(res3))
p$ = " + "
t$ = " x "
s$ = " = $7.26"
print res1$ + p$ + res2$, + p$ + res3$ + s$
print res1$ + t$ + res2$, + t$ + res3$ + s$
return


There are many interesting contributions from many years ago ..  :)

Best wishes, :)

Graham

Tomorrow may be too late ..