in reply to help with algorithm
Think of this in terms of bits, 2 ** $x == 1 << $x. That allows you to decode with bitwise operations. Here's a simple method that uses a hash to translate between names and numbers.
by default, days() returns all the days of the week if no argument is given.our %daycode = ( Sunday => 1, Monday => 2, Tuesday => 4, Wednesday => 8, Thursday => 16, Friday => 32, Saturday => 64, ); our %codeday; @codeday{ values(%daycode)} = keys %daycode; sub days { my $mask = shift || 127; sort { $daycode($a} <=> $daycode{$b} } grep { $mask & $daycode{$_} } keys %daycode; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: help with algorithm
by Anonymous Monk on Nov 17, 2002 at 01:15 UTC | |
by sauoq (Abbot) on Nov 17, 2002 at 01:44 UTC | |
by Zaxo (Archbishop) on Nov 17, 2002 at 01:37 UTC |