Skip to content

Instantly share code, notes, and snippets.

@msx80
Created December 2, 2022 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msx80/97bfcfd20cb4fb1fb8330f8a84e00dee to your computer and use it in GitHub Desktop.
Save msx80/97bfcfd20cb4fb1fb8330f8a84e00dee to your computer and use it in GitHub Desktop.
package esperimentini;
import java.nio.file.Files;
import java.nio.file.Path;
public class AOC2 {
public static String FIRST = "ABC";
public static String SECOND = "XYZ";
public static void main(String[] args) throws Exception {
var list = Files.readAllLines(Path.of("input2.txt"));
var tok = list
.stream()
.map(s -> s.split(" "))
.map(s -> new int[]{FIRST.indexOf(s[0]), SECOND.indexOf(s[1])})
.toList();
System.out.println(tok.stream().mapToLong(s -> score(s[0], s[1])).sum());
System.out.println(tok.stream().mapToLong(s -> score2(s[0], s[1])).sum());
}
private static long score2(int v1, int v2)
{
v2 = ( v2 == 1 ? v1 : (v2 == 0 ? v1+2 : v1+1) ) % 3;
int sc = v1 == v2 ? 3 : ( (v1+3 - v2)%3==2 ? 6 : 0);
return sc+ v2 + 1;
}
private static long score(int v1, int v2)
{
int sc = v1 == v2 ? 3 : ( (v1+3 - v2)%3==2 ? 6 : 0);
return sc+ v2 + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment