Skip to content

Instantly share code, notes, and snippets.

View otac0n's full-sized avatar

John Gietzen otac0n

View GitHub Profile
@otac0n
otac0n / HydraGame.cs
Last active April 18, 2024 19:21
Simple code to compute the values of the Hydra game from Numberphile.
// Reference here: https://www.youtube.com/watch?v=prURA1i8Qj4
var rightMost = true;
var step = BigInteger.Zero;
var initialDepth = 5;
// Represents a simple tree (single trunk). Length is tree depth. Root node is excluded. Value is count of leaf nodes (heads) at that depth.
// Nodes will always be added to the right of the implied connections.
// Set up Animations
var chain = new MarkovChain<string>(1);
chain.Add(new[] { "Sitting" }, "Sitting", 50);
chain.Add(new[] { "Sitting" }, "Grooming", 20);
chain.Add(new[] { "Sitting" }, "Sleeping", 20);
chain.Add(new[] { "Sitting" }, "Playing", 10);
chain.Add(new[] { "Playing" }, "Sitting", 100);
chain.Add(new[] { "Sleeping" }, "Sleeping", 60);
@otac0n
otac0n / prompt.txt
Created December 21, 2022 04:12
Embed ChatGPT in AR
You are now inhabiting my augmented reality headset. I may refer to you as "Computer" or "Headset" because of this.
I want you to help me control some software on my headset
From now on, I would like you to respond with code that contains your reponse, such as:
```
response = "I understand.";
```
If there is some some reason you want to issue a warning, you can first toggle the warning status with:
@otac0n
otac0n / SpecialRelativity.cs
Created November 9, 2022 08:24
Special Relativity
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Numerics.dll</Reference>
<Namespace>System.Drawing</Namespace>
<Namespace>System.Drawing.Drawing2D</Namespace>
<Namespace>System.Drawing.Text</Namespace>
<Namespace>System.Drawing.Imaging</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
</Query>
const int FrameRate = 30;
// Note: Much of the descriptions are from https://en.wikipedia.org/
void Main()
{
var sb = new StringBuilder();
sb.AppendLine("digraph classes {");
sb.AppendLine("node [shape=none width=0 height=0 margin=0];");
Func<Type, string> id = null;
id = FuncUtils.Memoize((Type type) =>
Oh Yeaheyay!
[The Mystic Crystal]
Long ago and far away
In labarynths of coral caves
A Mystic Crystal was forged in glass
With magic or some shit like that.
Its powers had been used for good
@otac0n
otac0n / MartingaleSimulation.linq
Last active August 6, 2021 08:23
Shows that the Martingale strategy has a 50% chance of doubling your money.
var rand = new Random();
bool Play(ref int bank, int bet)
{
var win = rand.Next(2) < 1;
checked
{
bank += win ? bet : -bet; // If you win, you gain your bet back AND the winnings. If you lose, you just lose your bet.
}
@otac0n
otac0n / VotingSystems.linq
Created October 2, 2020 06:17
Voting Systems
void Demo<T>(IEnumerable<IEnumerable<T>> ballots, int seats, IEqualityComparer<T> comparer = null)
{
var elections = new Dictionary<string, Tuple<IElection<T>, ITieBreak<T>[]>>
{
["STV"] = Tuple.Create<IElection<T>, ITieBreak<T>[]>(
new SingleTransferableVoteElection<T>(),
new ITieBreak<T>[]
{
new BordaCountTieBreak<T>(),
new ApprovalCountTieBreak<T>(),
@otac0n
otac0n / SexAndGender.linq
Last active November 10, 2023 18:42
A theory of sex and gender.
// My opinions are my own.
public class PseudobicerosHancockanus : Flatworm { }
public abstract class Flatworm : Animal
{
public Flatworm() : this(Sex.Male | Sex.Female) { }
public Flatworm(Sex sex) : base(sex) { }
}
void Main()
{
GetPassFailRateWithConfidence(10, 2, 0.95).ToString().Dump();
GetPassFailRateWithConfidence(100, 20, 0.95).ToString().Dump();
GetPassFailRateWithConfidence(1000, 200, 0.95).ToString().Dump();
GetPassFailRateWithConfidence(10000, 2000, 0.95).ToString().Dump();
}
public ErrorRate GetPassFailRateWithConfidence(long passes, long fails, double confidence)
{