for ^o: other do push(arr, *o);
}
-// This assumes that the elements are sorted in some fashion,
-// such that equal elements would be next to each other.
-unique :: (arr: ^[..] $T) {
- idx := 0;
- while i := 0; i < arr.count - 1 {
- defer i += 1;
-
- if idx != i {
- arr.data[idx] = arr.data[i];
- }
-
- if !(arr.data[i] == arr.data[i + 1]) {
- idx += 1;
- }
- }
-
- arr.data[idx] = arr.data[arr.count - 1];
- arr.count = idx + 1;
-}
-
fold_idx_elem :: (arr: [] $T, cmp: (T, T) -> bool) -> (i32, T) {
idx := 0;
}
}
+// This assumes that the elements are sorted in some fashion,
+// such that equal elements would be next to each other.
+unique :: (arr: ^[] $T) {
+ idx := 0;
+ while i := 0; i < arr.count - 1 {
+ defer i += 1;
+
+ if idx != i {
+ arr.data[idx] = arr.data[i];
+ }
+
+ if !(arr.data[i] == arr.data[i + 1]) {
+ idx += 1;
+ }
+ }
+
+ arr.data[idx] = arr.data[arr.count - 1];
+ arr.count = idx + 1;
+}
+
+
fold :: (arr: [] $T, init: $R, f: (T, R) -> R) -> R {
val := init;
for it: arr do val = f(it, val);
return p1.y - p2.y;
}
-apply_fold :: (dots: ^[..] Point, axis_name: str, axis_value: i32) {
+apply_fold :: (dots: ^[] Point, axis_name: str, axis_value: i32) {
for^ *dots do switch axis_name {
case "x" do if it.x > axis_value do it.x = 2 * axis_value - it.x;
case "y" do if it.y > axis_value do it.y = 2 * axis_value - it.y;
string.advance(^line, 1);
axis_value := cast(i32) conv.str_to_i64(line);
- apply_fold(^dots, axis_name, axis_value);
+ apply_fold(~~ ^dots, axis_name, axis_value);
if part_1_answer < 0 {
part_1_answer = dots.count;
}