day11_pt1.java (1129B)
1 import java.nio.file.Files; 2 import java.nio.file.Path; 3 import java.io.IOException; 4 import java.util.*; 5 import java.util.stream.*; 6 7 class day11_pt1 { 8 public static void main(String[] args) throws IOException { 9 var input = Files.readString(Path.of(args[0])).trim(); 10 var stones = new ArrayList<>(Arrays.asList(input.split(" "))); 11 System.out.println(stones); 12 for (var i=0;i<25;i++) { 13 for (var j=0; j<stones.size(); j++) { 14 var stone = stones.get(j); 15 if ("0".equals(stone)) { 16 stones.set(j, "1"); 17 } else if (stone.length() % 2 == 0) { 18 var s1 = stone.substring(0, stone.length()/2); 19 var s2 = "%d".formatted(Long.parseLong(stone.substring(stone.length() / 2))); 20 //System.out.printf("s1 [%s] s2 [%s]\n", s1, s2); 21 stones.set(j, s2); 22 stones.add(j, s1); 23 j++; // skip the newly inserted stone 24 } else { 25 stones.set(j, "%d".formatted(Long.parseLong(stone) * 2024)); 26 } 27 } 28 //System.out.println(stones); 29 } 30 var res = stones.size(); 31 System.out.printf("Day 11, pt1: %d\n", res); 32 } 33 }