Compare commits
7 commits
df639235b0
...
c5a843ea39
| Author | SHA1 | Date | |
|---|---|---|---|
| c5a843ea39 | |||
| 72b2ec224b | |||
| aeb305210c | |||
| 0f905a7fea | |||
| 8d12c0bdf8 | |||
| 42fa039daf | |||
| db3a3e29eb |
19 changed files with 0 additions and 287 deletions
|
|
@ -1,40 +0,0 @@
|
|||
import "lib/math.ang"
|
||||
|
||||
primes := [2]
|
||||
|
||||
func is_prime(x: number) boolean {
|
||||
i := 0
|
||||
while i < primes.length() && primes.at(i)*primes.at(i) < x {
|
||||
if mod(x, primes.at(i)) == 0 {
|
||||
return false
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
n := 1
|
||||
max := 100000
|
||||
|
||||
while n < max {
|
||||
n = n + 2
|
||||
|
||||
if is_prime(n) {
|
||||
primes.append(n)
|
||||
|
||||
# Update counter
|
||||
print(char(0x0D))
|
||||
print(str(n))
|
||||
print("/")
|
||||
print(str(max))
|
||||
print(char(0x09))
|
||||
print(str(roundd(n/max*100, 2)))
|
||||
print("%")
|
||||
print(char(0x09))
|
||||
print(str(primes.length()))
|
||||
print(" primes")
|
||||
}
|
||||
}
|
||||
|
||||
write(str(primes))
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
fn fib(n: int) -> int {
|
||||
if n < 2 {
|
||||
n
|
||||
} else {
|
||||
fib(n-1) + fib(n-2)
|
||||
}
|
||||
}
|
||||
|
||||
println(fib(2))
|
||||
|
||||
fn other(n: int) -> int {
|
||||
if n <= 0 {
|
||||
n
|
||||
} else {
|
||||
println(n)
|
||||
(n - 1)
|
||||
}
|
||||
}
|
||||
|
||||
println(other(2))
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
MAX_WIDTH := 16
|
||||
|
||||
print(" ")
|
||||
w := 1
|
||||
n := 0x21
|
||||
while n < 0xA0 {
|
||||
print(char(n))
|
||||
n = n + 1
|
||||
w = w + 1
|
||||
if w >= MAX_WIDTH {
|
||||
write("")
|
||||
w = 0
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
|
||||
passphrase := "Hello world!".split("")
|
||||
start := [0, 0, 0]
|
||||
modulus := 10
|
||||
base := byte("!")
|
||||
|
||||
i := 0
|
||||
n := 0
|
||||
while n < passphrase.length() {
|
||||
b := byte(passphrase.at(n))
|
||||
|
||||
v = start.at(i) + b - base
|
||||
while v >= modulus {
|
||||
v = v - modulus
|
||||
}
|
||||
|
||||
start.put(i, v)
|
||||
|
||||
if i >= 3 {
|
||||
i = 0
|
||||
}
|
||||
n = n + 1
|
||||
}
|
||||
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
write(char(0x12) + char(0x85) + char(0x07))
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fn counter() -> (fn() -> int) {
|
||||
i := 0
|
||||
|
||||
fn() -> int { i = i + 1 }
|
||||
}
|
||||
|
||||
next := counter()
|
||||
|
||||
println(next())
|
||||
println(next())
|
||||
println(next())
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
import "lib/honning.ang"
|
||||
|
||||
write(_bell+_italic+"Hello "+_underline+"world "+_strike+"micheal"+_reset)
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
fn foo(n: int) -> str {
|
||||
if n % 2 == 0 {
|
||||
"foo"
|
||||
} else {
|
||||
"bar"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
func is_cool(x: number|string) boolean {
|
||||
if x == "cool" {
|
||||
return true
|
||||
} else if x == 69 {
|
||||
return true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
write(str(is_cool("not cool")))
|
||||
write(str(is_cool("cool")))
|
||||
write(str(is_cool(0)))
|
||||
write(str(is_cool(69)))
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
foo := include "foo.ang"
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
a := fn b(n: int) -> int {
|
||||
n + 1
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
func get(url: string) string {
|
||||
res := request("GET", url, "")
|
||||
|
||||
return res.text
|
||||
}
|
||||
|
||||
write(get("https://www.neemek.com/hello.txt"))
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
import "../lib/math.ang"
|
||||
|
||||
# Inputs
|
||||
c := 1.0*pow(10.0, -2.0)
|
||||
|
||||
println(c)
|
||||
pH := -log(c, 10.0)
|
||||
|
||||
println(pH)
|
||||
|
||||
if pH == 7.0 {
|
||||
println("pH-en er nøytral (=7)")
|
||||
} else if pH < 7.0 {
|
||||
println("pH-en er sur (<7)")
|
||||
} else {
|
||||
println("pH-en er basisk (>7)")
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
|
||||
type Vec2 = (float, float)
|
||||
|
||||
fn add(a: Vec2, b: Vec2) -> Vec2 {
|
||||
(a[0] + b[0], a[1] + b[1])
|
||||
}
|
||||
|
||||
fn sub(a: Vec2, b: Vec2) -> Vec2 {
|
||||
(a[0] - b[0], a[1] - b[1])
|
||||
}
|
||||
|
||||
fn dot(a: Vec2, b: Vec2) -> float {
|
||||
a[0]*b[0] + a[1]*b[1]
|
||||
}
|
||||
|
||||
u := (0.0, 1.0)
|
||||
v := (2.0, 3.0)
|
||||
|
||||
println(add(u, v))
|
||||
println(sub(u, v))
|
||||
println(dot(u, v))
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#!/Users/neemek/Code/anglais/cli/cli run
|
||||
|
||||
import "lib/math.ang"
|
||||
|
||||
x := sqrt(9485739448)
|
||||
write(str(x))
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
a := 0
|
||||
while a < 10 {
|
||||
print(".")
|
||||
a = a + 1
|
||||
}
|
||||
|
||||
write("")
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
# Aliases
|
||||
type Receiver = fn() -> any
|
||||
type Sender = fn(any)
|
||||
|
||||
fn new_channel() -> (Sender, Receiver) {
|
||||
queue := []
|
||||
|
||||
fn send(n: any) {
|
||||
queue.push(n) # mutate in-place
|
||||
}
|
||||
|
||||
fn recv() -> any | nil {
|
||||
queue.pop()
|
||||
}
|
||||
|
||||
(send, recv)
|
||||
}
|
||||
|
||||
(send, recv) := new_channel()
|
||||
|
||||
(
|
||||
send:,
|
||||
recv:,
|
||||
)
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
import "worst.ang"
|
||||
|
||||
write("Hello world!")
|
||||
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
fn range(from: int, to: int) -> (fn() -> (int, bool)) {
|
||||
i := from - 1
|
||||
|
||||
fn() -> (int, bool) {
|
||||
i = i + 1
|
||||
if i >= to {
|
||||
(-1, false)
|
||||
} else {
|
||||
(i, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i in range(0, 10) {
|
||||
println(i)
|
||||
}
|
||||
|
||||
fn chars(s: str) -> (fn() -> (str, bool)) {
|
||||
i := 0
|
||||
|
||||
fn() -> (str, bool) {
|
||||
if i >= s.length() {
|
||||
("", false)
|
||||
} else {
|
||||
c := s[i]
|
||||
i = i + 1
|
||||
|
||||
(c, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for c in chars("hello") {
|
||||
print(c)
|
||||
print(" ")
|
||||
}
|
||||
|
||||
println("")
|
||||
|
||||
fn items(l: [any]) -> (fn() -> (any, bool)) {
|
||||
i := 0
|
||||
|
||||
fn() -> (any, bool) {
|
||||
if i >= l.length() {
|
||||
(nil, false)
|
||||
} else {
|
||||
i = i + 1
|
||||
(l[i - 1], true)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue