WG declared as follows:
My number
1. Comprises 7 digits.
2. Uses only 3 distinct digits.
3. Is a square.
4. Is a cube.
5. Is somewhere between 4,500,000 and 8,500,000.
6. Sum of its digits is 45.
One (and only one) of the above statements is false.
Erase it and recover the number.
Is it possible to ignore additional statement(s) and still stay with the original number?
The number 7077888 is the only one that fits the bill.
We knew right away it had to be a 7digit number; if it weren't, both statements 1 and 5 would be false. It also had to be either a perfect square or a perfect cube.
DefDbl AZ
Private Sub Form_Load()
Form1.Visible = True
For n = 1000000 To 9998244
ns$ = LTrim(Str(n))
digct = 0
had$ = ""
For i = 1 To Len(ns)
c$ = Mid$(ns, i, 1)
If InStr(had, c) = 0 Then had = had + c
Next
If Len(had) < 4 Then digct = Val(Len(had)) Else digct = 0
sr = Int(Sqr(n))
If sr * sr = n Then square = 1 Else square = 0
cr = Int(n ^ (1 / 3) + 0.5)
If cr * cr * cr = n Then cube = 1 Else cube = 0
If n >= 4500000 And n <= 8500000 Then range = 1 Else range = 0
If sod(n) = 45 Then sodeq = 1 Else sodeq = 0
truect = 0
If digct Then truect = truect + 1
truect = truect + square + cube + range + sodeq
If truect = 4 Then
Text1.Text = Text1.Text & mform(n, "#######0") & " " & digct & square & cube & range & sodeq & vbCrLf
End If
DoEvents
Next
Print "done"
Close 1
End Sub
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$)  Len(a$)) & a$
mform$ = a$
End Function
Function sod(n)
s$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(s$)
tot = tot + Val(Mid(s$, i, 1))
Next
sod = tot
End Function
By lowering the number of true statements we find:
5177717 satisfies the same criteria as 7077888 except its digits do not sum to 45, so if that were left out we couldn't identify this one.
and there are many that are neither cubes nor squares that fit the other criteria.

Posted by Charlie
on 20200904 11:57:15 