Skip to content

Instantly share code, notes, and snippets.

View buvinghausen's full-sized avatar

Brian Buvinghausen buvinghausen

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));
}
static 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()
@buvinghausen
buvinghausen / FizzBuzz.cs
Last active March 9, 2026 15:29
FizzBuzz using C# pattern matching, value tuples, and a switch expression
FizzBuzz(63).ForEach(Console.WriteLine);
return;
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",
(true, true) => "FizzBuzz",