Find palindromic numbers in both binary and ternary bases: Difference between revisions

(→‎{{header|J}}: comments)
Line 181:
=={{header|J}}==
'''Solution:'''
<lang j>isPalin=: -: |. NB. check if palindrome
toBase=: #.inv"0 NB. convert to base(s) in left arg
filterPalinBase=: ] #~ isPalin@toBase/ NB. palindromes for base(s)
find23Palindromes=: 3 filterPalinBase 2 filterPalinBase ] NB. palindromes in both base 2 and base 3
Line 188:
showBases=: [: ,./ ' ' (,"1) (' ' -.~ ":)@toBase/ NB. display bases for numbers
 
NB.*getfirst a Adverb to get first y items to returned by verb u
getfirst=: 1adverb :0define
1e5 u getfirst y
:
res=. 0$0
start=. 0
blk=. i.x
whilst. y > #res do.
tmp=. u start + blk
start=. start + x
res=. res, tmp
end.
res
)</lang>
'''Usage:'''
Line 211:
90396755477 1010100001100000100010000011000010101 22122022220102222022122
</lang>
 
=={{header|Java}}==
This takes a while to get to the 6th one (I didn't time it precisely, but it was less than 2 hours on an i7)
892

edits