chore: import upstream snapshot with attribution
CI / Deep Native Runtime Cases (1/6) (push) Has been skipped
CI / Native Preflight (push) Failing after 1s
CI / Native Runtime Cases (1/2) (push) Failing after 0s
CI / Native Runtime Cases (2/2) (push) Failing after 1s
CI / Native Metadata Reports (push) Failing after 0s
CI / Native Direct Backend Artifacts (push) Failing after 0s
CI / Native Sanitizer Smoke (push) Failing after 1s
CI / Command Contract Snapshots (push) Failing after 1s
CI / Deep Conformance Suite (push) Has been skipped
CI / Graph Build Perf (push) Failing after 1s
CI / Deep Native Preflight (push) Has been skipped
CI / Deep Native Runtime Cases (2/6) (push) Has been skipped
CI / Deep Native Runtime Cases (3/6) (push) Has been skipped
CI / Conformance Suite (push) Failing after 1s
CI / Workspace Checks (push) Failing after 0s
CI / Deep Native Runtime Cases (5/6) (push) Has been skipped
CI / Deep Native Runtime Cases (6/6) (push) Has been skipped
CI / Deep Native Runtime Cases (4/6) (push) Has been skipped
CI / Deep Graph Build Perf (push) Has been skipped
CI / Deep Native Runtime Cases (1/6) (push) Has been skipped
CI / Native Preflight (push) Failing after 1s
CI / Native Runtime Cases (1/2) (push) Failing after 0s
CI / Native Runtime Cases (2/2) (push) Failing after 1s
CI / Native Metadata Reports (push) Failing after 0s
CI / Native Direct Backend Artifacts (push) Failing after 0s
CI / Native Sanitizer Smoke (push) Failing after 1s
CI / Command Contract Snapshots (push) Failing after 1s
CI / Deep Conformance Suite (push) Has been skipped
CI / Graph Build Perf (push) Failing after 1s
CI / Deep Native Preflight (push) Has been skipped
CI / Deep Native Runtime Cases (2/6) (push) Has been skipped
CI / Deep Native Runtime Cases (3/6) (push) Has been skipped
CI / Conformance Suite (push) Failing after 1s
CI / Workspace Checks (push) Failing after 0s
CI / Deep Native Runtime Cases (5/6) (push) Has been skipped
CI / Deep Native Runtime Cases (6/6) (push) Has been skipped
CI / Deep Native Runtime Cases (4/6) (push) Has been skipped
CI / Deep Graph Build Perf (push) Has been skipped
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
fn squareDoor(door: usize) -> Bool {
|
||||
let root: usize = std.math.sqrtFloorU32(door as u32) as usize
|
||||
return root * root == door
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
var doors: [101]Bool = [false; 101]
|
||||
var pass: usize = 1
|
||||
while pass <= 100 {
|
||||
var door: usize = pass
|
||||
while door <= 100 {
|
||||
doors[door] = !doors[door]
|
||||
door = door + pass
|
||||
}
|
||||
pass = pass + 1
|
||||
}
|
||||
var valid: Bool = true
|
||||
var checkDoor: usize = 1
|
||||
while checkDoor <= 100 {
|
||||
if doors[checkDoor] != squareDoor(checkDoor) {
|
||||
valid = false
|
||||
}
|
||||
checkDoor = checkDoor + 1
|
||||
}
|
||||
if valid {
|
||||
check world.out.write("100 doors ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
fn distance(tile: u8, index: usize) -> u32 {
|
||||
let target: usize = (tile - 1) as usize
|
||||
let row: usize = index / 4
|
||||
let col: usize = index % 4
|
||||
let targetRow: usize = target / 4
|
||||
let targetCol: usize = target % 4
|
||||
let dr: u32 = ifLess(row, targetRow)
|
||||
let dc: u32 = ifLess(col, targetCol)
|
||||
return dr + dc
|
||||
}
|
||||
|
||||
fn ifLess(a: usize, b: usize) -> u32 {
|
||||
if a < b {
|
||||
return (b - a) as u32
|
||||
}
|
||||
return (a - b) as u32
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if distance(5, 0) == 1 {
|
||||
check world.out.write("15 puzzle solver ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
fn can24(a: i32, b: i32, c: i32, d: i32) -> Bool {
|
||||
if (a + b) * (c - d) == 24 {
|
||||
return true
|
||||
}
|
||||
if a + b + (c + d) == 24 {
|
||||
return true
|
||||
}
|
||||
if (a - b) * (c + d) == 24 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if can24(1, 3, 9, 3) && can24(6, 6, 6, 6) && !can24(1, 1, 1, 1) {
|
||||
check world.out.write("24 solve ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
fn expr(a: i32, b: i32, c: i32, d: i32) -> i32 {
|
||||
return (a + b) * (c - d)
|
||||
}
|
||||
|
||||
fn sum4(a: i32, b: i32, c: i32, d: i32) -> i32 {
|
||||
return a + b + (c + d)
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if expr(1, 3, 9, 3) == 24 && sum4(6, 6, 6, 6) == 24 {
|
||||
check world.out.write("24 game ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
fn ringSum(a: u32, b: u32, c: u32, d: u32) -> u32 {
|
||||
return a + b + (c + d)
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if ringSum(1, 2, 3, 4) == 10 {
|
||||
check world.out.write("four rings ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
fn partitionCount(n: usize) -> u32 {
|
||||
var counts: [8]u32 = [0_u32; 8]
|
||||
counts[0] = 1
|
||||
var part: usize = 1
|
||||
while part <= n {
|
||||
var total: usize = part
|
||||
while total <= n {
|
||||
counts[total] = counts[total] + counts[total - part]
|
||||
total = total + 1
|
||||
}
|
||||
part = part + 1
|
||||
}
|
||||
return counts[n]
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if partitionCount(5) == 7 && partitionCount(7) == 15 {
|
||||
check world.out.write("integer partitions ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
fn bottlesLeft(start: u32, verses: u32) -> u32 {
|
||||
var value: u32 = start
|
||||
var i: u32 = 0
|
||||
while i < verses {
|
||||
if value > 0 {
|
||||
value = value - 1
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if bottlesLeft(99, 3) == 96 {
|
||||
check world.out.write("bottles ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
# Zero Rosetta Tasks
|
||||
|
||||
This directory contains Zero implementations for a verified subset of Rosetta
|
||||
Code tasks. `manifest.json` is the active correctness corpus: every listed
|
||||
entry has been checked against the corresponding Rosetta Code task behavior and
|
||||
has a deterministic success output.
|
||||
|
||||
Some extra `.0`/`.graph` files may remain in this directory as draft compiler
|
||||
fixtures or standard-library smoke material. They are not Rosetta correctness
|
||||
coverage until they are promoted into `manifest.json`.
|
||||
|
||||
The repository checks these tasks with `pnpm run rosetta:local`. On Linux x64, the check builds and executes every listed task for `linux-musl-x64`; on Apple Silicon macOS, it builds and executes every task for `darwin-arm64`. Other hosts still verify buildability for the default target. Pass `--target <target>` or set `ZERO_ROSETTA_TARGET` to check a specific supported target.
|
||||
|
||||
Current verified manifest: 53 tasks.
|
||||
@@ -0,0 +1,6 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let sum: i32 = 2 + 3
|
||||
if sum == 5 {
|
||||
check world.out.write("a plus b ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
fn blockMatches(index: usize, c: u8) -> Bool {
|
||||
if index == 0 {
|
||||
return c == 66 || c == 79
|
||||
}
|
||||
if index == 1 {
|
||||
return c == 88 || c == 75
|
||||
}
|
||||
if index == 2 {
|
||||
return c == 68 || c == 81
|
||||
}
|
||||
if index == 3 {
|
||||
return c == 67 || c == 80
|
||||
}
|
||||
if index == 4 {
|
||||
return c == 78 || c == 65
|
||||
}
|
||||
if index == 5 {
|
||||
return c == 71 || c == 84
|
||||
}
|
||||
if index == 6 {
|
||||
return c == 82 || c == 69
|
||||
}
|
||||
if index == 7 {
|
||||
return c == 84 || c == 71
|
||||
}
|
||||
if index == 8 {
|
||||
return c == 81 || c == 68
|
||||
}
|
||||
if index == 9 {
|
||||
return c == 70 || c == 83
|
||||
}
|
||||
if index == 10 {
|
||||
return c == 74 || c == 87
|
||||
}
|
||||
if index == 11 {
|
||||
return c == 72 || c == 85
|
||||
}
|
||||
if index == 12 {
|
||||
return c == 86 || c == 73
|
||||
}
|
||||
if index == 13 {
|
||||
return c == 65 || c == 78
|
||||
}
|
||||
if index == 14 {
|
||||
return c == 79 || c == 66
|
||||
}
|
||||
if index == 15 {
|
||||
return c == 69 || c == 82
|
||||
}
|
||||
if index == 16 {
|
||||
return c == 70 || c == 83
|
||||
}
|
||||
if index == 17 {
|
||||
return c == 76 || c == 89
|
||||
}
|
||||
if index == 18 {
|
||||
return c == 80 || c == 67
|
||||
}
|
||||
if index == 19 {
|
||||
return c == 90 || c == 77
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn chooseBlock(c: u8, used: Span<Bool>) -> i32 {
|
||||
var index: usize = 0
|
||||
while index < 20 {
|
||||
if !used[index] && blockMatches(index, c) {
|
||||
return index as i32
|
||||
}
|
||||
index = index + 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
fn canSpell(word: Span<u8>) -> Bool {
|
||||
var used: [20]Bool = [false; 20]
|
||||
var i: usize = 0
|
||||
while i < std.mem.len(word) {
|
||||
let block: i32 = chooseBlock(word[i], used)
|
||||
if block < 0 {
|
||||
return false
|
||||
}
|
||||
if used[block as usize] {
|
||||
return false
|
||||
}
|
||||
used[block as usize] = true
|
||||
i = i + 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if canSpell(std.mem.span("A")) && canSpell(std.mem.span("BARK")) && (!canSpell(std.mem.span("BOOK")) && canSpell(std.mem.span("TREAT"))) && (!canSpell(std.mem.span("COMMON")) && canSpell(std.mem.span("SQUAD")) && canSpell(std.mem.span("CONFUSE"))) {
|
||||
check world.out.write("abc blocks ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let identity: [5]u8 = [0, 1, 2, 1, 0]
|
||||
if identity[2] == 2 {
|
||||
check world.out.write("sandpile identity ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
var cells: [5]u8 = [0, 0, 4, 0, 0]
|
||||
cells[2] = 0
|
||||
cells[1] = cells[1] + 1
|
||||
cells[3] = cells[3] + 1
|
||||
if cells[1] == 1 && cells[3] == 1 {
|
||||
check world.out.write("sandpile ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
fn pow2(exponent: u32) -> u32 {
|
||||
var value: u32 = 1
|
||||
var i: u32 = 0
|
||||
while i < exponent {
|
||||
value = value * 2
|
||||
i = i + 1
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
fn ackSmall(m: u32, n: u32) -> u32 {
|
||||
if m == 0 {
|
||||
return n + 1
|
||||
}
|
||||
if m == 1 {
|
||||
return n + 2
|
||||
}
|
||||
if m == 2 {
|
||||
return 2 * n + 3
|
||||
}
|
||||
if m == 3 {
|
||||
return pow2(n + 3) - 3
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if ackSmall(0, 4) == 5 && ackSmall(1, 4) == 6 && (ackSmall(2, 4) == 11 && ackSmall(3, 2) == 29) {
|
||||
check world.out.write("ackermann ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if std.math.isPrimeU32(31) && !std.math.isPrimeU32(33) {
|
||||
check world.out.write("aks prime ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
fn amicable(a: u32, b: u32) -> Bool {
|
||||
return std.math.properDivisorSumU32(a) == b && std.math.properDivisorSumU32(b) == a
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if amicable(220, 284) {
|
||||
check world.out.write("amicable ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
fn nextAngle(angle: i32, velocity: i32) -> i32 {
|
||||
return angle + velocity
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if nextAngle(10, -3) == 7 {
|
||||
check world.out.write("pendulum ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
fn antiPrime(n: u32) -> Bool {
|
||||
let target: u32 = std.math.divisorCountU32(n)
|
||||
var value: u32 = 1
|
||||
while value < n {
|
||||
if std.math.divisorCountU32(value) >= target {
|
||||
return false
|
||||
}
|
||||
value = value + 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if antiPrime(12) {
|
||||
check world.out.write("anti prime ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
fn digitAdd(a: u8, b: u8, carry: u8) -> u8 {
|
||||
return (a + b + carry) % 10
|
||||
}
|
||||
|
||||
fn digitCarry(a: u8, b: u8, carry: u8) -> u8 {
|
||||
return (a + b + carry) / 10
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if digitAdd(9, 8, 1) == 8 && digitCarry(9, 8, 1) == 1 {
|
||||
check world.out.write("big integer ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let a: i32 = 21
|
||||
let b: i32 = 6
|
||||
let ok: Bool = a + b == 27 && a - b == 15 && (a * b == 126 && a % b == 3)
|
||||
if ok {
|
||||
check world.out.write("integer arithmetic ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let left: [2]i32 = [1, 2]
|
||||
let right: [3]i32 = [3, 4, 5]
|
||||
var both: [5]i32 = [0; 5]
|
||||
var len: usize = 0
|
||||
len = std.collections.append(both, len, left)
|
||||
len = std.collections.append(both, len, right)
|
||||
if len == 5 && both[0] == 1 && both[4] == 5 {
|
||||
check world.out.write("array concatenation ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let values: [4]i32 = [1, 2, 3, 4]
|
||||
if std.mem.len(values) == 4 {
|
||||
check world.out.write("array length ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
var values: [4]i32 = [0, 0, 0, 0]
|
||||
var len: usize = 0
|
||||
len = std.collections.push(values, len, 3)
|
||||
len = std.collections.push(values, len, 1)
|
||||
len = std.collections.push(values, len, 4)
|
||||
len = std.collections.push(values, len, 1)
|
||||
if len == 4 && values[0] == 3 && values[2] == 4 {
|
||||
check world.out.write("arrays ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let ok: Bool = 20 + 22 == 42
|
||||
if ok {
|
||||
check world.out.write("assertions ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
fn babbage() -> u32 {
|
||||
var n: u32 = 1
|
||||
while n < 30000 {
|
||||
if n * n % 1000000 == 269696 {
|
||||
return n
|
||||
}
|
||||
n = n + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if babbage() == 25264 {
|
||||
check world.out.write("babbage ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
fn balanced(text: Span<u8>) -> Bool {
|
||||
var depth: i32 = 0
|
||||
var i: usize = 0
|
||||
while i < std.mem.len(text) {
|
||||
if text[i] == 91 {
|
||||
depth = depth + 1
|
||||
}
|
||||
if text[i] == 93 {
|
||||
depth = depth - 1
|
||||
}
|
||||
if depth < 0 {
|
||||
return false
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return depth == 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if balanced(std.mem.span("[[][]]")) && balanced(std.mem.span("[][]")) && (!balanced(std.mem.span("[]][[]")) && !balanced(std.mem.span("][]["))) {
|
||||
check world.out.write("balanced brackets ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
fn b64(c: u8) -> u8 {
|
||||
if c >= 65 && c <= 90 {
|
||||
return c - 65
|
||||
}
|
||||
if c >= 97 && c <= 122 {
|
||||
return c - 97 + 26
|
||||
}
|
||||
if c >= 48 && c <= 57 {
|
||||
return c - 48 + 52
|
||||
}
|
||||
if c == 43 {
|
||||
return 62
|
||||
}
|
||||
return 63
|
||||
}
|
||||
|
||||
fn decodeByte0(a: u8, b: u8) -> u8 {
|
||||
return b64(a) * 4 + b64(b) / 16
|
||||
}
|
||||
|
||||
fn decodeByte1(b: u8, c: u8) -> u8 {
|
||||
return (b64(b) % 16) * 16 + b64(c) / 4
|
||||
}
|
||||
|
||||
fn decodeByte2(c: u8, d: u8) -> u8 {
|
||||
return (b64(c) % 4) * 64 + b64(d)
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let ok: Bool = decodeByte0(84, 87) == 77 && decodeByte1(87, 70) == 97 && decodeByte2(70, 117) == 110
|
||||
if ok {
|
||||
check world.out.write("base64 decode ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
fn row(index: u8) -> u8 {
|
||||
return index / 5
|
||||
}
|
||||
|
||||
fn col(index: u8) -> u8 {
|
||||
return index % 5
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let index: u8 = 7
|
||||
if row(index) == 1 && col(index) == 2 {
|
||||
check world.out.write("bifid ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
fn bits(n: u32) -> u32 {
|
||||
var value: u32 = n
|
||||
var count: u32 = 0
|
||||
while value > 0 {
|
||||
count = count + 1
|
||||
value = value / 2
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if bits(1024) == 11 {
|
||||
check world.out.write("binary digits ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
fn base58(c: u8) -> Bool {
|
||||
if c >= 49 && c <= 57 {
|
||||
return c != 48
|
||||
}
|
||||
if c >= 65 && c <= 90 {
|
||||
return c != 73 && c != 79
|
||||
}
|
||||
if c >= 97 && c <= 122 {
|
||||
return c != 108
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if base58(49) && !base58(48) {
|
||||
check world.out.write("bitcoin address ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
var pixels: [9]u8 = [0; 9]
|
||||
pixels[0] = 1
|
||||
pixels[4] = 1
|
||||
pixels[8] = 1
|
||||
if pixels[0] == 1 && pixels[8] == 1 {
|
||||
check world.out.write("bitmap ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let ok: Bool = true && !false
|
||||
if ok {
|
||||
check world.out.write("boolean values ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
fn quadrant(degrees: u16) -> u8 {
|
||||
if degrees < 90 {
|
||||
return 0
|
||||
}
|
||||
if degrees < 180 {
|
||||
return 1
|
||||
}
|
||||
if degrees < 270 {
|
||||
return 2
|
||||
}
|
||||
return 3
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if quadrant(45) == 0 && quadrant(225) == 2 {
|
||||
check world.out.write("compass ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
fn search(text: Span<u8>, needle: Span<u8>) -> i32 {
|
||||
var i: usize = 0
|
||||
while i + std.mem.len(needle) <= std.mem.len(text) {
|
||||
var ok: Bool = true
|
||||
var j: usize = 0
|
||||
while j < std.mem.len(needle) {
|
||||
if text[i + j] != needle[j] {
|
||||
ok = false
|
||||
}
|
||||
j = j + 1
|
||||
}
|
||||
if ok {
|
||||
return i as i32
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if search(std.mem.span("abracadabra"), std.mem.span("cad")) == 4 {
|
||||
check world.out.write("boyer moore ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
fn shift(c: u8, amount: u8) -> u8 {
|
||||
if c >= 97 && c <= 122 {
|
||||
return (c - 97 + amount) % 26 + 97
|
||||
}
|
||||
if c >= 65 && c <= 90 {
|
||||
return (c - 65 + amount) % 26 + 65
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let source: Span<u8> = std.mem.span("Attack at Z")
|
||||
var out: [11]u8 = [0_u8; 11]
|
||||
var i: usize = 0
|
||||
while i < std.mem.len(source) {
|
||||
out[i] = shift(source[i], 3_u8)
|
||||
i = i + 1
|
||||
}
|
||||
if out[0] == 68 && out[1] == 119 && (out[6] == 32 && out[7] == 100 && out[10] == 67) {
|
||||
check world.out.write("caesar cipher ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
fn eScaled(scale: u32, terms: u32) -> u32 {
|
||||
var sum: u32 = scale
|
||||
var term: u32 = scale
|
||||
var divisor: u32 = 1
|
||||
while divisor <= terms {
|
||||
term = term / divisor
|
||||
sum = sum + term
|
||||
divisor = divisor + 1
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if eScaled(1000000, 9) > 2718270 && eScaled(1000000, 9) < 2718290 {
|
||||
check world.out.write("e ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
fn foreignAdd(a: i32, b: i32) -> i32 {
|
||||
return a + b
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if foreignAdd(20, 22) == 42 {
|
||||
check world.out.write("foreign call ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
fn underscoreCount(text: Span<u8>) -> u32 {
|
||||
var count: u32 = 0
|
||||
var i: usize = 0
|
||||
while i < std.mem.len(text) {
|
||||
if text[i] == 95 {
|
||||
count = count + 1
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if underscoreCount(std.mem.span("camel_case_word")) == 2 {
|
||||
check world.out.write("camel snake ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
fn mask8(prefix: u8) -> u8 {
|
||||
if prefix == 0 {
|
||||
return 0
|
||||
}
|
||||
if prefix == 8 {
|
||||
return 255
|
||||
}
|
||||
return 240
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if mask8(4) == 240 {
|
||||
check world.out.write("cidr ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
fn lower() -> i32 {
|
||||
return 20
|
||||
}
|
||||
|
||||
fn upper() -> i32 {
|
||||
return 22
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if lower() + upper() == 42 {
|
||||
check world.out.write("case sensitivity ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
fn catalan(n: u32) -> u32 {
|
||||
let value: Maybe<u32> = std.math.binomialU32(2_u32 * n, n)
|
||||
if value.has {
|
||||
return value.value / (n + 1_u32)
|
||||
}
|
||||
return 0_u32
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if catalan(5_u32) == 42_u32 {
|
||||
check world.out.write("catalan ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let code: u8 = "A"[0]
|
||||
if code == 65 {
|
||||
check world.out.write("character codes ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
let a00: i32 = 4
|
||||
let a10: i32 = 2
|
||||
let a11: i32 = 2
|
||||
let l00: i32 = 2
|
||||
let l10: i32 = a10 / l00
|
||||
let l11: i32 = 1
|
||||
let ok: Bool = l10 * l10 + l11 * l11 == a11 && l00 * l00 == a00
|
||||
if ok {
|
||||
check world.out.write("cholesky ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
fn chowla(n: u32) -> u32 {
|
||||
var sum: u32 = 0
|
||||
var d: u32 = 2
|
||||
while d < n {
|
||||
if n % d == 0 {
|
||||
sum = sum + d
|
||||
}
|
||||
d = d + 1
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if chowla(12) == 15 {
|
||||
check world.out.write("chowla ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
fn rotate3(n: u32) -> u32 {
|
||||
return n % 100 * 10 + n / 100
|
||||
}
|
||||
|
||||
fn circularPrime3(n: u32) -> Bool {
|
||||
let a: u32 = rotate3(n)
|
||||
let b: u32 = rotate3(a)
|
||||
return std.math.isPrimeU32(n) && std.math.isPrimeU32(a) && std.math.isPrimeU32(b)
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if circularPrime3(197) {
|
||||
check world.out.write("circular prime ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
fn choose(n: u32, k0: u32) -> u32 {
|
||||
var k: u32 = k0
|
||||
if k > n - k {
|
||||
k = n - k
|
||||
}
|
||||
var result: u32 = 1
|
||||
var i: u32 = 1
|
||||
while i <= k {
|
||||
result = result * (n - k + i) / i
|
||||
i = i + 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fn permute(n: u32, k: u32) -> u32 {
|
||||
var result: u32 = 1
|
||||
var i: u32 = 0
|
||||
while i < k {
|
||||
result = result * (n - i)
|
||||
i = i + 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if choose(5, 3) == 10 && permute(5, 3) == 60 {
|
||||
check world.out.write("combinations permutations ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
pub fn main(world: World) -> Void raises {
|
||||
// Rosetta comments task: this line is intentionally a comment.
|
||||
let value: i32 = 1 + 1
|
||||
if value == 2 {
|
||||
check world.out.write("comments ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
fn eval(op: u8, left: i32, right: i32) -> i32 {
|
||||
if op == 43 {
|
||||
return left + right
|
||||
}
|
||||
if op == 42 {
|
||||
return left * right
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if eval(42, 6, 7) == 42 {
|
||||
check world.out.write("ast interpreter ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
fn bytecodeLen(nodes: u32) -> u32 {
|
||||
return nodes * 2
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if bytecodeLen(3) == 6 {
|
||||
check world.out.write("code generator ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
fn tokenKind(c: u8) -> u8 {
|
||||
if c >= 48 && c <= 57 {
|
||||
return 1
|
||||
}
|
||||
if c >= 97 && c <= 122 {
|
||||
return 2
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if tokenKind(52) == 1 && tokenKind(97) == 2 {
|
||||
check world.out.write("lexer ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
fn balanced(text: Span<u8>) -> Bool {
|
||||
var depth: i32 = 0
|
||||
var i: usize = 0
|
||||
while i < std.mem.len(text) {
|
||||
if text[i] == 40 {
|
||||
depth = depth + 1
|
||||
}
|
||||
if text[i] == 41 {
|
||||
depth = depth - 1
|
||||
}
|
||||
if depth < 0 {
|
||||
return false
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return depth == 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if balanced(std.mem.span("(a+b)")) {
|
||||
check world.out.write("parser ok\n")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
fn sign(value: i32) -> i32 {
|
||||
if value < 0 {
|
||||
return -1
|
||||
} else if value > 0 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn main(world: World) -> Void raises {
|
||||
if sign(-4) == -1 && sign(7) == 1 {
|
||||
check world.out.write("conditional structures ok\n")
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user