Find the nth Fibohexaprime
MATL, 28 bytes
This uses MATL version 1.0.0, which was published in Esolangs on December 12, earlier than this challenge.
1Hi:"`tb+t16YAt58<)YtZp~]]1$
Example
>> matl 1Hi:"`tb+t16YAt58<)YtZp~]]1$
> 10
121393
Explanation
The code is similar to that in Martin Büttner's answer.
1 % number literal
H % paste from clipboard H. Initial contents: 2
i: % vector of equally spaced values from 1 to input value
" % for
` % do...while
t % duplicate
b % bubble up element in stack
+ % addition
t % duplicate
16YA % convert integer to string representation in base 16
t % duplicate
58 % number literal: first ASCII code after '9'
< % is less than? (element-wise)
) % reference () indexing with logical index from previous comparison
Yt % convert string to number
Zp % true for prime numbers
~ % logical 'not'
] % end
] % end
1$ % input specification for final implicit display function
CJam, 28 bytes
TXri{{_@+_Gb{A<},Abmp!}g}*p;
Test it here.
Explanation
TX e# Push 0 and 1 to initialise Fibonacci computation.
ri e# Read input and convert to integer N.
{ e# Run this block N times...
{ e# While the condition on top of the stack is truthy...
_@+ e# Compute next Fibonacci number (dropping the second-to-last one).
_Gb e# Duplicate and convert to base 16.
{A<}, e# Keep only digits less than 10.
Ab e# Convert from base 10.
mp! e# Check that it's not a prime.
}g
}*
p; e# Print the last number we found and discard the one before.
Perl 6, 62 bytes
My first pass of just get it to work was:
{(grep *[1].is-prime,map {$_,+[~] .base(16)~~m:g/\d/},(1,1,*+*...*))[$_-1;0]} # 77
By combining the grep
and the map
, I can remove 10 bytes
{(map {$_ if is-prime [~] .base(16)~~m:g/\d/},(1,1,*+*...*))[$_-1]} # 67
If I use grep
instead of map
, I save 5 more bytes:
{(grep {is-prime [~] .base(16)~~m:g/\d/},(1,1,*+*...*))[$_-1]} # 62
usage:
# give it a name
my &code = {...}
say code $_ for 1..^20;
2
3
5
55
89
377
987
28657
75025
121393
317811
5702887
9227465
39088169
102334155
32951280099
4052739537881
806515533049393
7540113804746346429