Files
rexlang/examples/basics/sieve.rex
T
Your NameandClaude Opus 5.5 7cf9727bcd Rename the language from Dino to Rex
Files use .rex, the command is rex, and the crate, runtime prefixes,
docs, editor files and examples all use the new name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:51:23 +01:00

46 lines
934 B
Rexx

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)
}