Commits

Shlomi Fish committed 98422b2

Remove all trailing space.

  • Participants
  • Parent commits 2e3fdc0

Comments (0)

Files changed (144)

File project-euler/1.lisp

 
 (defun display-result ()
   (format t "Total is ~A~%" (sum1 (1- 1000))))
-          
-
-

File project-euler/10/10-zerothorder.hs

         -- only check divisibility of the numbers less than the square root of n
         isPrime n = all (not . divides n) $ takeWhile (\p -> p*p <= n) primes
         divides n p = n `mod` p == 0
- 
+
 result = sum $ takeWhile (< 2000000) primes
- 
+
 main = do putStrLn( show result )
 
 

File project-euler/10/10.c

-/*
- * =====================================================================================
- *
- *       Filename:  10.c
- *
- *    Description:  
- *
- *        Version:  1.0
- *        Created:  28/11/09 14:08:11
- *       Revision:  none
- *       Compiler:  gcc
- *
- *         Author:  YOUR NAME (), 
- *        Company:  
- *
- * =====================================================================================
- */
-
 #include <string.h>
 #include <math.h>
 #include <stdint.h>
 
     memset(bitmask, '\0', sizeof(bitmask));
     mark_limit = (int)sqrt(limit);
-    
+
     for (p=2 ; p <= mark_limit ; p++)
     {
         if (! ( bitmask[p>>3]&(1 << (p&(8-1))) ) )

File project-euler/10/10.hs

 primes :: Integer -> [Integer]
 
 primes how_much = sieve [2..how_much] where
-         sieve (p:x) = 
+         sieve (p:x) =
              p : (if p <= mybound
                  then sieve (remove (p*p) x)
                  else x) where
                                 | a == what = (remove (what+step) as)
                                 | a > what = a:(remove (what+step) as)
              remove what [] = []
-             step = (if (p == 2) then p else (2*p)) 
+             step = (if (p == 2) then p else (2*p))
          sieve [] = []
          mybound = ceiling(sqrt(fromIntegral how_much))
 

File project-euler/10/10_3.c

-/*
- * =====================================================================================
- *
- *       Filename:  10.c
- *
- *    Description:  
- *
- *        Version:  1.0
- *        Created:  28/11/09 14:08:11
- *       Revision:  none
- *       Compiler:  gcc
- *
- *         Author:  YOUR NAME (), 
- *        Company:  
- *
- * =====================================================================================
- */
-
 #include <string.h>
 #include <math.h>
 #include <stdint.h>
 
     memset(bitmask, '\0', sizeof(bitmask));
     mark_limit = (int)sqrt(limit);
-    
+
     for (p=2 ; p <= mark_limit ; p++)
     {
         if (! ( bitmask[p>>3]&(1 << (p&(8-1))) ) )

File project-euler/10/10_half.c

-/*
- * =====================================================================================
- *
- *       Filename:  10.c
- *
- *    Description:  
- *
- *        Version:  1.0
- *        Created:  28/11/09 14:08:11
- *       Revision:  none
- *       Compiler:  gcc
- *
- *         Author:  YOUR NAME (), 
- *        Company:  
- *
- * =====================================================================================
- */
-
 #include <string.h>
 #include <math.h>
 #include <stdint.h>
 
     loop_to=(((int)(sqrt(limit)))>>1);
     half_limit = (limit-1)>>1;
-    
+
     for (half=1 ; half <= loop_to ; half++)
     {
         if (! ( bitmask[half>>3]&(1 << (half&(8-1))) ) )

File project-euler/10/10_micro_opt.c

-/*
- * =====================================================================================
- *
- *       Filename:  10.c
- *
- *    Description:  
- *
- *        Version:  1.0
- *        Created:  28/11/09 14:08:11
- *       Revision:  none
- *       Compiler:  gcc
- *
- *         Author:  YOUR NAME (), 
- *        Company:  
- *
- * =====================================================================================
- */
-
 #include <string.h>
 #include <math.h>
 #include <stdint.h>
 
     memset(bitmask, '\0', sizeof(bitmask));
     mark_limit = (int)sqrt(limit);
-    
+
     for (p=2 ; p <= mark_limit ; p++)
     {
         if (! ( bitmask[p>>3]&(1 << (p&(8-1))) ) )

File project-euler/10/benchmark.pl

     500,
     {
         (
-            map { get_c_prog_kv($_) } 
+            map { get_c_prog_kv($_) }
             (qw(
-                c_mine c_mine_micro_opt c_mine_half 
+                c_mine c_mine_micro_opt c_mine_half
             ))
         ),
     }
     20,
     {
         (
-            map { get_c_prog_kv($_) } 
+            map { get_c_prog_kv($_) }
             qw(haskell_mine haskell_zeroth)
         ),
         (

File project-euler/100/100.pl

     while ($top >= $bottom)
     {
         my $mid = (($bottom + $top) >> 1);
-        
+
         my $product = $mid * ($mid-1);
         if ($product == $wanted_product)
         {

File project-euler/100/euler-100-50-chance-of-taking-two-blue-discs.pl

     while ($top >= $bottom)
     {
         my $mid = (($bottom + $top) >> 1);
-        
+
         my $product = $mid * ($mid-1);
         if ($product == $wanted_product)
         {

File project-euler/101/euler-101-take2-with-bigrat.pl

 
     return $package->new(
         {
-            rows => 
+            rows =>
             [
                 map
-                { 
+                {
                     my $r = $_;
                     Row->new(
                         {
 sub _add_row_product_to_row
 {
     my ($self, $row_idx, $other_row, $multiplier) = @_;
-    
+
     foreach my $i (0 .. $self->size()-1)
     {
         $self->_set_elem(
     foreach my $col_to_stair (0 .. $self->size()-1)
     {
         my $found_row_idx =
-            List::Util::first 
+            List::Util::first
             {
                 ! $self->_elem($_, $col_to_stair)->is_zero()
             }
             {
                 $simultaneous->(
                     sub {
-                        $_->_multiply_row_by($col_to_stair, 1/$n);    
+                        $_->_multiply_row_by($col_to_stair, 1/$n);
                     }
                 );
             }
         {
             rows =>
             [
-                map { 
-                    my $base = $_; 
+                map {
+                    my $base = $_;
                     _row([
-                        map { 
-                            my $power = $_; 
-                            Math::BigRat->new($base) ** $power 
-                        } 
+                        map {
+                            my $power = $_;
+                            Math::BigRat->new($base) ** $power
+                        }
                         (0 .. $idx-1)
                     ]);
-                } 
+                }
                 (1 .. $idx)
             ],
         }
         {
             $bop += $coeffs[$exp] * ($x ** $exp);
         }
-        
+
         return $bop;
     };
 

File project-euler/101/euler-101.pl

     my ($a_s) = @_;
 
     my $coeffs = Math::MatrixReal->new_from_rows(
-        [ map { my $x = $_; [map { $x ** $_ } (0 .. $#$a_s) ] } 
+        [ map { my $x = $_; [map { $x ** $_ } (0 .. $#$a_s) ] }
             (1 .. scalar(@$a_s))
         ]
     );
-    
+
     $coeffs->transpose($coeffs);
-    
+
     my $a_mat = Math::MatrixReal->new_from_rows([map { [$_] } @$a_s]);
 
     return $coeffs->inverse() * $a_mat;
 {
     my ($a_s) = @_;
 
-    return 
+    return
     (
-        Math::MatrixReal->new_from_rows([[map { @$a_s ** $_ } 1 .. scalar(@$a_s) ]]) 
+        Math::MatrixReal->new_from_rows([[map { @$a_s ** $_ } 1 .. scalar(@$a_s) ]])
         * find_coeff($a_s)
     )->element(1,1);
 }

File project-euler/102/euler-102-triangles.pl

 while (my $line = <$in>)
 {
     chomp($line);
-    
+
     my @coords = split(/,/, $line);
 
     my $main_area = triangle_area(@coords);
     for my $point_to_zero (0 .. 2)
     {
         my @new_coords = @coords;
-        # Set the other point to zero. 
+        # Set the other point to zero.
         $new_coords[$point_to_zero*2] = $new_coords[$point_to_zero*2+1] = 0;
         $sub_areas_total += triangle_area(@new_coords);
     }
-    
+
     if ($sub_areas_total == $main_area)
     {
         $count++;

File project-euler/103/euler-103.pl

 
 * * a1+a2+a3+a4 > a5+a6+a7
 
-* 20, 20+11, 20+18, 20+19, 20+20,  20+22, 20+25 = 
+* 20, 20+11, 20+18, 20+19, 20+20,  20+22, 20+25 =
 = 20, 31, 38, 39, 40, 42, 45 is a special sum set.
 
 =cut
     my $A = shift;
 
     my $recurse;
-    
+
     $recurse = sub {
         my ($i, $B_sum, $B_count, $C_sum, $C_count) = @_;
 
                     ||
             (
                 ($B_sum != $C_sum)
-                    && 
+                    &&
                 (($B_count > $C_count) ? ($B_sum > $C_sum) : 1)
                     &&
                 (($C_count > $B_count) ? ($C_sum > $B_sum) : 1)
     {
         return;
     }
-    
+
     if (@$A_so_far == 7)
     {
         print "@$A_so_far\n";

File project-euler/104/euler-104-2.pl

 sub calc_fib
 {
     my ($n) = @_;
-    
+
     return $fib_cache{$n} ||=
         (
               ($n & 0x1)
-            ? do { 
-                my $half = (($n-1)>>1); 
-                my $x = calc_fib($half); 
+            ? do {
+                my $half = (($n-1)>>1);
+                my $x = calc_fib($half);
                 my $y = calc_fib($half+1);
                 $x*$x+$y*$y;
             }
-            : do { 
-                my $half = ($n>>1); 
+            : do {
+                my $half = ($n>>1);
                 my $x = calc_fib($half);
                 my $y = calc_fib($half-1);
                 $x * (($y<<1)+$x);
 my $k = 2;
 while (1)
 {
-    ($prev_fib_low, $this_fib_low) = 
+    ($prev_fib_low, $this_fib_low) =
         ($this_fib_low, (($prev_fib_low+$this_fib_low) % $MOD));
     $k++;
 

File project-euler/105/euler-105.pl

     my $A = shift;
 
     my $recurse;
-    
+
     $recurse = sub {
         my ($i, $B_sum, $B_count, $C_sum, $C_count) = @_;
 
                     ||
             (
                 ($B_sum != $C_sum)
-                    && 
+                    &&
                 (($B_count > $C_count) ? ($B_sum > $C_sum) : 1)
                     &&
                 (($C_count > $B_count) ? ($C_sum > $B_sum) : 1)

File project-euler/108/euler-108.pl

     else
     {
         foreach my $idx (
-            0 
-                .. 
+            0
+                ..
             ((@$composition == @primes)
                 ? ($#$composition)
                 : ($#$composition+1)
         {
             my @new = @$composition;
             $new[$idx]++;
-            my $new_n = 
-                reduce { $a * $b } 1, 
-                map { $primes[$_] ** $new[$_] } (0 .. $#new) 
+            my $new_n =
+                reduce { $a * $b } 1,
+                map { $primes[$_] ** $new[$_] } (0 .. $#new)
                 ;
             if (! exists($decomposition{"$new_n"}))
             {

File project-euler/109/euler-109.pl

 
 There are exactly eleven distinct ways to checkout on a score of 6:
 
-D3 	
-  	
- 
+D3
+
+
 D1 	D2 	 S2 	D2 	 D2 	D1 	 S4 	D1 	 S1 	S1 	D2 S1 	T1 	D1 S1 	S3
 D1 D1 	D1 	D1 D1 	S2 	D1 S2 	S2 	D1
 
 
 Incredibly there are 42336 distinct ways of checking out in total.
 
-How many distinct ways can a player checkout with a score less than 100?  
+How many distinct ways can a player checkout with a score less than 100?
 
 =cut
 

File project-euler/11.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;
 {
     foreach my $y (0 .. 19)
     {
-        $max = 
+        $max =
             max(
-                $max, 
+                $max,
                 map {
                     p_v($x,$y,@$_)
                 } ([0,1],[1,0],[1,1],[1,-1])

File project-euler/110/euler-110-no-gmp.pl

         {
             foreach my $idx (
                 0
-                .. 
+                ..
                 ((@$factors == $num_primes)
                     ? ($#$factors)
                     : ($#$factors+1)
             {
                 my @new = @$factors;
                 $new[$idx]++;
-                my $new_n = 
-                reduce { $a * $b } 1, 
-                map { vec($primes_list, $_, 32) ** $new[$_] } (0 .. $#new) 
+                my $new_n =
+                reduce { $a * $b } 1,
+                map { vec($primes_list, $_, 32) ** $new[$_] } (0 .. $#new)
                 ;
                 my $new_rank  = calc_rank(\@new);
                 if (! any { $_->{n} <= $new_n && $_->{rank} >= $new_rank } @new_best)
                 {
-                    push @new_best, 
+                    push @new_best,
                         {n => $new_n, factors => \@new, rank => $new_rank }
                     ;
                 }

File project-euler/110/euler-110.pl

         {
             foreach my $idx (
                 0
-                .. 
+                ..
                 ((@$factors == $num_primes)
                     ? ($#$factors)
                     : ($#$factors+1)
             {
                 my @new = @$factors;
                 $new[$idx]++;
-                my $new_n = 
-                reduce { $a * $b } 1, 
-                map { Math::GMP->new(vec($primes_list, $_, 32)) ** $new[$_] } (0 .. $#new) 
+                my $new_n =
+                reduce { $a * $b } 1,
+                map { Math::GMP->new(vec($primes_list, $_, 32)) ** $new[$_] } (0 .. $#new)
                 ;
                 my $new_rank  = calc_rank(\@new);
                 if (! any { $_->{n} <= $new_n && $_->{rank} >= $new_rank } @new_best)
                 {
-                    push @new_best, 
+                    push @new_best,
                         {n => $new_n, factors => \@new, rank => $new_rank }
                     ;
                 }

File project-euler/111/euler-111.pl

 
 =begin verification
 
-This function throws an exception due to a bug in bsg-games' primes. 
+This function throws an exception due to a bug in bsg-games' primes.
 
 sub is_prime
 {
 
     if ($v1 xor $v2)
     {
-        die "Results don't match for $n!";    
+        die "Results don't match for $n!";
     }
 
     return $v1;

File project-euler/112/euler-112.pl

 =end foo
 
 =cut
-    
+
     if ($n % 100_000 == 0)
     {
         print "$n: @counts\n"

File project-euler/113/euler-113.pl

     my $total_sum = 0;
 
     # Count the decreasing numbers
-    # 
+    #
     # Plan:
     # -----
-    # 
+    #
     # A decreasing number is 00000000000000000000$D[$N]...$D[2]$D[1]$D[0]
     # where for every $I $D[$I+1] > $D[$I].
-    # 
+    #
     # For N = 1 the decreasing numbers are 0-9.
     # For N = 2 the decreasing numbers are 0-9,10,11,20,21,22,30,31,32,33,...
-    # For N = 3 the decreasing numbers are 
+    # For N = 3 the decreasing numbers are
     my @counts;
 
     {
         push @counts, (\@d_counts);
 
         # print "For $digit_idx : ", join(",", reverse @d_counts ), "\n";
-    
+
         foreach my $d_c (@d_counts[1 .. 9])
         {
             $total_sum += $d_c;
 
     my $total_sum = count_increasing($NUM_DIGITS) + count_decreasing($NUM_DIGITS);
 
-    # Remove one count of the numbers that are both increasing and 
+    # Remove one count of the numbers that are both increasing and
     # decreasing i.e: numbers with all digits the same.
     foreach my $num_digits (0 .. $max_digit)
     {

File project-euler/114/euler-114.pl

     }
     # For $block_len == $len
     $with_block++;
-    push @counts, +{ 
+    push @counts, +{
         start_with_block => $with_block,
         start_with_square => $with_square
     };

File project-euler/117/euler-117.pl

         {
             if ($delta <= @counts)
             {
-                $sum += $counts[-$delta]; 
+                $sum += $counts[-$delta];
             }
         }
         push @counts, $sum;

File project-euler/118/euler-118.pl

 my @sets_by_rank;
 
 push @sets_by_rank, undef();
-push @sets_by_rank, 
-    { 
-        map { 
+push @sets_by_rank,
+    {
+        map {
             my $p = $_;
             my $s = '';
             vec($s, $p, 1) = 1;
                     foreach my $o_k (keys(%{$other_sub_sets->{$other_sub_vec}}))
                     {
                         my $signature =
-                            join(",", sort { $a <=> $b } 
+                            join(",", sort { $a <=> $b }
                                 split(",", "$sub_k,$o_k")
                             );
                         $record->{$signature} = 1;
     }
 
     # Now let's find the complete numbers with $rank digits out of [1..9].
- 
+
     # The ending digit cannot be even or 5 because then the number won't
     # be prime.
     foreach my $ending_digit (qw(1 3 7 9))
     {
-        
+
         my $recurse;
-        
+
         $recurse = sub {
             my ($num_so_far, $vec) = @_;
-            
+
             if (length($num_so_far) == $rank)
             {
                 if (is_prime($num_so_far))
 
         my $init_vec = '';
         vec($init_vec, $ending_digit, 1) = 1;
-     
-        $recurse->($ending_digit, $init_vec); 
+
+        $recurse->($ending_digit, $init_vec);
     }
 
 }

File project-euler/119/euler-119-take2.pl

 {
     my $i = shift;
 
-    my $p_exp = ($prime_exponents[$i] ||= 
-        do { 
+    my $p_exp = ($prime_exponents[$i] ||=
+        do {
             my $p = <$primes_fh>;
             chomp($p);
             { e => $p, b => 2,};
     # set $self->{key} = $value;
     my ($e_idx) = @_;
 
-    my $p_exp = 
+    my $p_exp =
 
     $self->{e} = $e_idx;
     $self->{n} = Exponents::get_exp($e_idx);
     my $other = shift;
 
     return (
-            (($self->{n} <=> $other->{n})) 
+            (($self->{n} <=> $other->{n}))
                 ||
             (($self->{e} <=> $other->{e}))
     );
 
     while (Exponents::peek_exp($e_idx) <= $next_exp_i)
     {
-        $heap->add(MyHeapElem->new($e_idx++));    
+        $heap->add(MyHeapElem->new($e_idx++));
     }
 
     if (length($i) == 1)

File project-euler/12.lisp

                    (setq num (/ num (expt factor e))))))))
 
 (defun num-divisors (num)
-  (apply #'* 
+  (apply #'*
           (mapcar #'(lambda (pair) (1+ (cdr pair))) (factorize num))))
 
 (defun myfind ()

File project-euler/120/euler-120.pl

 Since a^2, a^3 , a^4 etc. are evenly divisable by a^2 we get that
 the modulo of the sum is:
 
-1^n + (-1)^n + n * a + (-1)^(n-1) * n * a = 
+1^n + (-1)^n + n * a + (-1)^(n-1) * n * a =
 
 If n mod 2 = 0 we get:
 

File project-euler/120/test.pl

 {
     print "$n: ";
     print +(
-        ( ((($A - 1) ** $n) + (($A + 1) ** $n)) % ($A * $A) ), 
+        ( ((($A - 1) ** $n) + (($A + 1) ** $n)) % ($A * $A) ),
         "\n",
     );
 }

File project-euler/121/euler-121.pl

 
     push @B_nums_probs, (0);
 
-    my @new_B_probs = map { 
-        my $i = $_; 
-        $B_nums_probs[$i] * (1-$this_B_prob) + 
+    my @new_B_probs = map {
+        my $i = $_;
+        $B_nums_probs[$i] * (1-$this_B_prob) +
             (($i == 0) ? 0 : ($B_nums_probs[$i-1] * $this_B_prob))
         } (0 .. $turn_idx);
 

File project-euler/122/122-planning.txt

 
 10: 1,2,4,5,10 -> 4
 
-11: 1,2,4,8,10,11 -> 5 ; 1,2,3,6,9,11 -> 5 ; 1,2,4,5,10,11 -> 5 ; 
+11: 1,2,4,8,10,11 -> 5 ; 1,2,3,6,9,11 -> 5 ; 1,2,4,5,10,11 -> 5 ;
     1,2,4,5,6,11 -> 5
 
 12: 1,2,3,6,12 -> 4 ; 1,2,4,8,12 -> 4 [3 * 2 * 2]
 
 rank(2*x+1) >= rank(2*x).
 
-Proof: let's assume that x is the minimal natural number for which 
+Proof: let's assume that x is the minimal natural number for which
 rank(2*x+1) < rank(2*x). If its best composition was "(2*x)+(1)" then
 2*x would have a lower rank. Therefore it is i+j. Now since 2*x+1 is odd,
 it means one of i,j is even and the other odd. Without loss of generality,
 let's assume that i is even and j is odd.
 
 Let's look at the composition C[2*x+1] at one point we add 1 to an even number
-Let's not add it there. If we can still form 2*x with the lower rank then we 
+Let's not add it there. If we can still form 2*x with the lower rank then we
 have a contradiction. If, OTOH, we do something with [2*a'+1], like add it to
 another number then either:
 
 1. Instead of doing [2*a'+1]+[2*b'+1] we can do [2*a']+[2*b']+2  to get the
 same sum with the same, or lesser, effort.
 
-2. If we multiply [2*a'+1] by two to get [2*a'+1]*2, we can do 
+2. If we multiply [2*a'+1] by two to get [2*a'+1]*2, we can do
 [2*a']*2+2 and get it at the same effort.
 
 Therefore, the rank of 2*x+1 must be greater or equal to that of 2*x.
 Lemma 2:
 --------
 
-For every x \in N : rank(2*x) == rank(x)+1 and one of its best compositions is 
+For every x \in N : rank(2*x) == rank(x)+1 and one of its best compositions is
 that of "(x)+(x)".
 
 Proof: let's assume it is true for all y \in {1 .. x-1} and show it is also
 the we can take the "i/2+j/2" composition to find a better composition for
 x, and so yield a lower r (which is reductio ad absurdum). Therefore, i
 and j are both odd (because an odd number plus an even number cannot be
-2*x). 
+2*x).
 
-Let's assume that i < j (if i=j then i=j=x). Since j-1 >= x then 
-rank(j) >= rank(j-1) >= log_2[j-1] >= log_2[x] (according to Lemma 1 and the 
+Let's assume that i < j (if i=j then i=j=x). Since j-1 >= x then
+rank(j) >= rank(j-1) >= log_2[j-1] >= log_2[x] (according to Lemma 1 and the
 induction assumption). So j+i will be at least rank(j)+1 which won't be better
 than rank(x)+1 (why? - left as an exercise for the future).
 
 --------
 
 If C[2*x+1] (where C is the composition) is {1,2,.....a2,a1, 2*x+1}
-then a2 != a1 or else 2*x+1 will be odd. So a1 > x. Now, let's take the 
+then a2 != a1 or else 2*x+1 will be odd. So a1 > x. Now, let's take the
 identical set only with a1-1 - {1,2,.....a2,a1-1,2*x} . We need to compose
 a1-1 somehow and make sure that (2*x+1-a1) is still a composing number.
 
 j-1 = {1,2....j-1}
 
 Since j-1 < j then the number of elements in the j-1 set is lesser or
-equal to that of j. 
+equal to that of j.
 
 Removed 2:
 ----------
 Lemma 1 then rank(j-1) <= rank(j) and we can use "(j-1)+(2)" instead
 to yield a minimal sum which is a contradiction.
 
-So i >= 3. 
+So i >= 3.
 
-Let's look at "(i-1)+(j-1)" 
+Let's look at "(i-1)+(j-1)"
 Now since rank(i-1) <= rank(i) and rank(j-1) <= rank(j)
 Now, in order to form an odd number one has to add 1 to an even power
-of 2 such as 2, 4, 8, 16, etc (which clearly are minimally composed). 
-If 
+of 2 such as 2, 4, 8, 16, etc (which clearly are minimally composed).
+If
 

File project-euler/122/euler-122-take2.pl

                         next SUPERSETS;
                     }
                     # If the new set is a superset of an existing set,
-                    # then we don't want it here. Put all the existing sets in 
+                    # then we don't want it here. Put all the existing sets in
                     # place and skip this loop.
                     elsif (is_superset((\%new_set_hash), $s, 0))
                     {

File project-euler/122/euler-122-take5.pl

                     last FILL_LOOP;
                 }
             }
-            
+
             push @{$compositions_by_rank[$base_rank+1]}, $new_comp;
         }
     }
 }
 
-print "Sum is " . 
+print "Sum is " .
     sum (
         map { $_->{rank} } @compositions[ 1 .. $#compositions]
     ) . "\n"

File project-euler/122/euler-122.pl

                         next SUPERSETS;
                     }
                     # If the new set is a superset of an existing set,
-                    # then we don't want it here. Put all the existing sets in 
+                    # then we don't want it here. Put all the existing sets in
                     # place and skip this loop.
                     elsif (is_superset((\%new_set_hash), $s, 0))
                     {

File project-euler/123/euler-123.pl

 Since a^2, a^3 , a^4 etc. are evenly divisable by a^2 we get that
 the modulo of the sum is:
 
-1^n + (-1)^n + n * a + (-1)^(n-1) * n * a = 
+1^n + (-1)^n + n * a + (-1)^(n-1) * n * a =
 
 If n mod 2 = 0 we get:
 

File project-euler/124/euler-124.pl

     my $self = shift;
     my $other = shift;
 
-    return ((($self->{key} <=> $other->{key})) || 
+    return ((($self->{key} <=> $other->{key})) ||
             (($self->{n} <=> $other->{n}))
         );
 }

File project-euler/126/126-planning.txt

 Thinking:
 =========
 
-We've realised that in layer of depth 'd', the cells have a delta of 
+We've realised that in layer of depth 'd', the cells have a delta of
 d_x+d_y+d_z=d . Now in depth 1, the cells have a count of:
 
 2*[w_x*w_y + w_y*w_z + w_x*w_z]
 
 In depth 2, we add the following offsets - @d = (0,1,1) ; @d = (1,0,1)
-@d = (1,1,0) (as (2,0,0) and friends are already counted in the previous 
+@d = (1,1,0) (as (2,0,0) and friends are already counted in the previous
 layer). So:
 
 Total[2]-Total[1] = 4 * [ w_x + w_y + w_z ]
 
 Therefore:
 
-a[n] = x*y+y*z+x*z + n*(x+y+z)*2 + 4 * n * (n-1) /2 = 
+a[n] = x*y+y*z+x*z + n*(x+y+z)*2 + 4 * n * (n-1) /2 =
 x*y+y*z+x*z + 2 * n * (x+y+z + n - 1)

File project-euler/126/euler-126-take2.pl

 
 my @C;
 
-# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal 
+# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal
 # reached layer.
 my %cuboids;
 
         {
             my $x = $max_layer_size/$z/$y;
 
-            if ($x * $y * $z != $max_layer_size 
+            if ($x * $y * $z != $max_layer_size
                     or
                 $x < $y)
             {
 
             # print "$x,$y,$z\n";
             my $initial_cuboid =
-                [ map { 
+                [ map {
                     [ map { [(1)x$z] } (1 .. $y) ]
-                    } 
+                    }
                     (1 .. $x)
                 ];
 
-            $cuboids{"$x,$y,$z"} = 
+            $cuboids{"$x,$y,$z"} =
                 { d => 1, n => $max_layer_size };
 
             add_layer($x, $y, $z);

File project-euler/126/euler-126-take3.pl

 
 # Used to be:
 # <<<
-# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal 
+# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal
 # reached layer.
 # >>>
 # Now we no longer need the $X,$Y,$Z.
         {
             my $x = $max_layer_size/$z/$y;
 
-            if ($x * $y * $z != $max_layer_size 
+            if ($x * $y * $z != $max_layer_size
                     or
                 $x < $y)
             {
 
             # print "$x,$y,$z\n";
             # my $initial_cuboid =
-            # [ map { 
+            # [ map {
             # [ map { [(1)x$z] } (1 .. $y) ]
-            # } 
+            # }
             # (1 .. $x)
             # ];
             #
-            my $new_layer_count = 
+            my $new_layer_count =
                 ($x*($y+$z)+$z*$y);
 
             # We increase the depth's delta by 8 each time.

File project-euler/126/euler-126-take4.pl

 
 # Used to be:
 # <<<
-# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal 
+# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal
 # reached layer.
 # >>>
 # Now we no longer need the $X,$Y,$Z.
         X_LOOP:
         for my $x (1 .. $y)
         {
-            my $new_layer_count = 
+            my $new_layer_count =
                 ($x*($y+$z)+$z*$y);
 
             my $delta = ((($x+$y+$z)<<1)-4);

File project-euler/126/euler-126.pl

 
 my @C;
 
-# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal 
+# Matches $X,$Y,$Z (where $X >= $Y >= $Z) to the cuboid array and maximal
 # reached layer.
 my %cuboids;
 
     my @new_dims = (map { $_ + 2 } @dims);
 
     my $new_array =
-        [ map { 
+        [ map {
             [
             map
             { [(0)x($new_dims[2])] }
         {
             my $x = $max_layer_size/$z/$y;
 
-            if ($x * $y * $z != $max_layer_size 
+            if ($x * $y * $z != $max_layer_size
                     or
                 $x < $y)
             {
 
             # print "$x,$y,$z\n";
             my $initial_cuboid =
-                [ map { 
+                [ map {
                     [ map { [(1)x$z] } (1 .. $y) ]
-                    } 
+                    }
                     (1 .. $x)
                 ];
 
-            $cuboids{"$x,$y,$z"} = 
+            $cuboids{"$x,$y,$z"} =
                 { array => $initial_cuboid, dims => [$x,$y,$z], n => $max_layer_size };
 
             add_layer($x, $y, $z);

File project-euler/127/euler-127.pl

 
             if (gcd($B, $A) == 1)
             {
-                if ( # gcd($C, $A) == 1 and gcd($C, $B) == 1 and 
+                if ( # gcd($C, $A) == 1 and gcd($C, $B) == 1 and
                     ($rad_A*$rad_cache[$B]) < $div)
                 {
                     print "Found $C\n";

File project-euler/128/euler-128.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;
 
 0 ; 6 ; 12 ; 18 ;  - keeps increasing by +6.
 
-So the formula is 1 + 
+So the formula is 1 +
 
 =head2 Middle cells cannot be PD(n) = 3
 
     my $d = int(sqrt($y*$y+$x*$x));
     # $y is the 1,2,8,19 axis
     # $x is the 1,6,16,32... axis.
-    
+
     if (($x > 0) && ($y > $x))
     {
-        
+
     }
 }
 
 
         if (0)
         {
-            print "$n [Ring=$ring,Side=$side,Cell=$cell] ; Neighbours = ", 
-            join(",", sort { $a <=> $b } map { abs($n-$_) } @vicinity), 
+            print "$n [Ring=$ring,Side=$side,Cell=$cell] ; Neighbours = ",
+            join(",", sort { $a <=> $b } map { abs($n-$_) } @vicinity),
             "\n";
         }
         if (scalar(grep { is_prime(abs($n-$_)) } @vicinity) == 3)
     $ring++;
     ( $prev_ring_len, $prev_ring_start, $ring_len, $ring_start ) =
     ($ring_len, $ring_start, $next_ring_len, $next_ring_start);
-    
+
     $next_ring_start += $ring_len;
     $next_ring_len += 6;
 }

File project-euler/129/euler-129.pl

 =head1 ANALYSIS
 
 A(n) < n because otherwise for R(1) .. R(n-1) there will be two identical
-non-zero modulos. Let's say they are 'a' and 'b' where b > a, so 
-R(b) % n = R(a) % n. In that case (R(b)-R(a)) % n = 0, but then 
+non-zero modulos. Let's say they are 'a' and 'b' where b > a, so
+R(b) % n = R(a) % n. In that case (R(b)-R(a)) % n = 0, but then
 (R(b-a) * 10^R(a)) % n = 0, and since the modulo of a power of 10 with n
 cannot be 0 (because GCD(n, 10) = 1), then R(b-a) % n = 0, which demonstrates
 that A(n) < n (reduction ad absurdum.).

File project-euler/131/euler-131.pl

     for my $n (1 .. $prime*3)
     {
         my $x = Math::BigInt->new($n*$n*($n+$prime));
-        
+
         if ($x->copy->broot(3)->bpow(3) == $x)
         {
             $found_count++;

File project-euler/132/132-2.pl

     foreach my $power_of_5 (0 .. 9)
     {
         my $num_digits = 2 ** $power_of_2 * 5 ** $power_of_5;
-        push @divisors, +{ l => $num_digits+1, n => 
+        push @divisors, +{ l => $num_digits+1, n =>
             sub { return ("1" . "0" x ($num_digits-1) . "1") },
         };
 
 foreach my $div (@divisors)
 {
     my $n = $div->{n}->();
-    
+
     print "Checking $n\n";
     my $factor_string = `factor "$n"`;
-    
+
     $factor_string =~ s{\A[^:]*:\s*}{}ms;
-    
+
     foreach my $f (split(/\s+/, $factor_string))
     {
         $factors{$f}++;

File project-euler/132/132-3.pl

 }
 
 open my $primes_fh, "primes 7|";
-my $last_prime = 
+my $last_prime =
 
 my $count = 0;
 my $sum = 0;

File project-euler/132/132.pl

 # n = a promise for the number.
 my @factors =
 (
-    +{ l => 2, n => sub { return 11; }}, 
-    (map { 
+    +{ l => 2, n => sub { return 11; }},
+    (map {
         my $e = $_;
         +{
             l => ((2 ** $e)+1),

File project-euler/133/133.pl

     print "Checking $n\n";
     if (! is_div($n))
     {
-        $sum += $n;    
+        $sum += $n;
     }
 }
 

File project-euler/135/euler-135.pl

 
 =head1 ANALYSIS
 
-(z+2d)^2 - (z+d)^2 - z^2 = z^2+4dz+4d^2 - z^2 - 2dz - d^2 - z^2 = 
+(z+2d)^2 - (z+d)^2 - z^2 = z^2+4dz+4d^2 - z^2 - 2dz - d^2 - z^2 =
 -z^2 + 2dz +3d^2 = (-z + 3d)(z + d)
 =cut
 

File project-euler/136/euler-136.pl

 
 =head1 ANALYSIS
 
-(z+2d)^2 - (z+d)^2 - z^2 = z^2+4dz+4d^2 - z^2 - 2dz - d^2 - z^2 = 
+(z+2d)^2 - (z+d)^2 - z^2 = z^2+4dz+4d^2 - z^2 - 2dz - d^2 - z^2 =
 -z^2 + 2dz +3d^2 = (-z + 3d)(z + d)
+
 =cut
 
 my $solution_counts_vec = '';

File project-euler/14.lisp

 
 (defun myfind ()
   (iter (for i from 2 to 999999)
-        (reducing (cons i (calc-seq-rank i)) 
+        (reducing (cons i (calc-seq-rank i))
                   by #'(lambda (m n) (if (> (cdr m) (cdr n)) m n))
                   initial-value (cons 1 0))))

File project-euler/145/euler145.c

  *
  *       Filename:  euler145.c
  *
- *    Description:  
+ *    Description:
  *
 Some positive integers n have the property that the sum [ n + reverse(n) ]
 consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 +
 
 How many reversible numbers are there below one-billion (109)?
 
-* 
+*
  *        Version:  1.0
  *        Created:  11/07/11 15:35:15
  *       Revision:  none
  *       Compiler:  gcc
  *
- *         Author:  YOUR NAME (), 
- *        Company:  
+ *         Author:  YOUR NAME (),
+ *        Company:
  *
  * =====================================================================================
  */
     int n;
 
     int count = 0;
-    
+
     limit = atoi(argv[1]);
 
     for (n = 21 ; n < limit ; )

File project-euler/149/149.pl

 sub add
 {
     my ($self, $n) = @_;
- 
+
     $self->{_ending_here} = _max($self->{_ending_here} + $n, 0);
     $self->{_so_far} = _max($self->{_so_far}, $self->{_ending_here});
 

File project-euler/15.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/150/Euler150.pm

         {
             foreach my $col (0 .. $r)
             {
-                $min = min($min, 
+                $min = min($min,
                     ($sums[$tri_idx] += $row[$col+$row_idx-$r+1] - $row[$col])
                 );
                 $tri_idx++;

File project-euler/16.lisp

 
 (defun digits-sum (num)
   (labels
-    ((helper (n sum) 
+    ((helper (n sum)
         (if (zerop n)
           sum
           (helper (floor (/ n 10)) (+ sum (mod n 10))))))
     (helper num 0)))
-    
+
 (defun myfind ()
   (digits-sum (expt 2 1000)))
 

File project-euler/17.lisp

 (defun string-list-len (l)
   (apply #'+ (mapcar #'length l)))
 
-(defun f-up-to-nine () 
+(defun f-up-to-nine ()
   (list "one" "two" "three" "four" "five" "six" "seven" "eight" "nine"))
 
 (defun f-ten-to-19 ()
-  (list "ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" 
+  (list "ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen"
         "sixteen" "seventeen" "eighteen" "nineteen"))
 
 (defun f-tens ()
 
     (+ (* up-to-nine 9 10) ; the digits of the non-teens
        (* ten-to-19 10) ; the digits of the teens
-       (* tens 10 10) ; the digits of the tens 
+       (* tens 10 10) ; the digits of the tens
        (* hundreds 100) ; the digits of the hundreds.
        (* (length "and") 99 9) ; the digits of the "and" of the hundreds"
        (length "onethousand")

File project-euler/18.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;
     push @totals_lines,
         [
             map
-            { 
+            {
                 $this->[$_] +
                 max(
                   (($_ > 0) ? ($last->[$_-1]) : ()),

File project-euler/19.lisp

 
 (defun month-len (y m)
   (cond ((is-in m '(4 6 9 11)) 30)
-        ((= m 2) (+ 28 (if (or (div-by y 400) 
+        ((= m 2) (+ 28 (if (or (div-by y 400)
                                (and (div-by y 4) (not (div-by y 100))))
                          1 0)))
         (t 31)))
 
 (defmacro-clause (sum7 expr &optional into var initial-value init-val)
-    `(reducing ,expr by #'(lambda (m n) (mod (+ m n) 7)) 
+    `(reducing ,expr by #'(lambda (m n) (mod (+ m n) 7))
                into ,var initial-value ,init-val))
 
 (defun calc ()
-  (iter year-iter 
+  (iter year-iter
         (for year from 1900 to 2000)
         (iter (for month from 1 to 12)
-              (in year-iter (sum7 (month-len year month) into day-of-week 
+              (in year-iter (sum7 (month-len year month) into day-of-week
                                   initial-value 2))
               (format t "DW=~A~%" day-of-week)
-              (in year-iter (sum (if (and (>= year 1901) 
+              (in year-iter (sum (if (and (>= year 1901)
                                           (= day-of-week 1)) 1 0)
                                  into mycount
                                  )))

File project-euler/2.lisp

 
 (defun display-result ()
   (format t "Total is ~A~%" (sum1 1e6)))
-          
 
 
+

File project-euler/2.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/2.rb

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/20.lisp

 
 (defun digits-sum (num)
   (labels
-    ((helper (n sum) 
+    ((helper (n sum)
         (if (zerop n)
           sum
           (helper (floor (/ n 10)) (+ sum (mod n 10))))))
     ((helper (n prod)
              (if (= n 0) prod (helper (1- n) (* prod n)))))
     (helper num 1)))
- 
+
 (defun myfind ()
   (digits-sum (factorial 100)))
 

File project-euler/21.lisp

                    (setq num (/ num (expt factor e))))))))
 
 (defun num-divisors (num)
-  (reduce #'* 
+  (reduce #'*
           (mapcar #'(lambda (pair) (1+ (cdr pair))) (factorize num))
           :initial-value 1))
 

File project-euler/22.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/23/23.lisp

                    (setq num (/ num (expt factor e))))))))
 
 (defun num-divisors (num)
-  (reduce #'* 
+  (reduce #'*
           (mapcar #'(lambda (pair) (1+ (cdr pair))) (factorize num))
           :initial-value 1))
 

File project-euler/24.lisp

 (defun form-perm (remaining bit-vec)
   (
   (+ 5 6))
-    
-    

File project-euler/24.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;
 {
     my $f = factorial($place);
     my $p = int ($perm / $f);
-    
+
     push @result, splice(@digits,$p,1);
 
     $perm %= $f;

File project-euler/25.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/28.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/29.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/30.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/31.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/32.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/33.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/34.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/35.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/36.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/37.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;
 
 my @trunc_primes = ();
 
-N_LOOP: 
+N_LOOP:
 for(my $n = 11; @trunc_primes < 11 ; $n += 2)
 {
     foreach my $i (1 .. length($n))

File project-euler/38.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/39.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;
     }
 }
 
-print map { "$_ => $p_counts{$_}\n" } 
+print map { "$_ => $p_counts{$_}\n" }
     sort { $p_counts{$a} <=> $p_counts{$b} } keys(%p_counts)
     ;

File project-euler/4.pl

-#!/usr/bin/perl 
+#!/usr/bin/perl
 
 use strict;
 use warnings;

File project-euler/40.txt

      2894 ^
           2898
 
-1000+(10,000-2890)/4 = 3500 - 2890/4 = 3500 - 700 - 90/4 = 2800 - 90/4 = 
+1000+(10,000-2890)/4 = 3500 - 2890/4 = 3500 - 700 - 90/4 = 2800 - 90/4 =
 2800 - 22 - 2/4 = 2800-23+2/4 = 2777+2/4
 
 d[10,000] = 7
          38,895   ^
                   38,900
 
-10,000 + (100,000 - 38,890)/5 = 10,000 + 20,000 - 3,889 * 2 = 
+10,000 + (100,000 - 38,890)/5 = 10,000 + 20,000 - 3,889 * 2 =
 30,000 - 3,900 * 2 + 2*11 = 30,000 - 7,800 + 22 = 22,200 + 22 = 22,222
 
 d[100,000] = 2
 
 100,000 + (1,000,000 - 488,890)/6 = 100,000 + 511,110/6
 >>>>
-     85,185  
+     85,185
     --------
     511,110|6
     48

File project-euler/41.pl

 {
     my ($self, $set) = @_;
 
-    $self->{stack} =