Last active
December 2, 2022 10:55
-
-
Save aloisdg/7ba22a053d27e029e3e80be5c1bad446 to your computer and use it in GitHub Desktop.
Advent_2022_2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var s = @"A Y | |
B X | |
C Z"; | |
Console.WriteLine(s.Split("\n").Sum(Score)); | |
} | |
static int Score(string input) => input switch | |
{ | |
("A Y") => 2 + 6, | |
("B Y") => 2 + 3, | |
("C Y") => 2 + 0, | |
("A X") => 1 + 3, | |
("B X") => 1 + 0, | |
("C X") => 1 + 6, | |
("A Z") => 3 + 0, | |
("B Z") => 3 + 6, | |
("C Z") => 3 + 3, | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s = """A Y | |
B X | |
C Z""" | |
let score x = | |
match x with | |
| "A Y" -> 2 + 6 | |
| "B Y" -> 2 + 3 | |
| "C Y" -> 2 + 0 | |
| "A X" -> 1 + 3 | |
| "B X" -> 1 + 0 | |
| "C X" -> 1 + 6 | |
| "A Z" -> 3 + 0 | |
| "B Z" -> 3 + 6 | |
| "C Z" -> 3 + 3 | |
| _ -> 0 | |
s.Split "\n" | |
|> Array.sumBy score | |
|> printfn "%i" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var s = @"A Y | |
B X | |
C Z"; | |
Console.WriteLine(s.Split("\n").Sum(Score)); | |
} | |
static int Score(string input) => input switch | |
{ | |
("A Y") => 1 + 3, // ok | |
("B Y") => 2 + 3, | |
("C Y") => 3 + 3, | |
("A X") => 3 + 0, | |
("B X") => 1 + 0, // ok | |
("C X") => 2 + 0, | |
("A Z") => 2 + 6, | |
("B Z") => 3 + 6, | |
("C Z") => 1 + 6, // ok | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s = """A Y | |
B X | |
C Z""" | |
let score x = | |
match x with | |
| "A Y" -> 1 + 3 | |
| "B Y" -> 2 + 3 | |
| "C Y" -> 3 + 3 | |
| "A X" -> 3 + 0 | |
| "B X" -> 1 + 0 | |
| "C X" -> 2 + 0 | |
| "A Z" -> 2 + 6 | |
| "B Z" -> 3 + 6 | |
| "C Z" -> 1 + 6 | |
| _ -> 0 | |
s.Split "\n" | |
|> Array.sumBy score | |
|> printfn "%i" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative with an array: