Determine the minimum value of a pentagonal number each of whose binary, quaternary and hexadecimal representations is a palindrome. What is the smallest decagonal number with this property?
Any solution must have more than one digit in any given base. So, trivial solutions like (0)base 2, (2)base 4 or, (B)base 16 are not allowed.
DECLARE FUNCTION isPalinb# (n#, b#)
DECLARE FUNCTION isPalin# (s$)
DEFDBL A-Z
OPEN "palinpgn.txt" FOR OUTPUT AS #2
FOR n = 1 TO 99999
pent = (3 * n * n - n) / 2: deca = 4 * n * n - 3 * n
IF isPalinb(pent, 2) THEN PRINT #2, " pent"
IF isPalinb(pent, 4) THEN PRINT #2, " pent"
IF isPalinb(pent, 16) THEN PRINT #2, " pent"
IF isPalinb(deca, 2) THEN PRINT #2, " deca"
IF isPalinb(deca, 4) THEN PRINT #2, " deca"
IF isPalinb(deca, 16) THEN PRINT #2, " deca"
NEXT
CLOSE
FUNCTION isPalin (s$)
good = 1
FOR i = 1 TO LEN(s$) / 2
IF MID$(s$, i, 1) <> MID$(s$, LEN(s$) + 1 - i, 1) THEN good = 0: EXIT FOR
NEXT
isPalin = good
END FUNCTION
FUNCTION isPalinb (n, b)
s$ = ""
q = n
WHILE q > 0
r = q MOD b
q = q \ b
IF b < 10 THEN
s$ = LTRIM$(STR$(r)) + s$
ELSE
s$ = MID$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", r + 1, 1) + s$
END IF
WEND
IF LEN(s$) > 1 AND isPalin(s$) THEN PRINT #2, USING "########## ## \" + SPACE$(33) + "\"; n; b; s$; : isPalinb = 1: ELSE isPalinb = 0
EXIT FUNCTION
END FUNCTION
After the output of the above is sorted appropriately (on pentagonal vs decagonal, base and the number itself), the results are:
number in |base| representation |type
decimal | / |
27 2 11011 deca
85 2 1010101 deca
297 2 100101001 deca
1105 2 10001010001 deca
2047 2 11111111111 deca
4257 2 1000010100001 deca
16705 2 100000101000001 deca
27307 2 110101010101011 deca
66177 2 10000001010000001 deca
121975 2 11101110001110111 deca
263425 2 1000000010100000001 deca
1051137 2 100000000101000000001 deca
4199425 2 10000000001010000000001 deca
7735351 2 11101100000100000110111 deca
16787457 2 1000000000010100000000001 deca
67129345 2 100000000000101000000000001 deca
268476417 2 10000000000001010000000000001 deca
1073823745 2 1000000000000010100000000000001 deca
1637760195 2 1100001100111100011110011000011 deca
10 4 22 deca
85 4 1111 deca
855 4 31113 deca
1105 4 101101 deca
16705 4 10011001 deca
227767 4 313212313 deca
263425 4 1000110001 deca
2223826 4 20132323102 deca
4199425 4 100001100001 deca
39278422 4 2111311131112 deca
58449847 4 3132331332313 deca
67129345 4 10000011000001 deca
153245830 4 21020211202012 deca
1073823745 4 1000000110000001 deca
1196692945 4 1013111001113101 deca
85 16 55 deca
2232 16 8B8 deca
2425 16 979 deca
18292 16 4774 deca
564376 16 89C98 deca
755595 16 B878B deca
787212 16 C030C deca
144366232 16 89ADA98 deca
156982105 16 95B5B59 deca
5 2 101 pent
51 2 110011 pent
348245 2 1010101000001010101 pent
465095 2 1110001100011000111 pent
1407957 2 101010111101111010101 pent
15483447 2 111011000100001000110111 pent
400730365 2 10111111000101010100011111101 pent
5 4 11 pent
51 4 303 pent
425 4 12221 pent
477 4 13131 pent
48510 4 23311332 pent
134850 4 200323002 pent
348245 4 1111001111 pent
51 16 33 pent
8177 16 1FF1 pent
15555 16 3CC3 pent
98945 16 18281 pent
227955 16 37A73 pent
326900 16 4FCF4 pent
348245 16 55055 pent
399126 16 61716 pent
545112 16 85158 pent
818812 16 C7E7C pent
2145026 16 20BB02 pent
5767301 16 580085 pent
30116801 16 1CB8BC1 pent
36885042 16 232D232 pent
61532835 16 3AAEAA3 pent
75526276 16 4807084 pent
90905445 16 56B1B65 pent
252480527 16 F0C8C0F pent
261868447 16 F9BCB9F pent
Answers to the specific questions:
Pentagonal: 51
Decagonal: 85
|
Posted by Charlie
on 2014-01-05 17:47:49 |