in reply to Golf: Buying with exact change
Here are my two 48-character solutions:
|
$"="}|1{";$_=1x999;chop while/^(1{@_})*$/;length
$"="}|1{";(grep{(1x$_)!~/^(1{@_})*$/}1..999)[-1] |
And if it weren't for a bug I just found in alternations within negative lookaheads, I'm pretty sure this would be equivalent, giving me 46 characters:
| $"="}|1{";1x999=~/(1*?)(?!(1{@_})*$)/;length$' |
They all use basically the same idea, can you think of a different approach? As I mentioned in the original post, these work for all instances where (a) the solution is 999 or less, and also (b) the arguments are each less than 32k (because they are used in regex quantifiers).
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Golf: Buying with exact change
by dragonchild (Archbishop) on Feb 22, 2005 at 17:52 UTC | |
by blokhead (Monsignor) on Feb 22, 2005 at 18:16 UTC |