-
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.
- Loading branch information
Showing
5 changed files
with
131 additions
and
31 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
/out |
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 |
---|---|---|
@@ -1,18 +1,75 @@ | ||
alias string = [int]; | ||
extern printstr: fn(string): unit; | ||
extern printint: fn(int): unit; | ||
extern index: fn([int], int): int; | ||
extern setindex: fn([int], int, int): unit; | ||
extern setindex: fn([int],int,int): unit; | ||
|
||
let greeting = fn(): string { | ||
let str = "hello world"; | ||
printstr(str); | ||
str | ||
let isqrt_go = fn(a: int, s: int): int { | ||
let a_ = (a + s / a) / 2; | ||
|
||
if a_ >= a { | ||
a | ||
} else { | ||
isqrt_go(a_,s) | ||
} | ||
}; | ||
|
||
let isqrt = fn(a: int): int { | ||
isqrt_go(a,a) | ||
}; | ||
|
||
|
||
let gcd = fn(a: int,b:int): int { | ||
if b > a { | ||
gcd(b,a) | ||
} else { | ||
if b == 0 { | ||
a | ||
} else { | ||
gcd(a, b % a) | ||
} | ||
} | ||
}; | ||
|
||
let fraction_root_go = fn(cur_ind: int, list: [int], root_value: int, | ||
numerator_plus: int, divisor: int, stop_at: int, | ||
len: int): int { | ||
let an = (isqrt(root_value) + numerator_plus) / 2; | ||
|
||
if an == stop_at { | ||
cur_ind - 1 | ||
} else { | ||
if cur_ind >= len { | ||
printstr("value won't be correct becasue not enough array space was allocated"); | ||
-1 | ||
} else { | ||
setindex(list,cur_ind,an); | ||
|
||
let denom = (root_value - | ||
numerator_plus * numerator_plus - | ||
an * an * divisor * divisor + | ||
2 * an * divisor * numerator_plus); | ||
|
||
let gcd = gcd(divisor,denom); | ||
} | ||
} | ||
}; | ||
|
||
|
||
let fraction_root = fn(a: int, list: [int], len: int): int { | ||
let a_zero = isqrt(a); | ||
|
||
setindex(a,0,a_zero); | ||
|
||
if (a_zero * a_zero == a) { | ||
0 | ||
} else { | ||
fraction_root_go(1,list,a,a_zero,(a - a_zero * a_zero), a_zero * 2, len) | ||
} | ||
}; | ||
|
||
let main = fn() { | ||
let x = [64, 65, 64]; | ||
printint(index(x, 1)); | ||
setindex(x, 1, 64); | ||
printint(index(x, 1)); | ||
printstr(greeting()) | ||
printint(isqrt(10)); | ||
printint(isqrt(100)); | ||
printint(isqrt(4)); | ||
printint(isqrt(201)); | ||
}; |
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,20 @@ | ||
alias string = [int]; | ||
extern printstr: fn(string): unit; | ||
extern printint: fn(int): unit; | ||
|
||
let sum_to = fn(a: int): int { | ||
let ugly_hack = a + 1; | ||
let num = a * ugly_hack; | ||
num/2 | ||
}; | ||
|
||
let three_five_sum = fn(a: int): int { | ||
let a = a - 1; | ||
|
||
sum_to(a/3) * 3 + sum_to(a/5) * 5 - sum_to(a/15) * 15 | ||
}; | ||
|
||
let main = fn() { | ||
printstr("result: "); | ||
printint(three_five_sum(1000)) | ||
}; |
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