This file contains hidden or 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
| sub get_operand { | |
| my $arg = shift; | |
| my $listref = @$arg; | |
| if (UNIVERSAL::isa($listref, 'ARRAY')) { | |
| my $x = @$listref; | |
| print length($x).join(",",$x) . "\n" | |
| # WTF? | |
| } |
This file contains hidden or 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
| #Play with dispatch ideas and guards in Python. | |
| class Guard: | |
| dispatch_table = [] | |
| @classmethod | |
| def register(cls, func, condition): | |
| cls.dispatch_table += [(func, condition)] |
This file contains hidden or 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
| # 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] | |
This file contains hidden or 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(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) -> |
NewerOlder