summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-24 23:58:25 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-24 23:58:25 -0500
commita529ce696348a36e2251fdf4e040a7562c483154 (patch)
treea67f40cca0bbc01d3e8893d1244508bf5839fd01
parentd6966208224bb37ca532519a50849c686808582b (diff)
downloadrosalind-a529ce696348a36e2251fdf4e040a7562c483154.tar.gz
rosalind-a529ce696348a36e2251fdf4e040a7562c483154.zip
another solution
-rw-r--r--LEXF.pl20
1 files changed, 20 insertions, 0 deletions
diff --git a/LEXF.pl b/LEXF.pl
new file mode 100644
index 0000000..2c522da
--- /dev/null
+++ b/LEXF.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.016;
+
+my @string = split ' ', scalar(<>);
+chomp(my $length = <>);
+
+my $base = @string;
+
+for my $num (0..$base ** $length - 1) {
+ my @digits;
+ my $remainder = $num;
+ for my $digit (1..$length) {
+ my $exponent = $length - $digit;
+ push @digits, int($remainder / $base ** $exponent);
+ $remainder -= $digits[-1] * $base ** $exponent;
+ }
+ say join('', map { $string[$_] } @digits);
+}