Skip to content

Instantly share code, notes, and snippets.

@Agnishom
Agnishom / main.rs
Created September 29, 2022 14:34
Paige-Tarjan
use std::collections::VecDeque;
use std::cell::RefCell;
use std::rc::Rc;
use std::cell::Ref;
pub mod vllsimple;
use vllsimple::*;
struct part_man{
// pools
@Agnishom
Agnishom / hopcroft.rs
Created September 13, 2022 02:47
Hopcroft's Algorithm
use std::collections::VecDeque;
// compute the inverse relation given a function
fn inverse_fn(n: usize, f: &Vec<usize>) -> Vec<Vec<usize>> {
let mut inverse_f = vec![vec![]; n];
for i in 0..n {
inverse_f[f[i]].push(i);
}
inverse_f
}
@Agnishom
Agnishom / main.c
Created January 12, 2022 15:54
Copilot example code
#include <stdio.h>
#include "heater.c"
uint8_t temperature;
int main(){
for (int i = 0; i < 200; i++){
temperature = i;
step();
@Agnishom
Agnishom / Board.hs
Created November 7, 2021 14:21
Haskell Tic Tac Toe with CLI and Gloss GUI
module Board where
import Data.Map (Map, (!))
import qualified Data.Map as Map
import Data.List (intercalate)
data Player = X | O
deriving (Eq, Ord, Show)
newtype Board = Board (Map (Int, Int) (Maybe Player))
@Agnishom
Agnishom / IntList.java
Created November 4, 2021 18:45
Visitor Pattern
/** The functional list type defined by IntList := EmptyIntList + ConsIntList(int, IntList) */
abstract class IntList {
/** Visitor hook */
abstract public Object visit(IntListVisitor iv);
/** Adds i to the front of this. */
public ConsIntList cons(int i) { return new ConsIntList(i, this); }
/** Returns the unique empty list. */
public static EmptyIntList empty() { return EmptyIntList.ONLY; }
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
module Regex.Glushkov where
import Control.Monad.State
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.Text as T
import qualified Data.ByteString.Lazy as BSL
@Agnishom
Agnishom / test.rs
Created May 26, 2021 15:17
Composable Transductions
use std::marker::PhantomData;
pub trait Sink<A> {
fn init(&mut self);
fn next(&mut self, item: A);
fn end(&mut self);
}
pub trait Query<A,B>: {
fn init(&mut self, sink: &mut dyn Sink<B>);
@Agnishom
Agnishom / monoid_recognizers.lean
Last active January 14, 2020 13:39
Lean Automata
import data.fintype
structure dfa (alphabet : Type) [fintype alphabet] :=
(qq : Type) {is_finite : fintype qq} {has_decidable_eq : decidable_eq qq}
(δ : qq → alphabet → qq)
(init : qq)
(fin : qq → bool)
def language (alphabet : Type) [fintype alphabet] := list alphabet → bool
@Agnishom
Agnishom / keybase.md
Created September 6, 2019 04:17
Keybase

Keybase proof

I hereby claim:

  • I am agnishom on github.
  • I am agnishom (https://keybase.io/agnishom) on keybase.
  • I have a public key ASBEfGCEQw4cY-VOkwSiHBWosC_4pM60jwJi5AufQzgF2wo

To claim this, I am signing this object:

@Agnishom
Agnishom / multiplication.hs
Created August 10, 2019 02:39
When is Karatsuba faster?
import Data.List
{-
We are assumming the multiplication is happening in decimal digits. Here is the yardstick with which we are measuring the number of operations
1. Every single digit multiplication is 1 step
2. Adding two n-digit numbers is n steps.
Adding an m-digit and an n-digit number takes max(m, n) steps.
Adding two n-digit numbers produce an (n+1)-digit number.