File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 7
7
Put the ` input ` file in the same directory as the code then compile and run it, e.g.:
8
8
9
9
``` sh
10
- cd day01_part1
11
- zig run day01_part1 .zig
10
+ cd day01
11
+ zig run part1 .zig
12
12
```
Original file line number Diff line number Diff line change
1
+ const std = @import ("std" );
2
+
3
+ pub fn main () ! void {
4
+ var file = try std .fs .cwd ().openFile ("input" , .{});
5
+ defer file .close ();
6
+
7
+ var buf_reader = std .io .bufferedReader (file .reader ());
8
+ var in_stream = buf_reader .reader ();
9
+
10
+ var buf : [1024 ]u8 = undefined ;
11
+
12
+ const first = try in_stream .readUntilDelimiterOrEof (& buf , '\n ' );
13
+ var prev : u32 = try std .fmt .parseInt (u32 , first .? , 10 );
14
+
15
+ var inc : u32 = 0 ;
16
+ while (try in_stream .readUntilDelimiterOrEof (& buf , '\n ' )) | line | {
17
+ if (line .len > 0 ) {
18
+ var x : u32 = try std .fmt .parseInt (u32 , line , 10 );
19
+ if (x > prev ) {
20
+ inc += 1 ;
21
+ }
22
+ prev = x ;
23
+ }
24
+ }
25
+
26
+ const stdout = std .io .getStdOut ().writer ();
27
+ try stdout .print ("{d}\n " , .{inc });
28
+ }
You can’t perform that action at this time.
0 commit comments