Skip to content

Instantly share code, notes, and snippets.

View built's full-sized avatar

Matt Youell built

View GitHub Profile
sub get_operand {
my $arg = shift;
my $listref = @$arg;
if (UNIVERSAL::isa($listref, 'ARRAY')) {
my $x = @$listref;
print length($x).join(",",$x) . "\n"
# WTF?
}
#Play with dispatch ideas and guards in Python.
class Guard:
dispatch_table = []
@classmethod
def register(cls, func, condition):
cls.dispatch_table += [(func, condition)]
# One of several ways to do a ternary operation in Python
# For more discussion, see: http://drj11.wordpress.com/2007/05/25/iversons-convention-or-what-is-the-value-of-x-y/
# "AB"[True] => A, likewise "AB"[False] => B
# In this way you can index any two item list with a test:
card_type = ["Low", "High"]][card_value < 10]
@built
built / gist:42971
Created January 4, 2009 01:07 — forked from anonymous/gist:42949
Didn't like that I had to reassemble the Coins list. Took advantage of parametric temp variables (See Coins variable)
-module(change2).
-export([find_variations/2]).
-export([count_change/1]).
find_variations(0, _) -> 1; % No amount given.
find_variations(_, []) -> 0; % No coins given.
find_variations(Amount, _) % Amount is impossible.
when Amount < 0 -> 0;
find_variations(Amount, [Coin|Rest]=Coins) ->