Added Java solutions from Anton
[ou-summer-of-code-2017.git] / anton / SummerOfCode / src / summerofcode / Day1.java
1 /*
2 * Day 1 parts 1 and 2
3 */
4 package summerofcode;
5
6 import java.io.FileReader;
7 import java.util.HashMap;
8 import java.util.Map;
9 import java.util.Scanner;
10
11 /**
12 *
13 * @author Anton Dil
14 */
15 public class Day1
16 {
17 private final static Map<String,Double> scores = new HashMap<>();
18
19 static
20 {
21 scores.put("Almaty", 2.0);
22 scores.put("Brorfelde", 0.9);
23 scores.put("Estacada", 0.4);
24 scores.put("Jayuya", 0.6);
25 scores.put("Karlukovo", 2.2);
26 scores.put("Morgantown", 2.9);
27 scores.put("Nordkapp", 1.5);
28 scores.put("Nullarbor", 2.2);
29 scores.put("Puente-Laguna-Garzonkuala-Penyu", 0.4);
30 scores.put("Uzupis", 0.9);
31 }
32
33 public static void main(String[] args) throws Exception
34 {
35 Scanner sc = new Scanner(new FileReader("01-holidays.txt"));
36
37 String id, loc, bestId = "";
38 double value, score;
39 double bestValue = 0;
40 int price, days;
41 int afford = 0;
42
43 while(sc.hasNext())
44 {
45 id = sc.next();
46 price = sc.nextInt();
47 loc = sc.next();
48 days = sc.nextInt();
49
50 if(scores.get(loc) != null)
51 {
52 score = scores.get(loc);
53 }
54 else
55 {
56 score = 1.0;
57 }
58
59 //only consider holidays we can afford
60 if(price <= 1200)
61 {
62 value = score * days/price;
63
64 System.out.printf("%s %d %s %d value %.5f %n", id, price, loc, days, value);
65 afford++;
66
67 if(value > bestValue)
68 {
69 bestValue = value;
70 bestId = id;
71 }
72 }
73 }
74
75 System.out.println("Affordable " + afford);
76 System.out.printf("Best value is id %s with value %f%n", bestId, bestValue);
77 }
78 }