This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module XOR | |
def ^ other | |
case other | |
when Fixnum | |
chars.map { |c| (c.ord ^ other).chr }.join | |
when String | |
chars.zip(other.chars.cycle).map { |a, b| (a.ord ^ b.ord).chr }.join | |
else | |
raise ArgumentError, "must be String or Fixnum" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Refinements | |
def self.included core | |
core.send :include, Refinements.const_get(core.to_s) | |
end | |
module String | |
def ^ other | |
chars.zip(other.chars.cycle).map { |a, b| (a.ord ^ b.ord).chr }.join | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
Enumerable.instance_methods.each do |meth| | |
define_method(meth) do |*args| | |
obj = args.pop | |
case pred = args.first | |
when Proc, Symbol | |
obj.send meth, *args.drop(1), &pred | |
else | |
obj.send meth, *args | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
class Thing | |
def to_s | |
case caller[0] | |
when /write/ then 'print' | |
else 'puts' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factorial = -> n { | |
n < 2 ? 1 : n * factorial[n - 1] | |
} | |
size = -> ary { | |
sz = 0 | |
(cut = -> { | |
sz += 1 | |
(ary = ary[1..-1]) == [] ? sz : cut[] | |
})[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIZE = -> coll { | |
coll == [] || coll == '' ? 0 : 1 + SIZE[coll[1..-1]] | |
} | |
MAP = -> coll, &fn { | |
coll == [] ? [] : [fn[coll[0]]] + MAP[coll[1..-1], &fn] | |
} | |
KEYS = -> hash { MAP[[*hash], &-> h { h[ 0] }] } | |
VALUES = -> hash { MAP[[*hash], &-> h { h[-1] }] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'church' | |
include Church | |
brainfuck = -> prog { | |
tape = [] | |
sz = SIZE[prog] | |
pc = bp = i = 0 | |
jumps, stack = {}, [] | |
(jumper = -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def >> obj | |
obj.send self | |
end | |
end | |
class Symbol | |
def >> obj | |
obj.send self | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} |
OlderNewer