Permalink
Browse files

Some untested sum-of-pair submissions

  • Loading branch information...
1 parent db53f92 commit 1eed14c2e611d01d873d6eb9f60877dddf810618 Andreas Pauley committed Nov 19, 2009
Showing with 12 additions and 0 deletions.
  1. +10 −0 CodeSnippets/SumPairs/sumpairs-perl.pl
  2. +2 −0 CodeSnippets/SumPairs/sumpairs-prolog.pl
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Data::Dumper;
+
+my @array = (1, 2, 3, 4, 5, 6, 7, 8, 9);
+push @array, 0 if scalar @array % 2;
+my %hash = @array;
+my @sum = map { $hash{$_}+$_ } sort keys %hash;
+
+print Dumper(\@sum);
@@ -0,0 +1,2 @@
+sumpairs([X,Y|T],Out) :- Z is X + Y, sumpairs([Y|T], Tail), append([Z],Tail,Out).
+sumpairs(_,[]).

0 comments on commit 1eed14c

Please sign in to comment.