-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_k-rough_numbers.sf
45 lines (33 loc) · 1.71 KB
/
generate_k-rough_numbers.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby
# A simple algorithm for generating k-rough numbers.
# See also:
# https://oeis.org/A008364
func rough_generator(k) {
Enumerator({|f|
var c = primorial(k-1)
var a = []
for n in (1..c) {
n.is_coprime(c) || next
a.push(n)
f(n)
}
loop {
var n = (a.shift + c)
a.push(n)
f(n)
}
})
}
var rough11 = rough_generator(11)
var rough13 = rough_generator(13)
say "First 100 11-rough numbers:"
say rough11.first(100)
say "\nFirst 100 13-rough numbers:"
say rough13.first(100)
assert_eq(rough11.first(100), 100.by { .is_rough(11) })
assert_eq(rough13.first(100), 100.by { .is_rough(13) })
__END__
First 100 11-rough numbers:
[1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209, 211, 221, 223, 227, 229, 233, 239, 241, 247, 251, 253, 257, 263, 269, 271, 277, 281, 283, 289, 293, 299, 307, 311, 313, 317, 319, 323, 331, 337, 341, 347, 349, 353, 359, 361, 367, 373, 377, 379, 383, 389, 391, 397, 401, 403, 407, 409, 419, 421, 431, 433, 437]
First 100 13-rough numbers:
[1, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 169, 173, 179, 181, 191, 193, 197, 199, 211, 221, 223, 227, 229, 233, 239, 241, 247, 251, 257, 263, 269, 271, 277, 281, 283, 289, 293, 299, 307, 311, 313, 317, 323, 331, 337, 347, 349, 353, 359, 361, 367, 373, 377, 379, 383, 389, 391, 397, 401, 403, 409, 419, 421, 431, 433, 437, 439, 443, 449, 457, 461, 463, 467, 479, 481]