Contribution for Puzzlet #058
From: Denzil Newman [Denzil.Newman@BlueYonder.Co.UK]
' Rapid solution by D.Newman
' I saw the problem set at
' and realised that I could probably make the
' solution very quickly (in fact while dinner was
' cooking), although there are probably better ways
' of doing it. My program loops from 1-9999 then
' creates a string and reverses it to calculate the
' reverse. After this the answer is calculated and
' converted to a string. The length is then compared
' (as if the length does not match it cannot have all
' the numbers in it). Each character is then checked
' to see if it is in the original and not in a string
' called used. If so the character is added to used.
' In this fashion all characters are tested then the
' successful numbers are printed.
const True = -1
const False = not True
def count as int
def subCount as int
def inv1 as string
def inv2 as string
def invAns as int
def invStr as string
def used as string
def found as int
print "Find any integer not greater than 9999 such that subtracting"
print "its reverse from the original yields an anagram of the original."
for count=1 to 9999
for subCount=1 to len(inv1)
for subCount=1 to len(invStr)
if instr(inv1, mid$(invStr,subCount,1))
if instr(used, mid$(invStr,subCount,1))
print inv1+" - "+inv2+" = "+invStr
print "press a key to continue."
Thanks for the program. It runs in just a second or so on my machine and produces all possible solutions in a neat screen printout. The code is clear and easy to follow. Well done.