Skip to content

Instantly share code, notes, and snippets.

View GrahamCampbell's full-sized avatar
🇺🇦

Graham Campbell GrahamCampbell

🇺🇦
View GitHub Profile
import json
import sys
from urllib import request, error
class GP2Exception(Exception):
def __init__(self, *args):
if args:
self.message = args[0]
else:
@GrahamCampbell
GrahamCampbell / is-bin-dag.gp2
Created February 13, 2020 22:28
The Improved GP 2 Compiler
Main = (init; Reduce!; if flag then break)!; if flag then fail
Reduce = up!; try Delete else set_flag
Delete = {del0, del1, del1_d, del21, del21_d, del22, del22_d}
init(x: list)
[ (n1, x) | ]
=>
[ (n1(R), x) | ]
interface = {n1}
object Smooth {
type Prime = BigInt
type Exponent = Int
type Factorization = Map[Prime, Exponent]
case class Row(a: BigInt, b: BigInt, f: Factorization)
def sqrt(a : BigInt): BigInt = {
def next(n : BigInt, i : BigInt) : BigInt = (n + i/n) >> 1

Keybase proof

I hereby claim:

  • I am GrahamCampbell on github.
  • I am grahamcampbell (https://keybase.io/grahamcampbell) on keybase.
  • I have a public key whose fingerprint is 3B52 2130 5C5D D9FB 6ED0 C8B6 7C6F E1F0 226B 7A06

To claim this, I am signing this object:

package fsa
import state.State
sealed trait Alphabet
case object A extends Alphabet
case object B extends Alphabet
sealed trait FSAState
case object Q0 extends FSAState
package state
case class State[S, +A](run: S => (A, S)) {
def flatMap[AA >: A, B](f: AA => State[S, B]): State[S, B] =
State({ s0: S =>
val (a, s1) = run(s0)
f(a).run(s1)
})
def map[AA >: A, B](f: AA => B): State[S, B] =
package streams
import scala.annotation.tailrec
sealed trait Stream[+A] {
def fold[B](z: B)(f: (A, => B) => B): B = {
def inner(as: Stream[A]) = as match {
case Cons(h, t) => f(h(), t().fold(z)(f))
case _ => z
}