Author: Nicholas Prado <nmprado@nzen.ws>
Date: Sat Dec 4 06:35:57 UTC 2021
Parent: 6fb2517c1bbea803d153aaaff3919c933154fd5b
Log message:
feat 21 01.2 best of three
1: diff --git a/src/java/y2021/Exercise210102.java b/src/java/y2021/Exercise210102.java 2: new file mode 100644 3: index 0000000..6578c9c 4: --- /dev/null 5: +++ b/src/java/y2021/Exercise210102.java 6: @@ -0,0 +1,82 @@ 7: + 8: +import java.io.IOException; 9: +import java.nio.file.*; 10: +import java.util.*; 11: + 12: +public class Exercise210102 13: +{ 14: + 15: + public static void main( 16: + String args[] 17: + ) { 18: + final String here = "e210102.m "; 19: + if ( args.length < 1 ) 20: + { 21: + throw new RuntimeException( here +"add a filename argument" ); 22: + } 23: + String userSaysFile = args[ 0 ]; 24: + List<String> fileLines = new LinkedList<>(); 25: + try 26: + { 27: + Path where = Paths.get( userSaysFile ); 28: + fileLines = Files.readAllLines( where ); 29: + } 30: + catch ( IOException | InvalidPathException ie ) 31: + { 32: + System.err.println( here +"couldn't read file "+ userSaysFile +" because "+ ie ); 33: + return; 34: + } 35: + /* 36: + - interpretation of spec - 37: + */ 38: + Exercise210102.findDepth( fileLines ); 39: + } 40: + 41: + public static void findDepth( 42: + List<String> fileLines 43: + ) { 44: + int currentSum = 0, previousDepthSum = 0, previousDepth = 0, ancientDepth = 0, qualifiedDrops = 0; 45: + for ( String line : fileLines ) 46: + { 47: + if ( line.isEmpty() ) 48: + continue; 49: + int currDepth = Integer.parseInt( line ); 50: + currentSum = currDepth + previousDepth + ancientDepth; 51: + if ( ancientDepth != 0 && currentSum > previousDepthSum ) 52: + { qualifiedDrops += 1; System.out.print( "+" ); } 53: + System.out.println( "cs "+ currentSum +" ad"+ ancientDepth ); 54: + previousDepthSum = currentSum; 55: + ancientDepth = previousDepth; 56: + previousDepth = currDepth; 57: + } 58: + System.out.println( "\tanswer "+ qualifiedDrops ); 59: + } 60: + 61: +} 62: + 63: + 64: + 65: + 66: + 67: + 68: + 69: + 70: + 71: + 72: + 73: + 74: + 75: + 76: + 77: + 78: + 79: + 80: + 81: + 82: + 83: + 84: + 85: + 86: + 87: + 88: +