Skip to content

Instantly share code, notes, and snippets.

View s5bug's full-sized avatar
📦
I have become an NPM package.

Aly Cerruti s5bug

📦
I have become an NPM package.
View GitHub Profile
@s5bug
s5bug / 01a.md
Last active December 2, 2023 06:17
Advent of Code solved in Hex Casting
View 01a.md

Accepts input as a list of UTF-32 codepoints and returns a Number.

High-Level

let isNewline: Number -> Boolean =
  (x: Number) -> x == 10

let isDigit: Number -> Boolean =
  (x: Number) -> (x >= 48) && (x < 58)
@s5bug
s5bug / kh2vm_notes.txt
Last active December 26, 2023 04:14
Kingdom Hearts 2 AI VM Language notes
View kh2vm_notes.txt
???? ???? ???? 0000:
[TODO: document special cases related to Xemnas]
???? ???? ??0? 0000:
???? ???? ??00 0000 iiii iiii iiii iiii iiii iiii iiii iiii:
load immediate INT
push to TP
???? ???? ??01 0000 ffff ffff ffff ffff ffff ffff ffff ffff:
load immediate FLOAT
push to TP
iiii iiii ii1m 0000 oooo oooo oooo oooo:
@s5bug
s5bug / note.md
Created September 9, 2023 10:26
Inclusive Volume Spell (HexCasting)
View note.md

High-level Immutable Algorithm

val volumeWithin: (Vec3, Vec3) -> List[Vec3] = (a: Vec3, b: Vec3) -> {
  val Vec3(ax, ay, az) = a
  val Vec3(bx, by, bz) = b
  
  val (minX, maxX) =
    if(ax <= bx) (ax, bx)
    else (bx, ax)
@s5bug
s5bug / 0_initial_brainstorming.md
Last active February 14, 2024 17:07
Hex Casting compiler ideas
View 0_initial_brainstorming.md

Basic Control Flow

Given an arbitrary program:

@main def lcm(a: Int, b: Int): Int =
  if(a < b) (a * (b / gcd(b, a))
  else (b * (a / gcd(a, b))

def gcd(a: Int, b: Int): Int =
  if(b == 0) a
@s5bug
s5bug / 1-fluffy.scala
Last active October 10, 2022 03:34
20 intermediate exercises: Scala edition
View 1-fluffy.scala
// show Fluffy instances
trait Fluffy[F[_]] {
def furry[A, B](fa: F[A])(f: A => B): F[B]
}
// Exercise 1
// Relative Difficulty: 1
implicit def fluffyList: Fluffy[List] = new Fluffy[List] {}
// Exercise 2
@s5bug
s5bug / worksheet.scala
Last active September 9, 2022 02:28
Monads are Monoids in the category of Endofunctors: Scala 3
View worksheet.scala
// Author: Aly Cerruti
// Please follow along in Scastie, so you can see the output of statements:
// https://scastie.scala-lang.org/CLmK5tLuRd6rxXuEnba0rQ
// A Category
trait Category[
// A collection of objects
Obj <: AnyKind,
// A constraint on those objects (Scala lacks dependent typing, so i.e. `Val = [A] =>> Monoid[A]` makes the category of Monoids)
Val[_ <: Obj],
@s5bug
s5bug / hw14_2.scala
Created December 12, 2020 07:15
Scala program for my CS 113 class that generates tracing for QuickSort in HW #14
View hw14_2.scala
import cats._, cats.data._, cats.syntax.all._
import scala.annotation.tailrec
object Main2 {
sealed trait Trace {
def show: String
}
object Trace {
implicit val showTrace: Show[Trace] = Show.show(_.show)
@s5bug
s5bug / hw14.scala
Created December 12, 2020 05:54
Scala program for my CS 113 class that generates LaTeX code for the Heapify problems in HW #14
View hw14.scala
import cats._, cats.data._, cats.syntax.all._
import scala.annotation.tailrec
object Main {
case class Snapshot(comparisons: Int, exchanges: Int, tikz: String)
def main(args: Array[String]): Unit = {
val vector: Vector[Int] = Vector(55, 50, 10, 40, 80, 90, 60, 100, 70, 80, 20, 50, 22)
val (snapshots, _, ()) = heapify[Int].runEmpty(vector).value
@s5bug
s5bug / 1-README.md
Last active August 20, 2020 23:41
Making Everest mods in FSharp
View 1-README.md

Making Everest mods in FSharp

Prerequesites:

  • Everest installed
  • Git
  • Visual Studio 2015 or newer with the .NET Framework 4.5.2 Targeting Pack

And either:

  • Visual Studio Code
  • Iodine for Visual Studio Code
@s5bug
s5bug / gcd.c
Last active July 11, 2020 01:59
C vs LLVM vs MCFASM
View gcd.c
int gcd(int x, int y) {
if(x == y) {
return x;
} else if(x < y) {
return gcd(x, y - x);
} else {
return gcd(x - y, y);
}
}