Skip to content

Commit

Permalink
vine: string interpolation (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi authored Feb 12, 2025
1 parent ae82004 commit 95f971a
Show file tree
Hide file tree
Showing 161 changed files with 1,689 additions and 1,540 deletions.
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_01.vi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn main(&io: &IO) {
};
}

io.println("Total Distance: " ++ total_dist.to_string());
io.println("Total Distance: {total_dist}");

let similarity = 0;
let iter_a = left.into_iter();
Expand All @@ -41,5 +41,5 @@ pub fn main(&io: &IO) {
similarity += a * count;
}

io.println("Similarity Score: " ++ similarity.to_string());
io.println("Similarity Score: {similarity}");
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_02.vi
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub fn main(&io: &IO) {
}
}

io.println("Safe Count: " ++ safe_count.to_string());
io.println("Dampened Safe Count: " ++ dampened_safe_count.to_string());
io.println("Safe Count: {safe_count}");
io.println("Dampened Safe Count: {dampened_safe_count}");
}

fn is_safe(report: List[N32]) -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_03.vi
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ pub fn main(&io: &IO) {

let part1 = get_muls(input);

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");

let part2 = get_muls(input.split("do()").map(fn(x: String) {
let (a, _) = x.split_once("don't()");
a
}).join(""));

io.println("Part 2: " ++ part2.to_string());
io.println("Part 2: {part2}");
}

fn get_muls(input: String) -> N32 {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_04.vi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main(&io: &IO) {
0,
);

io.println("XMAS: " ++ matches.to_string());
io.println("XMAS: {matches}");

let matches = diamond(
lines,
Expand All @@ -63,7 +63,7 @@ pub fn main(&io: &IO) {
0,
);

io.println("X-MAS: " ++ matches.to_string());
io.println("X-MAS: {matches}");
}

struct Channel[M](M, ~M);
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_05.vi
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub fn main(&io: &IO) {
}
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 2: " ++ part2.to_string());
io.println("Part 1: {part1}");
io.println("Part 2: {part2}");
}

type Mask = ((N32, N32), (N32, N32));
Expand Down
6 changes: 3 additions & 3 deletions tests/programs/aoc_2024/day_06.vi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main(&io: &IO) {

let (_, length) = walk(&grid, guard_pos);

io.println("Part 1: " ++ length.to_string());
io.println("Part 1: {length}");

let spaces = [];
clear(&grid, &spaces);
Expand All @@ -42,10 +42,10 @@ pub fn main(&io: &IO) {
loops += 1;
}
i += 1;
io.println(i.to_string() ++ " " ++ loops.to_string());
io.println("{i} {loops}");
}

io.println("Part 2: " ++ loops.to_string());
io.println("Part 2: {loops}");
}

fn clear(&grid: &Array[Array[Char]], &spaces: &List[(N32, N32)]) {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_07.vi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ pub fn main(&io: &IO) {
}
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 2: " ++ part2.to_string());
io.println("Part 1: {part1}");
io.println("Part 2: {part2}");
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_08.vi
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ pub fn main(&io: &IO) {
y += 1;
}

io.println("Part 1: " ++ antinodes1.len().to_string());
io.println("Part 2: " ++ antinodes2.len().to_string());
io.println("Part 1: {antinodes1.len()}");
io.println("Part 2: {antinodes2.len()}");
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_09.vi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::numeric::N64;
pub fn main(&io: &IO) {
let input = io.read_line().unwrap();

io.println("Part 1: " ++ part1(input).to_string());
io.println("Part 2: " ++ part2(input).to_string());
io.println("Part 1: {part1(input)}");
io.println("Part 2: {part2(input)}");
}

fn part1(input: String) -> N64 {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_10.vi
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn main(&io: &IO) {
&(io, id, scores, ratings),
);

io.println("Scores: " ++ scores.to_string());
io.println("Ratings: " ++ ratings.to_string());
io.println("Scores: {scores}");
io.println("Ratings: {ratings}");
}

type Set32 = N32;
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_11.vi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn main(&io: &IO) {
while i < max {
stones = blink(&io, stones);
i += 1;
io.println(i.to_string() ++ ": " ++ count(&stones).to_string());
io.println("{i}: {count(&stones)}");
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/programs/aoc_2024/day_12.vi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn main(&io: &IO) {
i += 1;
}

io.println("Part 1: " ++ price.to_string());
io.println("Part 1: {price}");

let width = array.len() / height;

Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn main(&io: &IO) {
y += 1;
}

io.println("Part 2: " ++ bulk.to_string());
io.println("Part 2: {bulk}");
}

struct Regions(Array[Region]);
Expand All @@ -91,8 +91,8 @@ mod Region {
pub impl to_string: ToString[Region] {
fn to_string(self: Region) -> String {
match self {
Region::Root(a, p) { "Root(" ++ a.to_string() ++ ", " ++ p.to_string() ++ ")" }
Region::Child(n) { "Child(" ++ n.to_string() ++ ")" }
Region::Root(a, p) { "Root({a}, {p})" }
Region::Child(n) { "Child({n})" }
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_13.vi
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub fn main(&io: &IO) {
}
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 2: " ++ part2.to_string());
io.println("Part 1: {part1}");
io.println("Part 2: {part2}");
}

const n64: fn(N32) -> N64 = N64::from_n32;
7 changes: 3 additions & 4 deletions tests/programs/aoc_2024/day_14.vi
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ pub fn main(&io: &IO) {

let part1 = a * b * c * d;

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");

let i = 0;
while io.read_line() is Some(line) {
if N32::parse(line) is Some(n) {
i = n;
}
let esc = String({ chars: [Char::from_n32(27)] });
io.println(esc ++ "[2J" ++ esc ++ "[H");
io.println("\x1b[2J\x1b[H");
let grid = Array::new(height, Array::new(width, '.'));
let iter = robots.into_iter();
while iter.next() is Some((px, py, vx, vy)) {
Expand All @@ -81,5 +80,5 @@ pub fn main(&io: &IO) {

let part2 = 0;

io.println("Part 2: " ++ part2.to_string());
io.println("Part 2: {part2}");
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_15.vi
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn main(&io: &IO) {

show_grid();

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");

grid = Array::from_list(initial_grid.to_list().map(fn(row: Array[Char]) {
let new_row = [];
Expand Down Expand Up @@ -196,5 +196,5 @@ pub fn main(&io: &IO) {

show_grid();

io.println("Part 2: " ++ part2.to_string());
io.println("Part 2: {part2}");
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_16.vi
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ pub fn main(&io: &IO) {
}
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");

io.println("Part 2: " ++ part2.to_string());
io.println("Part 2: {part2}");
}

fn delta(dir: N32) -> (N32, N32) {
Expand Down
3 changes: 2 additions & 1 deletion tests/programs/aoc_2024/day_17.vi
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ pub fn main(&io: &IO) {
ip += 2;
}

io.println("Part 1: " ++ output.map(fn(x: N32) { x.to_string() }).join(","));
let output = output.map(fn(x: N32) { x.to_string() }).join(",");
io.println("Part 1: {output}");
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_18.vi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn main(&io: &IO) {

let part1 = pathfind(grid, size, iters);

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");

let set = DisjointSet::new(size * size);

Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn main(&io: &IO) {

let (x, y) = *data.get(i);

io.println("Part 2: " ++ x.to_string() ++ "," ++ y.to_string());
io.println("Part 2: {x},{y}");
}

struct DisjointSet(Array[Node]);
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_19.vi
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub fn main(&io: &IO) {
}
}

io.println("Part 1: " ++ possible.to_string());
io.println("Part 2: " ++ ways.to_string());
io.println("Part 1: {possible}");
io.println("Part 2: {ways}");
}

fn match_counts(design: String, patterns: List[String]) -> Array[N64] {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_20.vi
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ pub fn main(&io: &IO) {
i += 1;
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 2: " ++ part2.to_string());
io.println("Part 1: {part1}");
io.println("Part 2: {part2}");
}

fn eq((ax, ay): (N32, N32), (bx, by): (N32, N32)) -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_21.vi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main(&io: &IO) {
sum += num * len;
}

io.println("Part 1: " ++ sum.to_string());
io.println("Part 1: {sum}");

let c = base_cost_func();
let i = 0;
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn main(&io: &IO) {
sum = sum.add(cost.mul(N64::from_n32(num)));
}

io.println("Part 2: " ++ sum.to_string());
io.println("Part 2: {sum}");
}

fn control_string(cur: Char, string: String, seed: N32, f: fn(Char, Char, Bool) -> String) -> String {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_22.vi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn main(&io: &IO) {
buyer += 1;
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");

io.println(map.len().to_string());

Expand All @@ -40,7 +40,7 @@ pub fn main(&io: &IO) {
part2 = part2.max(bananas);
}

io.println("Part 2: " ++ part2.to_string());
io.println("Part 2: {part2}");
}

fn evolve(&secret: &N32) {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_23.vi
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub fn main(&io: &IO) {
}
}

io.println("Triangles: " ++ triangles.to_string());
io.println("Part 1: " ++ t_triangles.to_string());
io.println("Triangles: {triangles}");
io.println("Part 1: {t_triangles}");
}

fn extend_clique(
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_24.vi
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn main(&io: &IO) {
}
}

io.println("Part 1: " ++ part1.to_string());
io.println("Part 1: {part1}");
}

struct Wire(~Bool, Bool);
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_25.vi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn main(&io: &IO) {
sum += n;
}

io.println("Part 1: " ++ sum.to_string());
io.println("Part 1: {sum}");
}

fn fits(lock: List[N32], key: List[N32]) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/basic_diverge.vi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub fn main(&io: &IO) {
io.println(foo(0, &zero_count));
io.println(foo(1, &zero_count));
io.println(foo(0, &zero_count));
io.println("\nzero_count: " ++ zero_count.to_string());
io.println("\nzero_count: {zero_count}");
}

fn foo(value: N32, &zero_count: &N32) -> String {
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/classify_primes.vi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn main(&io: &IO) {
}
"prime"
};
io.println(n.to_string() ++ ": " ++ class);
io.println("{n}: {class}");
n += 1;
}
}
2 changes: 1 addition & 1 deletion tests/programs/cyclist.vi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn main(&io: &IO) {

while list.pop_front() is Some(val) {
cycle(&list, val);
io.println(val.to_string() ++ ";\t" ++ list.to_string());
io.println("{val};\t{list}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/programs/final_countdown.vi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn main(&io: &IO) {
let i = 10;
while i > 0 {
let &&m = &msg_ref;
m ++= i.to_string() ++ "...\n"
m ++= "{i}...\n"
i -= 1;
}
let &m = msg_ref;
Expand Down
Loading

0 comments on commit 95f971a

Please sign in to comment.