Rebol3 Code Examplex
Prime conspiracy
Rebol [
title: "Rosetta code: Prime conspiracy"
file: %Prime_conspiracy.r3
url: https://rosettacode.org/wiki/Prime_conspiracy
]
prime-conspiracy: function [
"Return map of frequencies for final digits of consecutive primes"
limit [integer!]
][
freq: #[1 #[] 2 #[3 1] 3 #[] 5 #[] 7 #[] 9 #[]] ;; 2->3 transition pre-seeded
count: 2 ;; 2 and 3 already counted
last: x: 3
while [count < limit] [
x: x + 2
if prime? x [
ending: x % 10
row: freq/:last
row/:ending: 1 + any [row/:ending 0]
last: ending
count: count + 1
]
]
freq
]
limit: 1000000
t: prime-conspiracy limit
for a 1 9 1 [
for b 1 9 1 [
if all [row: t/:a row/:b] [
print ajoin [
a " -> " b "^-count: " row/:b
"^-frequency: " round/to row/:b / limit * 100 0.0001 "%"
]
]
]
]Output:
1 -> 1 count: 42853 frequency: 4.2853%
1 -> 3 count: 77475 frequency: 7.7475%
1 -> 7 count: 79453 frequency: 7.9453%
1 -> 9 count: 50153 frequency: 5.0153%
2 -> 3 count: 1 frequency: 0.0001%
3 -> 1 count: 58255 frequency: 5.8255%
3 -> 3 count: 39668 frequency: 3.9668%
3 -> 5 count: 1 frequency: 0.0001%
3 -> 7 count: 72827 frequency: 7.2827%
3 -> 9 count: 79358 frequency: 7.9358%
5 -> 7 count: 1 frequency: 0.0001%
7 -> 1 count: 64230 frequency: 6.423%
7 -> 3 count: 68595 frequency: 6.8595%
7 -> 7 count: 39603 frequency: 3.9603%
7 -> 9 count: 77586 frequency: 7.7586%
9 -> 1 count: 84596 frequency: 8.4596%
9 -> 3 count: 64371 frequency: 6.4371%
9 -> 7 count: 58130 frequency: 5.813%
9 -> 9 count: 42843 frequency: 4.2843%