Skip to content
Browse files

Answer Problem 29 in Common Lisp and Perl

  • Loading branch information...
1 parent bad69c6 commit 207ecd5c79166316fcd536d9a8f4088413d7791c @syohex committed Apr 10, 2012
Showing with 38 additions and 0 deletions.
  1. +13 −0 00029/p29.lisp
  2. +25 −0 00029/p29.pl
View
13 00029/p29.lisp
@@ -0,0 +1,13 @@
+(defun p29 (a-limit b-limit)
+ (length (remove-duplicates (powered-num a-limit b-limit))))
+
+(defun powered-num (a-limit b-limit)
+ (loop for a in (itoa 2 a-limit)
+ appending
+ (loop for b in (itoa 2 b-limit)
+ collect (expt a b))))
+
+(defun itoa (start end)
+ (loop for i from start to end collect i))
+
+(p29 100 100)
View
25 00029/p29.pl
@@ -0,0 +1,25 @@
+#!perl
+use strict;
+use warnings;
+
+use Math::BigInt;
+
+sub p29 {
+ my ($a_limit, $b_limit) = @_;
+
+ my %powered;
+ for my $a (2..$a_limit) {
+ my $big_a = Math::BigInt->new($a);
+ $big_a->bround(200);
+ for my $b (2..$b_limit) {
+ my $big_b = Math::BigInt->new($b);
+ $big_b->bround(200);
+ my $key = $big_a ** $big_b;
+ $powered{$key}++;
+ }
+ }
+
+ return scalar keys %powered;
+}
+
+printf "p29() = %d\n", p29(100, 100);

0 comments on commit 207ecd5

Please sign in to comment.
Something went wrong with that request. Please try again.