Quantcast
Channel: Shortest code to find next prime palindrome - Code Golf Stack Exchange
Browsing latest articles
Browse All 15 View Live

Answer by Sean for Shortest code to find next prime palindrome

Raku, 37 bytes{first &is-prime&{.flip eq$_},$_^..*}Try it online!The outer expression is first EXPR, $_ ^.. *, which looks for the first number which matches EXPR in the numbers from one...

View Article



Answer by Makonede for Shortest code to find next prime palindrome

05AB1E, 7 bytes[ÅNDÂQ#Try it online![ÅNDÂQ# # full program # # exit...[ # infinite loop... # # when...ÅN # first prime greater than... # implicit input... D # or top of stack if not first...

View Article

Answer by Oliver for Shortest code to find next prime palindrome

Japt, 11 bytes_¥sÔ©Zj}aUÄRun it online

View Article

Answer by J. Sallé for Shortest code to find next prime palindrome

K (oK), 27 bytes{~(x=.|$x)&/(2_!x)!'x}(1+)/Try it online! for all test cases where the input n<1000My first answer in K. Yay!Thanks to @ngn for the help.ngn also found a shorter solution which...

View Article

Answer by Sundar R for Shortest code to find next prime palindrome

Brachylog, 4 bytes<.ṗ↔Try it online!Simple and neat. ?<.ṗ↔. (Initial ? and final . are implicit)?<. Input is less than the output .ṗ Output is a prime number↔. And output reversed is the...

View Article


Answer by Kevin Cruijssen for Shortest code to find next prime palindrome

05AB1E (legacy), 9 bytes[>ÐÂQsp*#Try it online or verify some test cases.Explanation: # (Implicit input) # i.e. 15 # i.e. 130[ # Start an infinite loop> # Increase the top of the stack by 1 #...

View Article

Answer by mxdsp for Shortest code to find next prime palindrome

Python, 63 60 charactersdef g(n): n+=1 while`n`[::-1]!=`n`or~-2**n%n>2:n+=1 return n

View Article

Answer by britishtea for Shortest code to find next prime palindrome

Ruby, 63require"prime"x=->n{Prime.find{|p|q=p.to_s;p>n&&q.reverse==q}}ExplanationInput is taken as the arguments to a lambda. It's expected to be an Integer.Prime is Enumerable. Use...

View Article


Answer by edc65 for Shortest code to find next prime palindrome

JavaScript (E6) 95Q=n=>(f=>{for(;a=!f;)for(f=++n==[...n+''].reverse().join('');b=n/++a|0,f&&a<=b;)f=a*b-n;})(0)|nUngolfedQ=n=>{ for (f=0; !f;) // loop until both palindrome and...

View Article


Answer by Dennis for Shortest code to find next prime palindrome

CJam, 15 bytesli{)__mfsW%i^}gReads a single, positive integer from STDIN. Try it online.Example run$ cjam <(echo 'li{)__mfsW%i^}g') <<< 250313How it worksThis uses a tricky prime check...

View Article

Answer by phosgene for Shortest code to find next prime palindrome

Mathematica - 75 charactersi=IntegerDigits;f@n_:=Select[Range[n+1,10^5],i@#==Reverse@i@#&&PrimeQ@#&,1]Ungolfed:i=IntegerDigits;f@n_:=Select[ Range[n+1,10^5], i@#==Reverse@i@#&&...

View Article

Answer by isaacg for Shortest code to find next prime palindrome

Pyth, 17~Q1Wn`Q_`ePQ~Q1)QExplanation: Implicit: Q = eval(input())~Q1 Q +=1W while n not equal `Q repr(Q) `ePQ repr(end(prime_factorization(Q))) ~Q1 Q += 1) end whileQ print(Q)

View Article

Answer by Ray for Shortest code to find next prime palindrome

Haskell - 71p n|s==reverse s&&all((/=0).mod m)[2..n]=m|1<2=p m where m=n+1;s=show mUngolfednextPrime n | s == reverse s && all ((/=0).(mod m)) [2..n] = m | otherwise = nextPrime (n +...

View Article


Answer by Optimizer for Shortest code to find next prime palindrome

CJam, 18 17 charactersri{)__s_W%=*mp!}gHow it works:ri "Convert the input into an integer"; { }g "Run this code block while the top stack element is truthy"; )__ "Increment the number and make two...

View Article

Shortest code to find next prime palindrome

I was trying to find the shortest code possible that given a number n, returns the next prime palindrome number (limited to below 100000). If the number itself is a prime palindrome, the code should...

View Article

Browsing latest articles
Browse All 15 View Live




Latest Images