Skip to content

Instantly share code, notes, and snippets.

@htoma
Last active August 7, 2018 21:26
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 htoma/fcd05739cf95379183bbea192bb10f39 to your computer and use it in GitHub Desktop.
Save htoma/fcd05739cf95379183bbea192bb10f39 to your computer and use it in GitHub Desktop.
public static List<string> Anagrams()
{
var star = string.Join("", "star".OrderBy(l => l));
return "parts,traps,arts,rats,starts,tarts,rat,art,tar,tars,stars,stray"
.Split(',')
.Where(w => w.Length == star.Length && string.Join("", w.OrderBy(l => l)).Contains(star)).ToList();
}
public static List<string> ChristmasDayOfTheWeek()
{
var start = new DateTime(2018, 12, 25);
return Enumerable.Range(0, 8)
.Select(y => start.AddYears(y))
.Select(d => d.DayOfWeek.ToString()).ToList();
}
public static List<string> FullHouseHands()
{
var hands = "4♣ 5♦ 6♦ 7♠ 10♥;10♣ Q♥ 10♠ Q♠ 10♦;6♣ 6♥ 6♠ A♠ 6♦;2♣ 3♥ 3♠ 2♠ 2♦;2♣ 3♣ 4♣ 5♠ 6♠"
.Split(';');
var indexes = hands
.Select((h, index) => (index: index,
hand: h.Split(new[] {' ', '♣', '♦', '♠', '♥'}, StringSplitOptions.RemoveEmptyEntries)))
.Select(t => (index: t.index, groups: t.hand.GroupBy(y => y)))
.Where(t => t.groups.Count() == 2 && t.groups.First().Count() == 3)
.Select(t => t.index);
return indexes.Select(i => hands[i]).ToList();
}
public static int LongestSequenceOfZeroes()
{
return "1,2,1,1,0,3,1,0,0,2,4,1,0,0,0,0,2,1,0,3,1,0,0,0,6,1,3,0,0,0"
.Split(',')
.Aggregate((l: 0, m: 0),
(t, s) => s == "0"
? (t.l + 1, Math.Max(t.l + 1, t.m))
: (0, t.m)).m;
}
public static List<(string, List<string>)> SharedInitials()
{
var players =
"Santi Cazorla, Per Mertesacker, Alan Smith, Thierry Henry, Alex Song, Paul Merson, Alexis Sánchez, Robert Pires, Dennis Bergkamp, Sol Campbell"
.Split(new[] {", "}, StringSplitOptions.RemoveEmptyEntries);
return players
.Select(p => (name: p, initials: string.Join("", p.Where(c => c >= 'A' && c <= 'Z').OrderBy(c => c))))
.GroupBy(t => t.initials)
.Select(t => (initials: t.Key, names: t.Select(x => x.name).ToList())).ToList();
}
public static string VideoEditing()
{
var cuts = ("0:00:00-0:00:05;0:55:12-1:05:02;1:37:47-1:37:51" + "-2:00:00")
.Split(new[] {'-', ';'}, StringSplitOptions.RemoveEmptyEntries);
return string.Join(";", Enumerable.Range(0, cuts.Length / 2)
.Select(i => $"{cuts[i * 2 + 1]}-{cuts[(i + 1) * 2]}"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment