Skip to content

Instantly share code, notes, and snippets.

View threeifbywhiskey's full-sized avatar

Dorien Snake threeifbywhiskey

View GitHub Profile
@threeifbywhiskey
threeifbywhiskey / monty_hall.rb
Created August 18, 2014 03:37
Monty Hall Problem simulation
def monty_hall
doors = ['goat', 'stupid goat', 'car']
doors.delete choice = doors.sample
doors.delete reveal = doors.grep(/goat/).sample
puts 'Stay or switch?' until %w[stay switch].include? action = gets.chomp
choice = doors.last if action == 'switch'
@threeifbywhiskey
threeifbywhiskey / brainfuck.asm
Created August 9, 2014 00:43
This is a brainfuck interpreter written in a pseudo-assembly language which maps onto Whitespace's instructions.
; brainfuck interpreter in Whitespace assembly
; To facilitate the interpretation of "literate" brainfuck, consecutive newlines
; are used to signal the end of program input. Thus, the previous character must
; be remembered. Also, non-brainfuck characters must be passed over silenty. The
; heap is used for these processes to avoid having to juggle the stack too much.
push ,
push .
push <
push >
@threeifbywhiskey
threeifbywhiskey / braille.c
Created August 1, 2014 20:01
This is an interpreter for the Braille esolang: http://esolangs.org/wiki/Braille
#include <stdio.h>
#include <stdlib.h>
unsigned char convert(unsigned char c)
{
return (c & 0x40) << 1
| (c & 0x07) << 4
| (c & 0x80) >> 4
| (c & 0x38) >> 3;
}
@threeifbywhiskey
threeifbywhiskey / com.aor.droidedit.pro_preferences.xml
Created March 26, 2014 01:38
Solarized color scheme for DroidEdit (Pro).
<map>
<boolean name="lineWrap" value="true"/>
<boolean name="alternativeActionBar" value="true"/>
<boolean name="actionBar" value="true"/>
<boolean name="rootMode" value="false"/>
<string name="theme.0.background">#ff002b36</string>
<boolean name="actionBarTabs" value="true"/>
<string name="theme.0.type">#ffb58900</string>
<boolean name="bugsense" value="true"/>
<string name="lineBreak">linux</string>
@threeifbywhiskey
threeifbywhiskey / odd_syntax_error.rb
Created March 20, 2014 09:02
Apparently to_proc'd lambdas can't be contained within arrays?
class Object
def >> _
_.send *self
end
end
['get', '/', &-> { ['haml', 'to_sym' >> 'index'] >> self }] >> self
module ReverseSend
def self.extended klass
klass.send(:define_method, '>>') do |obj|
obj.send *self
end
end
end
class String
extend ReverseSend
@threeifbywhiskey
threeifbywhiskey / rot13_church.rb
Created March 19, 2014 18:32
This is a Church-enabled script that prints the ROT-13 transformation of each line of standard input.
require 'church'
include Church, Church::Utils
$_ = JOIN[MAP[CHARS[$_], &ROT13], '']
@threeifbywhiskey
threeifbywhiskey / 154i_lambdas.rb
Created March 19, 2014 17:56
This is a solution to /r/dailyprogrammer's Intermediate challenge #154 written almost entirely with numbers and lambdas.
MAP = -> coll, &fn {
coll == [] ? [] : [fn[coll[0]]] + MAP[coll[1..-1], &fn]
}
SIZE = -> coll {
coll == [] || coll == '' ? 0 : 1 + SIZE[coll[1..-1]]
}
FILTER = -> coll, &fn {
coll == [] ? [] : (fn[coll[0]] ? [coll[0]] : []) + FILTER[coll[1..-1], &fn]
@threeifbywhiskey
threeifbywhiskey / 154i_church.rb
Created March 19, 2014 17:54
This is a solution to /r/dailyprogrammer's Intermediate challenge #154 written using the Church gem.
require 'church'
include Church
GORELLIAN = -> n, alphabet, words {
alphabet = MAP[CHARS[alphabet], &-> a { ORD[a] | 32 }]
EACH[SORT_BY[words, &-> w {MAP[CHARS[w],
&-> c { INDEX[alphabet, ORD[c] | 32] }] }], &PUTS]
}
@threeifbywhiskey
threeifbywhiskey / gorellian_alphabet_sort.c
Created March 19, 2014 08:21
This is a solution to /r/dailyprogrammer's Intermediate challenge #154, Gorellian Alphabet Sort.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXWORD 80
char alphabet[27];
int gorellian_strcmp(const void *va, const void *vb)
{
size_t i;