THE PUZZLET PAGE

PUZZLET 001 - THE SOLUTION

This was the very first Puzzlet, and somewhat simpler than those that followed.  The following IBasic program describes the problem in its introductory remarks and goes on to solve it.

' Puzzlet #001
' To find a 4-digit integer abcd,
' such that:
' a + c = b + d
' a * d = 10*(b * c)
' a + b = 0.5*(c + d)
' By Dave Ellis.


def a,b,c,d: int
openconsole
print "Searching ...": print

for a = 0 to 9
    for b = 0 to 9
        for c = 0 to 9
            for d = 0 to 9
                if a + c = b + d
                    if a * d = 10 * b * c
                        if 2*(a + b) = c + d)
                            print a, b, c, d
                         endif
                    endif
                endif
            next
d
        next c
    next b
next a

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

PROGRAM NOTES

The variables a through d are used in the for-next loops to generate all possible integers from 0000 to 9999 while retaining access to each individual digit.  The tests described in the introductory remarks are carried out at each iteration, and whenever an integer is found that successfully meets those tests it's printed out.

The first solution is trivial - 0000.  The only other is 5148. The screen shot shown below is the actual screen produced when the above code is run.


The first solution is trivial - 0000. The only other is 5148.

 The screen shot shown on the left  is the actual screen produced when the above code is run.

Puzzlet_001_screenshot



MAIN MENU
DOWNLOAD CODE
ARCHIVES

Site design/maintenance: Dave Ellis E-mail me!
Last Updated: January 22nd, 2010.