mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 12:46:31 +00:00
81 lines
2.3 KiB
Plaintext
81 lines
2.3 KiB
Plaintext
|
|
||
|
fn remainder(left: int, right: int) -> int #[remainder()] {}
|
||
|
|
||
|
fn int_to_string(v: int) -> string #[builtin(IntToString)] {}
|
||
|
|
||
|
fn string_push_char(str: string, value: int) -> string #[builtin(StringPushChar)] {}
|
||
|
fn string_char_at(str: string, index: int) -> int #[builtin(StringCharAt)] {}
|
||
|
fn string_length(str: string) -> int #[builtin(StringLength)] {}
|
||
|
fn string_to_int(v: string) -> int #[builtin(StringToInt)] {}
|
||
|
|
||
|
fn string_array_new() -> [string] #[builtin(ArrayNew)] {}
|
||
|
fn string_array_push(array: [string], value: string) #[builtin(ArrayPush)] {}
|
||
|
fn string_array_length(array: [string]) -> int #[builtin(ArrayLength)] {}
|
||
|
fn string_array_at(array: [string], index: int) -> string #[builtin(ArrayAt)] {}
|
||
|
|
||
|
fn int_array_new() -> [int] #[builtin(ArrayNew)] {}
|
||
|
fn int_array_push(array: [int], value: int) #[builtin(ArrayPush)] {}
|
||
|
fn int_array_length(array: [int]) -> int #[builtin(ArrayLength)] {}
|
||
|
fn int_array_at(array: [int], index: int) -> int #[builtin(ArrayAt)] {}
|
||
|
|
||
|
fn file_open(filename: string, mode: string) -> int #[builtin(FileOpen)] {}
|
||
|
fn file_close(file: int) #[builtin(FileClose)] {}
|
||
|
fn file_write_string(file: int, content: string) -> int #[builtin(FileWriteString)] {}
|
||
|
fn file_read_char(file: int) -> int #[builtin(FileReadChar)] {}
|
||
|
fn file_read_to_string(file: int) -> string #[builtin(FileReadToString)] {}
|
||
|
fn file_flush(file: int) #[builtin(FileFlush)] {}
|
||
|
fn file_eof(file: int) -> bool #[builtin(FileEof)] {}
|
||
|
|
||
|
fn stdin() -> int { 0 }
|
||
|
fn stdout() -> int { 1 }
|
||
|
fn stderr() -> int { 2 }
|
||
|
|
||
|
fn file_read_line(file: int) -> string {
|
||
|
let line = "";
|
||
|
loop {
|
||
|
if file_eof(file) {
|
||
|
break;
|
||
|
}
|
||
|
let ch = file_read_char(file);
|
||
|
if ch == "\n"[0] {
|
||
|
break;
|
||
|
}
|
||
|
line = string_push_char(line, ch);
|
||
|
}
|
||
|
line
|
||
|
}
|
||
|
|
||
|
fn print(msg: string) #[builtin(Print)] {}
|
||
|
fn println(msg: string) { print(msg + "\n") }
|
||
|
|
||
|
fn input(prompt: string) -> string {
|
||
|
print("> ");
|
||
|
file_flush(stdout());
|
||
|
file_read_line(stdin())
|
||
|
}
|
||
|
|
||
|
//
|
||
|
|
||
|
fn is_prime(n: int) -> bool {
|
||
|
if n == 1 or n == 0{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
for (let i = 2; i < n; i += 1) {
|
||
|
if remainder(n, i) == 0 {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
true
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
for (let i = 1; i < 10000; i += 1) {
|
||
|
if is_prime(i) {
|
||
|
print(int_to_string(i) + " ");
|
||
|
}
|
||
|
}
|
||
|
println("");
|
||
|
}
|
||
|
|