Skip to content

Instantly share code, notes, and snippets.

View vhxs's full-sized avatar
💻
coding or mathing

Vikram Saraph vhxs

💻
coding or mathing
View GitHub Profile
@vhxs
vhxs / draw_2d.py
Created November 5, 2022 21:01
Draw a 2-dimensional simplicial complex in matplotlib
# modified from this:
# https://github.com/iaciac/py-draw-simplicial-complex/blob/master/Draw%202d%20simplicial%20complex.ipynb
import networkx as nx
import itertools
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(10)
@vhxs
vhxs / standard_chromatic.py
Created November 6, 2022 19:35
better standard chromatic subdivisions
# modified from this:
# https://github.com/iaciac/py-draw-simplicial-complex/blob/master/Draw%202d%20simplicial%20complex.ipynb
from copy import copy
import networkx as nx
import itertools
import matplotlib.pyplot as plt
import numpy as np
@vhxs
vhxs / heat_equation.py
Created November 6, 2022 20:05
Visualizing the heat equation
# I wrote this sometime in 2007 or 2008 so please be forgiving
# of younger me and his terrible code
from vpython import *
from time import sleep
from copy import deepcopy
class Heat2D:
def __init__(self, inittemp, k, max = 255):
self.prevtemp = deepcopy(inittemp)
self.k = k
@vhxs
vhxs / heartbeat_every_1s.py
Last active November 7, 2022 23:15
minimal pmtr test
import time
fout = open("test_1.txt", "w")
i = 0
while True:
fout.write(f"heartbeat {i}\n")
fout.flush()
i += 1
time.sleep(1)
@vhxs
vhxs / type-inference.arr
Last active November 30, 2022 03:13
Hindley-Milner type inference
# Hindley-Milner type inference in Pyret
# needs fixing, Pyret's syntax has changed substantially since 2013
# this was written in a functional language.
# can I take this and turn it into Haskell?
#lang pyret/whalesong
data Expr:
| idE(name :: String)
@vhxs
vhxs / fac.hs
Created December 1, 2022 02:48
baby's first Haskell program
-- Factorial recursively defined in Haskell
fac n = if n == 0 then 1 else n * fac (n-1)
main = print (fac 5)
@vhxs
vhxs / readlines.hs
Created December 1, 2022 23:08
Read line by line in Haskell
main = do
content <- readFile "input.txt"
mapM_ putStrLn (lines content)
@vhxs
vhxs / sum_ints.hs
Created December 2, 2022 02:12
Sum a list of integers represented as strings
sum_list [] = 0
sum_list (elt:elts) = (read elt :: Integer) + sum_list elts
@vhxs
vhxs / sexpr-parse.hs
Created December 3, 2022 17:45
Basic S-expression parsing in Haskell
-- sexpr parsing in Haskell
import Data.SCargot
import Data.SCargot.Language.Basic
import Data.Text
main = do
print (decode basicParser (pack "(- (+ 1 2) 3)"))
@vhxs
vhxs / parsing_example.hs
Created December 6, 2022 00:49
Parsing in Haskell
amount line = read (splitOn "from" ((splitOn "move" line)!!1)!!0) :: Int
src line = read (splitOn "to" ((splitOn "from" line)!!1)!!0) :: Int
dst line = read (splitOn "to" ((splitOn "from" line)!!1)!!1) :: Int