Skip to content

Instantly share code, notes, and snippets.

View buvinghausen's full-sized avatar
💭
In the bunker for a while got a lot do to before EoY

Brian Buvinghausen buvinghausen

💭
In the bunker for a while got a lot do to before EoY
View GitHub Profile
using System.Linq;
int digitDegree(int n)
{
var str = n.ToString();
var i = 0;
for (; str.Length > 1; i++)
{
str = str.Sum(c => int.Parse(c.ToString())).ToString();
}
using System;
bool bishopAndPawn(string bishop, string pawn) =>
Math.Abs(bishop[0] - pawn[0]) == Math.Abs(bishop[1] - pawn[1]);
using System;
using System.Linq;
bool isBeautifulString(string inputString)
{
var list = Enumerable.Range(Convert.ToInt32('a'), 26).Select(i => inputString.Count(c => c == i)).ToList();
return list.SequenceEqual(list.OrderByDescending(i => i));
}
using System.Linq;
int[][] minesweeper(bool[][] matrix) =>
matrix.Select((row, i) => row.Select((_, j) =>
matrix.Skip(i - 1).Take(i == 0 ? 2 : 3)
.SelectMany(r => r.Skip(j - 1).Take(j == 0 ? 2 : 3)).Count(m => m) -
(matrix[i][j] ? 1 : 0)).ToArray()).ToArray();
@buvinghausen
buvinghausen / FizzBuzz.cs
Created November 19, 2020 15:30
FizzBuzz using C# pattern matching, value tuples, and a switch expression
using System;
using System.Collections.Generic;
using System.Linq;
static List<string> FizzBuzz(int count) => Enumerable
.Range(1, count)
.Select(i => (i % 3 == 0, i % 5 == 0) switch
{
(true, false) => "Fizz",
(false, true) => "Buzz",