Skip to content

Instantly share code, notes, and snippets.

@aloisdg
Last active December 3, 2022 11:47
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 aloisdg/839b972d7dade03c7fd910157001eb1e to your computer and use it in GitHub Desktop.
Save aloisdg/839b972d7dade03c7fd910157001eb1e to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
public class Program
{
public static (string, string) Half(string s) => (s[..(s.Length / 2)], s[(s.Length / 2)..]);
public static int Prioritize(char c) => c - (char.IsLower(c) ? 'a' : ('A' - 26)) + 1;
public static void Main()
{
@"vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"
.Split('\n')
.Select(Half)
.Select(t => t.Item1.Intersect(t.Item2).First())
.Sum(Prioritize)
.Dump();
}
}
using System;
using System.Linq;
public class Program
{
public static int Prioritize(char c) => c - (char.IsLower(c) ? 'a' : ('A' - 26)) + 1;
public static void Main()
{
@"vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"
.Split('\n')
.Chunk(3)
.SelectMany(a => a[0].Intersect(a[1]).Intersect(a[2]))
.Sum(Prioritize)
.Dump();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment