In the planet Realmebon, the inhabitants use base 6 in their daily transactions. One of the inhabitants noticed that if he split his 6-digit ID number into two 3-digit numbers and squared each of them, their sum would equal his ID number.
How many possible ID numbers could he have been assigned, and what are they?
(In reply to
brute force by JLo)
Yes, computers are so fast. I had assumed no leading zeros:
DEFDBL A-Z
DECLARE FUNCTION dec (h$)
DECLARE FUNCTION b6$ (d)
low = dec("100000")
high = dec("555555")
FOR i = low TO high
chk$ = b6(i)
c1$ = LEFT$(chk$, 3)
c2$ = RIGHT$(chk$, 3)
a = dec(c1$): b = dec(c2$)
c$ = b6(a * a + b * b)
IF c$ = chk$ THEN PRINT c$: ct = ct + 1
NEXT
PRINT ct
FUNCTION b6$ (d)
s$ = ""
r = d
DO
dig = r MOD 6
r = r \ 6
s$ = LTRIM$(STR$(dig)) + s$
LOOP UNTIL r = 0
b6$ = s$
END FUNCTION
FUNCTION dec (h$)
t = 0
FOR i = 1 TO LEN(h$)
d$ = MID$(h$, i, 1)
t = t * 6 + VAL(d$)
NEXT
dec = t
END FUNCTION
100213
150244
410244
500213
550100
5
finding an answer of 5. But if you set low to 0 instead, you get
DEFDBL A-Z
DECLARE FUNCTION dec (h$)
DECLARE FUNCTION b6$ (d)
low = 0
high = dec("555555")
FOR i = low TO high
chk$ = b6(i)
c1$ = LEFT$(chk$, 3)
c2$ = RIGHT$(chk$, 3)
a = dec(c1$): b = dec(c2$)
c$ = b6(a * a + b * b)
IF c$ = chk$ THEN PRINT c$: ct = ct + 1
NEXT
PRINT ct
FUNCTION b6$ (d)
s$ = ""
r = d
DO
dig = r MOD 6
r = r \ 6
s$ = LTRIM$(STR$(dig)) + s$
LOOP UNTIL r = 0
IF LEN(s$) < 6 THEN s$ = RIGHT$("000000" + s$, 6)
b6$ = s$
END FUNCTION
FUNCTION dec (h$)
t = 0
FOR i = 1 TO LEN(h$)
d$ = MID$(h$, i, 1)
t = t * 6 + VAL(d$)
NEXT
dec = t
END FUNCTION
000000
000001
010100
100213
150244
410244
500213
550100
8
|
Posted by Charlie
on 2006-11-11 16:21:02 |