aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-08-30 07:21:43 +0100
committerGitHub <noreply@github.com>2020-08-30 07:21:43 +0100
commitce441a6b9c1918a44958de6ab7bee275d4e18d74 (patch)
treeb4078307e5ce9653e1fcf7a8659edc7514d80e2f
parentf0050df07ec26c52917b46db177d0b24cfff566c (diff)
parenta21b987c056e30828728624b5bdba5d018351079 (diff)
downloadperlweeklychallenge-club-ce441a6b9c1918a44958de6ab7bee275d4e18d74.tar.gz
perlweeklychallenge-club-ce441a6b9c1918a44958de6ab7bee275d4e18d74.tar.bz2
perlweeklychallenge-club-ce441a6b9c1918a44958de6ab7bee275d4e18d74.zip
Merge pull request #2172 from adamcrussell/challenge-075
solutions for challenge 075
-rw-r--r--challenge-075/adam-russell/blog.txt1
-rw-r--r--challenge-075/adam-russell/blog1.txt1
-rw-r--r--challenge-075/adam-russell/perl/ch-1.pl47
-rw-r--r--challenge-075/adam-russell/perl/ch-2.pl40
-rw-r--r--challenge-075/adam-russell/prolog/ch-1.p21
5 files changed, 110 insertions, 0 deletions
diff --git a/challenge-075/adam-russell/blog.txt b/challenge-075/adam-russell/blog.txt
new file mode 100644
index 0000000000..d4274370e8
--- /dev/null
+++ b/challenge-075/adam-russell/blog.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/17614.html
diff --git a/challenge-075/adam-russell/blog1.txt b/challenge-075/adam-russell/blog1.txt
new file mode 100644
index 0000000000..20ad3ac428
--- /dev/null
+++ b/challenge-075/adam-russell/blog1.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/17720.html
diff --git a/challenge-075/adam-russell/perl/ch-1.pl b/challenge-075/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..c86b26809e
--- /dev/null
+++ b/challenge-075/adam-russell/perl/ch-1.pl
@@ -0,0 +1,47 @@
+use strict;
+use warnings;
+
+use AI::Prolog;
+use Hash::MultiKey;
+
+MAIN:{
+ my $S = $ARGV[0];
+ my $C = "[" . $ARGV[1] . "]";
+
+ my $prolog = do{
+ local $/;
+ <DATA>;
+ };
+ $prolog =~ s/_COINS_/$C/g;
+ $prolog =~ s/_SUM_/$S/g;
+ $prolog = new AI::Prolog($prolog);
+ $prolog->query("sum(Coins).");
+ my %h;
+ tie %h, "Hash::MultiKey";
+ while(my $result = $prolog->results){
+ my @s = sort @{$result->[1]};
+ $h{\@s} = undef;
+ }
+ for my $k (keys %h){
+ print "(" . join(",", @{$k}) . ")";
+ print "\n";
+ }
+}
+
+__DATA__
+member(X,[X|_]).
+member(X,[_|T]) :- member(X,T).
+
+coins(_COINS_).
+
+sum(Coins):-
+ sum([], Coins, 0).
+
+sum(Coins, Coins, _SUM_).
+
+sum(Partial, Coins, Sum):-
+ Sum < _SUM_,
+ coins(L),
+ member(X,L),
+ S is Sum + X,
+ sum([X | Partial], Coins, S). \ No newline at end of file
diff --git a/challenge-075/adam-russell/perl/ch-2.pl b/challenge-075/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..85768efd98
--- /dev/null
+++ b/challenge-075/adam-russell/perl/ch-2.pl
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+sub print_histogram{
+ my($values) = @_;
+ my @sorted_values = sort @{$values};
+ my $max = $sorted_values[-1];
+ my $x = $max;
+ while($x >= 1){
+ print "$x ";
+ for my $h (@{$values}){
+ print "# " if $h >= $x;
+ print " " if $h < $x;
+ }
+ print "\n";
+ $x--;
+ }
+ print "- " x (@{$values} + 1);
+ print "\n " . join(" ", @{$values}) ."\n";
+}
+
+MAIN:{
+ #my @A = (2, 1, 4, 5, 3, 7);
+ my @A = (3, 2, 3, 5, 7, 5);
+ print_histogram(\@A);
+ my $maximum_rectangle = -1;
+ for my $i (@A){
+ my $rectangle;
+ for my $j (@A){
+ if($i > $j){
+ $rectangle = 0;
+ }
+ if($i <= $j){
+ $rectangle += $i;
+ }
+ }
+ $maximum_rectangle = $rectangle if $rectangle > $maximum_rectangle;
+ }
+ print "Largest Rectangle: $maximum_rectangle\n";
+}
diff --git a/challenge-075/adam-russell/prolog/ch-1.p b/challenge-075/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..3f080607e9
--- /dev/null
+++ b/challenge-075/adam-russell/prolog/ch-1.p
@@ -0,0 +1,21 @@
+member(X,[X|_]).
+member(X,[_|T]) :- member(X,T).
+
+coins([1,2,4]).
+
+sum(Coins):-
+ sum([], Coins, 0).
+
+sum(Coins, Coins, 6).
+
+sum(Partial, Coins, Sum):-
+ Sum < 6,
+ coins(L),
+ member(X,L),
+ S is Sum + X,
+ sum([X | Partial], Coins, S).
+
+main:-
+ findall(Coins,sum(Coins), C),
+ writeln(C),
+ halt. \ No newline at end of file