Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector.Unboxed as V
import System.CPUTime
import Text.Printf
time :: IO t -> IO t
time a = do
start <- getCPUTime
v <- a
end <- getCPUTime
module Main
import Data.Vect
toVec : List a -> (n : Nat ** Vect n a)
toVec [] = (_ ** [])
toVec (x::xs) with (toVec xs)
| (k ** v) = (S k ** x :: v)
myFun : Vect n1 Int -> Vect n2 Int -> LTE n1 n2 -> Int
myFun xs ys p = foldr (+) 0 xs
@thedeemon
thedeemon / path_int.d
Last active September 26, 2019 15:23
Toy quantum mechanics with path integrals
import std.complex, std.stdio, std.random, std.parallelism, std.math : hypot;
import std.getopt, std.datetime.stopwatch, std.array, std.algorithm : max, min, reduce;
import std.format, std.range : iota;
struct Wall { double y, x1, x2; } // x1 < x2
struct Point { double x, y; }
bool intersects(Point p1, Point p2, ref Wall wall) {
if (min(p1.y, p2.y) > wall.y) return false;
if (max(p1.y, p2.y) < wall.y) return false;
ILogger {
void log(string msg);
}
class BoringLogger : ILogger {
overrride void log(string msg) {...}
}
class ColorfulLogger : ILogger {
overrride void log(string msg) {...}
open Batteries
type point = { x : int; y : int }
let f from_y to_y from_x to_x =
let a = (from_y --^ to_y/2) |> Enum.map (fun y -> {x=from_x; y=y}) in
let b = (to_y/2 --^ to_y) |> Enum.map (fun y -> {x=to_x; y=y}) in
Enum.append a b |> Array.of_enum;;
let g from_y to_y from_x to_x =
let t = to_y/2 in
Array.init (to_y - from_y) (fun i -> let y = i + from_y in if y < t then {x=from_x; y=y} else {x=to_x;y=y});;
import std.stdio, std.algorithm, std.range, std.array, std.datetime.stopwatch;
struct Point { int x, y; }
auto f(int from_y, int to_y, int from_x, int to_x) {
return chain( iota(from_y, to_y/2).map!(y => Point(from_x, y)),
iota(to_y/2, to_y) .map!(y => Point(to_x, y)) ).array;
}
auto g(int from_y, int to_y, int from_x, int to_x) {
import qualified Data.ByteString.Lazy.Char8 as L8
import Network.HTTP.Client (defaultManagerSettings, newManager)
import Network.HTTP.Simple
import Network.HTTP.Client.TLS
import System.Directory
import qualified Data.Map as M
import Data.List (sortBy)
import Control.Monad
import Control.Applicative
import System.Environment
cap=134217728
arrSize=16385
next uni=8192
cap=8192
arrSize=129
next uni=64
cap=64
arrSize=9
next uni=8
n for 64 = 0
case ADD|RRR:
case ADD_RRR:
if (code[ip+1]==code[ip+2]) {
a.mov(eax, dword_ptr(edi, code[ip+3]*4));
a.add(dword_ptr(edi, code[ip+1]*4), eax);
} else {
a.mov(eax, dword_ptr(edi, code[ip+2]*4));
a.add(eax, dword_ptr(edi, code[ip+3]*4));
a.mov(dword_ptr(edi, code[ip+1]*4), eax);
}
#include "lvm2jit.h"
#include <stdio.h>
#include <vector>
LVM2jit::LVM2jit(int stacksize, int heapsize)
: fun(NULL)
{
frame = (int*)calloc(stacksize, 1);
heap = (BYTE*)calloc(heapsize, 1);
callstack = (context_t*)calloc(10000, sizeof(context_t));