Dino compiler: language, formatter, language server, docs, editor support
Compiler in Rust (lexer, parser, checker, C codegen), maps, chars, dino fmt, dino lsp (diagnostics, formatting, outline, definition, hover, completion, signature help), docs, examples, VS Code/Vim files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e2779f447
commit
eaf9567a36
117 files changed
+19970
No files matched your search
@@ -0,0 +1,45 @@
|
||||
func primes_up_to(n: int): []int {
|
||||
var is_prime: []bool
|
||||
for i in 0..n + 1 {
|
||||
is_prime.push(true)
|
||||
}
|
||||
is_prime[0] = false
|
||||
is_prime[1] = false
|
||||
for i in 2..n + 1 {
|
||||
if is_prime[i] {
|
||||
for j in i * i..n + 1 step i {
|
||||
is_prime[j] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
var out: []int
|
||||
for i, p in is_prime {
|
||||
if p {
|
||||
out.push(i)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func bubble_sort(xs: []int): []int {
|
||||
var n = xs.len()
|
||||
for i in 0..n {
|
||||
for j in 0..n - i - 1 {
|
||||
if xs[j] > xs[j + 1] {
|
||||
var tmp = xs[j]
|
||||
xs[j] = xs[j + 1]
|
||||
xs[j + 1] = tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
return xs
|
||||
}
|
||||
|
||||
func main() {
|
||||
var ps = primes_up_to(60)
|
||||
print(ps)
|
||||
print("count:", ps.len())
|
||||
var unsorted = [9, 4, 7, 1, 8, 2]
|
||||
var sorted = bubble_sort(unsorted)
|
||||
print(unsorted, "->", sorted)
|
||||
}
|
||||
Reference in new issue
Block a user