Skip to content

Instantly share code, notes, and snippets.

use std::iter::Unfold;
use std::os::args;
fn next(arg : &mut (int, int)) -> Option<int> {
let (lo, hi) = *arg;
*arg = (hi, lo + hi);
Some(lo)
}
fn main() {
,[>+>+<<-] input digit and copy it into A(2) and A(3)
>>
[>,----------] input rest of line subtracting 10 from each character to check for EOL
++++++++++<[++++++++++<] re add the 10s
Note that this also adds 10s to the two copies of the digit and sets the location to the beginning of the tape
>---------------------------------------------------------- subtract 58 from the first copy of the digit so it is its number now
>----------< subtract 10 from the other copy of the digit so it is what it should be then go back to the first digit where the fun happens
[>[.>]<[<]>-] print the string then decrement the number until the number reaches zero
@Taneb
Taneb / Q.hs
Created February 27, 2015 22:10
A quine in Haskell
module Main where
a, b :: String
a = "module Main where\n\na, b :: String\na = \""
b = "\"\n\nexpand :: Char -> String\nexpand '\\n' = \"\\\\n\"\nexpand '\"' = \"\\\\\\\"\"\nexpand '\\\\' = \"\\\\\\\\\"\nexpand c = [c]\n\nmain :: IO ()\nmain = do\n putStr a\n putStr $ a >>= expand\n putStr \"\\\"\\nb = \\\"\"\n putStr $ b >>= expand\n putStr b\n"
expand :: Char -> String
expand '\n' = "\\n"
expand '"' = "\\\""
expand '\\' = "\\\\"
module Nat where
newtype Nat = Nat [Nat] deriving (Show, Eq)
double :: Nat -> Nat
double (Nat []) = Nat []
double (Nat (a : as)) = Nat (succ a : as)
half :: Nat -> Nat
half (Nat []) = Nat []
import Graphics.Element exposing (Element)
import Graphics.Collage exposing (collage, toForm, text)
import Signal exposing ((<~))
import Time exposing (Time, every)
import Date exposing (fromTime, hour, minute, second)
import String exposing (padLeft)
import Text exposing (Text, fromString, monospace, height)
import List exposing (map)
main = showTime <~ every Time.second
@Taneb
Taneb / primes.rs
Created September 7, 2015 11:35
Sieve of Eratosthenes in Rust
pub fn main() {
let limit = 1000000;
let mut sieve = Vec::with_capacity(limit-2);
for _ in (2..limit) {
sieve.push(true);
}
for ix in(0..limit-2) {
if sieve[ix] {
println!("{}", ix + 2);
SPECIFICATIONS FOR DCPU/THRUSTER INTERFACE DRAFT 0.01
Name: UTI0001 - Universal Thruster Interface
ID: BFEC9661, verson: 0x0001
Manufacture: 0 (n/a)
0: NO_OF_SPEEDS
Writes the number of available speeds to the C register.
1: SET_SPEED
Reads the B register, and attempts to set the thruster to the specified
@Taneb
Taneb / sirpent.rs
Created June 5, 2016 13:39
Proof of concept for Rust implementation of sirpent
trait Vector {
type Direction;
fn distance(&self, other : &Self) -> Self;
fn neighbour(&self, direction : Self::Direction) -> Self;
}
trait Grid {
type Vector : Vector;
fn dimensions(&self) -> Vec<isize>;
theory PFDS
imports Main
begin
datatype 'a Tree = E | T "'a Tree" 'a "'a Tree"
primrec trmax :: "'a ⇒ 'a Tree ⇒ 'a" where
"trmax a E = a" |
"trmax _ (T _ here right) = trmax here right"
@Taneb
Taneb / Test.hs
Created September 8, 2016 17:50
isTreeOrdered causing headaches
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main where
import Data.Treap
import Test.QuickCheck
instance (Arbitrary h, Arbitrary t, Arbitrary a, Ord h, Ord t) => Arbitrary (Treap h t a) where
arbitrary = sized $ \n -> do
s <- choose (0, n)