-
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.
Add Rosetta Code Generator/Exponential test
Also ensure all RC tests are described consistently, with a forward slash (the way they are named on the site) rather than a hyphen (the way they have to be named as files).
- Loading branch information
Showing
3 changed files
with
51 additions
and
2 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 @@ | ||
null |
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,37 @@ | ||
let count = gen() { | ||
let n = 0 | ||
loop { | ||
yield n | ||
n := n + 1 | ||
} | ||
} | ||
|
||
let powers = gen(m) { | ||
for n of count() { | ||
yield n ** m | ||
} | ||
} | ||
|
||
let filtered = gen(s1, s2) { | ||
let v = s1() | ||
let f = s2() | ||
loop { | ||
if v > f { | ||
f := s2() | ||
continue | ||
} else if v < f { | ||
yield v | ||
} | ||
v := s1() | ||
} | ||
} | ||
|
||
|
||
let squares = powers(2) | ||
let cubes = powers(3) | ||
let f = filtered(squares, cubes) | ||
|
||
// Drop first 20 items. | ||
for i of range(20) {f()} | ||
// Print next 10 items. | ||
for i of range(10) {print(f())} |
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