complete day 5 part 1
This commit is contained in:
1186
day5.input
Normal file
1186
day5.input
Normal file
File diff suppressed because it is too large
Load Diff
73
day5.jai
Normal file
73
day5.jai
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
sample :: #string END
|
||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
|
END
|
||||||
|
|
||||||
|
Parsing_State :: enum {
|
||||||
|
Fresh_Ids;
|
||||||
|
Ingredient_Ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
Range :: struct {
|
||||||
|
min: int;
|
||||||
|
max: int;
|
||||||
|
}
|
||||||
|
|
||||||
|
range_contains :: (range: Range, id: int) -> bool {
|
||||||
|
return range.min <= id && id <= range.max;
|
||||||
|
}
|
||||||
|
|
||||||
|
main :: () {
|
||||||
|
content := read_entire_file("day5.input");
|
||||||
|
solve_first(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
solve_first :: (input: string) {
|
||||||
|
fresh_ids: [..]Range;
|
||||||
|
ingredients: [..]int;
|
||||||
|
parsing_state: Parsing_State;
|
||||||
|
for line: split(input, #char "\n") {
|
||||||
|
if line.count == 0 {
|
||||||
|
parsing_state = .Ingredient_Ids;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if parsing_state == .Fresh_Ids {
|
||||||
|
_, left, right := split_from_left(line, #char "-");
|
||||||
|
min := parse_int(*left);
|
||||||
|
max := parse_int(*right);
|
||||||
|
array_add(*fresh_ids, .{min=min, max=max});
|
||||||
|
} else if parsing_state == .Ingredient_Ids {
|
||||||
|
id := parse_int(*line);
|
||||||
|
array_add(*ingredients, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total_fresh := 0;
|
||||||
|
i: int;
|
||||||
|
while ingredient_loop := i < ingredients.count {
|
||||||
|
defer i += 1;
|
||||||
|
ingredient := ingredients[i];
|
||||||
|
for range: fresh_ids {
|
||||||
|
if range_contains(range, ingredient) {
|
||||||
|
total_fresh += 1;
|
||||||
|
continue ingredient_loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("%\n", total_fresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
#import "Basic";
|
||||||
|
#import "Hash_Table";
|
||||||
|
#import "File";
|
||||||
|
#import "String";
|
||||||
Reference in New Issue
Block a user