RosettaCodeData/Task/Cyclops-numbers/11l/cyclops-numbers.11l
2023-07-01 13:44:08 -04:00

71 lines
1.4 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F print50(arr, width = 8)
L(n) arr
print(commatize(n).rjust(width), end' I (L.index + 1) % 10 == 0 {"\n"} E )
F is_cyclops(=n)
I n == 0
R 1B
V m = n % 10
V count = 0
L m != 0
count++
n I/= 10
m = n % 10
n I/= 10
m = n % 10
L m != 0
count--
n I/= 10
m = n % 10
R n == 0 & count == 0
F is_prime(p)
I p < 2 | p % 2 == 0
R p == 2
L(i) (3 .. Int(sqrt(p))).step(2)
I p % i == 0
R 0B
R 1B
F is_palindromic(d)
R String(d) == reversed(String(d))
[Int] arr
print(The first 50 cyclops numbers are:)
L(i) 0..
I is_cyclops(i)
arr.append(i)
I arr.len == 50
L.break
print50(arr)
print("\nThe first 50 prime cyclops numbers are:")
arr.clear()
L(i) 0..
I is_cyclops(i) & is_prime(i)
arr.append(i)
I arr.len == 50
L.break
print50(arr)
print("\nThe first 50 blind prime cyclops numbers are:")
arr.clear()
L(i) 0..
I is_cyclops(i) & is_prime(i)
V istr = String(i)
V mid = istr.len I/ 2
I is_prime(Int(istr[0 .< mid]istr[mid + 1 ..]))
arr.append(i)
I arr.len == 50
L.break
print50(arr)
print("\nThe first 50 palindromic prime cyclops numbers are:")
arr.clear()
L(i) 0..
I is_cyclops(i) & is_prime(i) & is_palindromic(i)
arr.append(i)
I arr.len == 50
L.break
print50(arr, 11)