Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Nearest Prime Number
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
def find_prime(): N = 127 prime = [True for i in range(N+1)] p = 2 while (p * p <= N): if(prime[p] == True): for i in range(p*p,N+1,p): prime[i] = False p+=1 prime[0] = False prime[1] = False return prime def get_nearest(e,p): ind = ord(e) i = j = ind for s in range(len(p)): r_i = ind + s l_i = ind - s if(l_i >= 0 and p[l_i] == True and chr(l_i).isalpha()): return chr(l_i) elif(r_i < len(p) and p[r_i] == True and chr(r_i).isalpha()): return chr(r_i) prime = find_prime() s= "AWGrOwUcFWnghtAyvxSb" # "CYGqOqSaGYmggqCqqqSa" for each in s: print(get_nearest(each ,prime))
[
+
]
Show input
Absolute running time: 0.14 sec, cpu time: 0.12 sec, memory peak: 6 Mb, absolute service time: 0,15 sec
edit mode
|
history
|
discussion
C Y G q O q S a G Y m g g q C q q q S a