-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* $ time ruby 15a.rb MRI: 16s GraalVM --native: 7s With Integer#times written in Ruby to enable OSR: 2s
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
starts = [591, 393] | ||
factors = [16807, 48271] | ||
|
||
Generator = Struct.new(:start, :factor) do | ||
def initialize(*) | ||
super | ||
@n = start | ||
end | ||
|
||
def next | ||
@n = (@n * factor) % 2147483647 | ||
end | ||
end | ||
|
||
generators = starts.zip(factors).map { |start, factor| | ||
Generator.new(start, factor) | ||
} | ||
|
||
p 40_000_000.times.count { | ||
a, b = generators.map { |gen| gen.next % 2**16 } | ||
a == b | ||
} |
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,26 @@ | ||
starts = [591, 393] | ||
factors = [16807, 48271] | ||
multiples = [4, 8] | ||
|
||
Generator = Struct.new(:start, :factor, :multiple) do | ||
def initialize(*) | ||
super | ||
@n = start | ||
end | ||
|
||
def next | ||
begin | ||
@n = (@n * factor) % 2147483647 | ||
end until @n % multiple == 0 | ||
@n | ||
end | ||
end | ||
|
||
generators = starts.zip(factors, multiples).map { |start, factor, multiple| | ||
Generator.new(start, factor, multiple) | ||
} | ||
|
||
p 5_000_000.times.count { | ||
a, b = generators.map { |gen| gen.next % 2**16 } | ||
a == b | ||
} |