#!/usr/bin/perl use warnings; use strict; use Test::More; sub f { my $n = shift; $n % 4 + 4 * int((15 - $n) / 4) } my @in = qw( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15); my @out = qw(12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3); for my $i (0 .. $#in) { is(f($in[$i]), $out[$i], "_$i"); } done_testing(0 + @in);
TDD FTW!
Update: Also notice that f(f($x)) == $x.
In reply to Re: More simple math.
by choroba
in thread More simple math.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |