Skip to content

Instantly share code, notes, and snippets.

@viceroypenguin
Last active July 13, 2018 19:23
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 viceroypenguin/1da0ee5166dbdf0d2dd2794b36587942 to your computer and use it in GitHub Desktop.
Save viceroypenguin/1da0ee5166dbdf0d2dd2794b36587942 to your computer and use it in GitHub Desktop.
"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(',')
.Select(x => Convert.ToInt32(x))
.Segment((cur, prev, idx) => cur != prev)
.Where(x => x.First() == 0)
.Select(x => x.Count())
.Max()
"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(';')
.Select(x => x
.Split(' ')
.GroupBy(
y => y[0],
(k, y) => new { Number = k, Count = y.Count(), })
.OrderBy(y => y.Count)
.ToList())
.Where(x =>
x.Count == 2 &&
x[0].Count == 2 &&
x[1].Count == 3)
Enumerable.Range(DateTime.Today.Year, 10)
.Select(y => new DateTime(y, 12, 25))
.Select(y => y.DayOfWeek)
"parts,traps,arts,rats,starts,tarts,rat,art,tar,tars,stars,stray"
.Split(',')
.Where(x => x.Length == 4)
.Select(x => new { x, arr = x.OrderBy(c => c).ToArray(), })
.Where(x => x.arr[0] == 'a' && x.arr[1] == 'r' && x.arr[2] == 's' && x.arr[3] == 't')
.Select(x => x.x)
"Santi Cazorla, Per Mertesacker, Alan Smith, Thierry Henry, Alex Song, Paul Merson, Alexis Sánchez, Robert Pires, Dennis Bergkamp, Sol Campbell"
.Split(',')
.Select(x => x.Trim())
.Select(x => new
{
x,
Initials = x
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(y => y[0])
.ToArray(),
})
.GroupBy(x => (x.Initials[0], x.Initials[1]))
.Where(x => x.Count() > 1)
.SelectMany(x => x)
.Select(x => x.x)
Enumerable.Range(0, (int)TimeSpan.FromHours(2).TotalSeconds + 1)
.Except(
"0:00:00-0:00:05;0:55:12-1:05:02;1:37:47-1:37:51"
.Split(';')
.Select(x => x.Split('-')
.Select(y => TimeSpan.Parse(y))
.Select(y => (int)y.TotalSeconds)
.ToArray())
// +1 here if exclusion times are closed sets (generally true); Can remove to match answer on website.
.SelectMany(x => Enumerable.Range(x[0], x[1] - x[0] + 1)))
.Segment((cur, prev, idx) => cur != prev + 1)
.Select(x => new[] { TimeSpan.FromSeconds(x.First()), TimeSpan.FromSeconds(x.Last()), })
.Select(x => $"{x[0]}-{x[1]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment