Skip to content

Instantly share code, notes, and snippets.

@royvanrijn
Last active December 25, 2022 08:43
Show Gist options
  • Save royvanrijn/56857b5a5045d55612f49aab597ed782 to your computer and use it in GitHub Desktop.
Save royvanrijn/56857b5a5045d55612f49aab597ed782 to your computer and use it in GitHub Desktop.
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class Day25 {
public static void main(String[] args) throws Exception {
new Day25().calculate();
}
public void calculate() throws Exception {
List<String> lines = Files.readAllLines(Path.of("day25.txt"));
// Parse the input and sum:
long sum = lines.stream().mapToLong(s-> {
long r = 0;
for(int i = 0; i < s.length(); i++) {
int x = "=-012".indexOf(s.substring(s.length()-1-i, s.length()-i))-2;
r += (x*Math.pow(5,(i)));
}
return r;
}).sum();
// Integer to SNAFU:
String result = "";
while(sum>0) {
result = "012=-".charAt((int)(sum%5))+result;
sum -= (((sum+2)%5)-2);
sum/=5;
}
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment