Skip to content

Instantly share code, notes, and snippets.

View pema99's full-sized avatar

Pema Malling pema99

View GitHub Profile
@pema99
pema99 / CompactFizzBuzz
Created April 15, 2015 19:55
Compact FizzBuzz
for (int i = 0; i < 100; i++)
Console.WriteLine((0 == i % 3 && 0 == i % 5) ? "FizzBuzz" : 0 == i % 3 ? "Fizz" : 0 == i % 5 ? "Buzz" : i.ToString());
public object CreateInstance(string Name, params object[] Args)
{
Type ToCreate = Type.GetType(Name);
var InnerTypeList = new List<Type>();
InnerTypeList.Add(typeof(CallSite));
InnerTypeList.Add(typeof(Type));
foreach (object Arg in Args)
{
InnerTypeList.Add(Arg.GetType());
public class ImplicitTest
{
public double Val { get; set; }
public ImplicitTest(double Val)
{
this.Val = Val;
}
public static implicit operator int(ImplicitTest d)
@pema99
pema99 / zombies.fsx
Last active September 5, 2019 16:38
//Problem:
//You have N zombies, you wish to find the strongest and weakest zombie in population
//The only way to compare 2 zombies is by directly comparing their strength with either > or <
//Zombie strength in this implementation is specified with an integer
//The problem must be solved with a maximum of 3n/2 comparisons or "fights" between 2 zombies
open System
//Find the highest power of 2 which is less then or equal to n
let highestPower2 n =
@pema99
pema99 / fsharp.kak
Created September 6, 2019 00:39
Bootleg F# language support for Kakoune, use at your own disgression
# http://fsharp.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.(fs|fsi|fsx|fsscript)$ %{
set-option buffer filetype fsharp
}
@pema99
pema99 / mergesort.fsx
Last active September 23, 2021 21:23
//pema99 - Merge sort implementation - 23/09/2021
let rec merge op l r =
match l, r with
| [], _ -> r
| _, [] -> l
| lh::lt, rh::rt ->
if op lh rh then lh :: merge op lt r
else rh :: merge op l rt
@pema99
pema99 / cursed_breakout_processing.pde
Created September 10, 2019 13:27
Cursed processing breakout clone
float a,b,c,d,f;int[] e;int q=20;int w=50;
void r(){e=new int[32];c=2;d=2;b=300;f=0;a=0;}
void setup(){size(400,400);r();}
void draw(){
background(0);
rect(f,380,w,18);
for(int x=0;x<8;x++)
for(int y=0;y<4;y++)
if(e[y*8+x]==0){
int s=x*w;int t=y*q;
@pema99
pema99 / LambdaCalc.fs
Created May 14, 2021 15:54
Lambda calculus parsing and reduction - Using my own parsing combinator lib
module LambdaCalc
open Combinator
open Common
open Util
// Lambda calc AST
type Expr =
| Id of string
| Abs of string * Expr
Shader "Unlit/ScreenVertPos"
{
Properties
{
[IntRange] _Width ("Texture Size (POT)", Range(0, 13)) = 7
}
SubShader
{
Pass
{
Shader "Unlit/Double Layer Fresnel"
{
Properties {}
SubShader {
Tags {
"RenderType"="Transparent" "Queue"="Transparent" "DisableBatching"="True" "IgnoreProjector" = "True"
}
GrabPass {}
Pass {
Name "FORWARD"