-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the Object.bless() method which returns a blessed object in t…
…he self class. - Minor fix inside the Sidef deparser.
- Loading branch information
trizen
committed
Dec 17, 2015
1 parent
a3b9102
commit 0603970
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Sidef | ||
# | ||
|
||
func sieve_iter(limit) { | ||
var is_prime = [false, false, ([true] * limit-1)...]; | ||
gather { | ||
is_prime.each_kv { |number, prime| | ||
if (prime) { | ||
take(number); | ||
number**2 ... limit -> each { |n| is_prime[n] = false if n%%number } | ||
} | ||
} | ||
} | ||
} | ||
func sieve(Number n) { sieve(2..n) } | ||
func sieve(Array a { .first > .last.sqrt }) { a } | ||
func sieve(Array a) { [a[0], sieve(a.grep { !(_ %% a[0]) })...] } | ||
|
||
var s1 = sieve_iter(100).join(","); | ||
var s2 = sieve(100).join(","); | ||
|
||
say s1; | ||
assert_eq(s1, s2); |