Skip to content

Instantly share code, notes, and snippets.

View KelsonBall's full-sized avatar

Kelson Ball KelsonBall

View GitHub Profile
// assuming "Board" has a getTokenAt(row, column) function
// that returns "red", "blue", or null for each position
// and an isInBounds(row, column) function that returns
// true if row and column are valid, false if they are off the board
// returns number of players tokens that are connected in a direction
// (Board, string, int, int, int, int) -> int
function countConnectedInDirection(board, player, newTokenRow, newTokenColumn, directionX, directionY) {
var count = 1; // number connected, starts at 1 because of the new token
// scan "forward" in direction
@KelsonBall
KelsonBall / ConsoleApp1.csproj
Last active December 20, 2020 20:46
Curly Bracketn't Todos List API in C#
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
@KelsonBall
KelsonBall / main.rs
Last active December 30, 2019 05:04
words that are 💯
use std::fs::File;
use std::io::{BufReader, BufRead};
fn score(a : &String) -> i32 {
a.chars()
.map(|c| (c as i32) - ('a' as i32) + 1)
.sum::<i32>()
}
fn main() {
@KelsonBall
KelsonBall / Comparison.txt
Created November 30, 2018 03:40
Generic Raymarching Fragment Shader
OpenGL/Glsl result on left, simulated C# result on the right
https://media.discordapp.net/attachments/439873163497832449/517899042055782410/unknown.png
bool HasBit(int mask, int index)
{
return (mask & (1 << index)) != 0;
}
int SetBit(int mask, int index)
{
return mask | (1 << index);
}
using System;
// include prerelease nuget package 'System.Memory'
public static class CharSpanExtensions
{
public static DateTime ConsumeDateTime(this ReadOnlySpan<char> source, out ReadOnlySpan<char> remaining)
{
// date time parsing is a nightmare, so take the heap allocation hit and have DateTime.Parse do it
int i = 0;
while (i < source.Length)
@KelsonBall
KelsonBall / switch_case_example.cs
Last active April 29, 2018 19:21
examples of switch case statements
// a switch-case must be in a method
public int GetColorRank(String color)
{
switch (color)
{
case "green":
return 1;
case "blue":
return 2;
case "yellow":
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using SixLabors.Primitives;
using OpenTK.Graphics.OpenGL;
using Processing.OpenTk.Core.Extensions;
namespace Processing.OpenTk.Core.Textures
{
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using SixLabors.Primitives;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using static OpenTK.DisplayDevice;
using Processing.OpenTk.Core.Extensions;