-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from KainAlive/main
Add implementations in the Hare language
- Loading branch information
Showing
5 changed files
with
40 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
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,18 @@ | ||
use fmt; | ||
use os; | ||
use strconv; | ||
|
||
fn fibonacci(n: uint) uint = { | ||
if (n == 0) return 0; | ||
if (n == 1) return 1; | ||
return fibonacci(n-1) + fibonacci(n-1); | ||
}; | ||
|
||
export fn main() void = { | ||
let u = strconv::stou(os::args[1])!; | ||
let r: uint = 0; | ||
for (let i: uint = 1; i < u; i+=1) { | ||
r += fibonacci(i); | ||
}; | ||
fmt::printfln("{}", r)!; | ||
}; |
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,19 @@ | ||
use fmt; | ||
use os; | ||
use strconv; | ||
use math::random; | ||
use time; | ||
|
||
export fn main() void = { | ||
let u = strconv::stoi(os::args[1])!; | ||
let rng = random::init(time::unix(time::now(time::clock::REALTIME)): u64); | ||
let r = random::next(&rng) % 1000; | ||
let a: [10000]int = [0...]; | ||
for(let i = 0; i < 10000; i+=1) { | ||
for(let j = 0; j < 100000; j+=1) { | ||
a[i] = a[i] + j%u; | ||
}; | ||
a[i] += r: int; | ||
}; | ||
fmt::printfln("{}", a[r])!; | ||
}; |
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