some-advent-of-code: fd585b493fe2682416fceddf46f80b303901334e
1:
2: import java.io.IOException;
3: import java.nio.file.*;
4: import java.util.*;
5:
6: public class Exercise210101
7: {
8:
9: public static void main(
10: String args[]
11: ) {
12: final String here = "e210101.m ";
13: if ( args.length < 1 )
14: {
15: throw new RuntimeException( here +"add a filename argument" );
16: }
17: String userSaysFile = args[ 0 ];
18: List<String> fileLines = new LinkedList<>();
19: try
20: {
21: Path where = Paths.get( userSaysFile );
22: fileLines = Files.readAllLines( where );
23: }
24: catch ( IOException | InvalidPathException ie )
25: {
26: System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie );
27: return;
28: }
29: /*
30: - interpretation of spec -
31: */
32: Exercise210101.findDepth( fileLines );
33: }
34:
35: public static void findDepth(
36: List<String> fileLines
37: ) {
38: int previousDepth = Integer.MAX_VALUE, drops = 0;
39: for ( String line : fileLines )
40: {
41: if ( line.isEmpty() )
42: continue;
43: int currDepth = Integer.parseInt( line );
44: if ( currDepth > previousDepth )
45: drops += 1;
46: previousDepth = currDepth;
47: }
48: System.out.println( drops );
49: }
50:
51: }
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
Generated by git2html.