diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-04-19 12:30:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-19 12:30:46 +0100 |
| commit | 96cd7563954187de1b039181208487c589e1864d (patch) | |
| tree | 66fd100db5ee175de9213c1b17565fd7ce4f45df | |
| parent | dc4ba0840d954526231732abc8d517dc657d1123 (diff) | |
| parent | 78f87ae8a8a82595fe438f0033c2dcb9e88a4037 (diff) | |
| download | perlweeklychallenge-club-96cd7563954187de1b039181208487c589e1864d.tar.gz perlweeklychallenge-club-96cd7563954187de1b039181208487c589e1864d.tar.bz2 perlweeklychallenge-club-96cd7563954187de1b039181208487c589e1864d.zip | |
Merge pull request #1592 from Doomtrain14/master
perl solution ch#56
| -rw-r--r-- | challenge-055/yet-ebreo/python/ch-2a.py | 35 | ||||
| -rw-r--r-- | challenge-056/yet-ebreo/perl/ch-1.pl | 24 | ||||
| -rw-r--r-- | challenge-056/yet-ebreo/perl/ch-2.pl | 32 |
3 files changed, 91 insertions, 0 deletions
diff --git a/challenge-055/yet-ebreo/python/ch-2a.py b/challenge-055/yet-ebreo/python/ch-2a.py new file mode 100644 index 0000000000..15b537d506 --- /dev/null +++ b/challenge-055/yet-ebreo/python/ch-2a.py @@ -0,0 +1,35 @@ +import sys +import time + +start_time = time.time() + +if len(sys.argv) < 2: + narray = [1, 2, 3, 4] +else: + narray = list(map(int, sys.argv[1:])) + +narray.sort() +dict = {} + +def wave(a,l,r): + + if (l==r): + flag = 1 + for e in list(range(1,len(a))): + flag &= (a[e] >= a[e-1], a[e] <= a[e-1])[e % 2 > 0] + if not flag: + break + + if flag > 0: + hold = str(a) + if (not hold in dict): + print (hold) + dict[hold] = 1 + else: + for i in list(range(l,r+1)): + a[l],a[i] = a[i],a[l] + wave(a,l+1,r) + a[l],a[i] = a[i],a[l] + +wave(narray,0,len(narray)-1) +print("Execution Time: %s seconds" % (time.time() - start_time))
\ No newline at end of file diff --git a/challenge-056/yet-ebreo/perl/ch-1.pl b/challenge-056/yet-ebreo/perl/ch-1.pl new file mode 100644 index 0000000000..45c230b193 --- /dev/null +++ b/challenge-056/yet-ebreo/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature 'say'; + +my @N = (1, 6, 8, 2, 4, 9, 12); +my $k = 3; +my @h = (); + +$h[$_]++ for @N; +for my $x (0..$#N) { + #effort to optimize for larger arrays. + if ($h[$N[$x]+$k]) { + for my $y ($x+1..$#N) { + $k == abs $N[$x]-$N[$y] && say "$x\t$y"; + } + } +} +=begin +perl .\ch-1.pl +0 4 +1 5 +5 6 +=cut
\ No newline at end of file diff --git a/challenge-056/yet-ebreo/perl/ch-2.pl b/challenge-056/yet-ebreo/perl/ch-2.pl new file mode 100644 index 0000000000..e533d09a97 --- /dev/null +++ b/challenge-056/yet-ebreo/perl/ch-2.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature 'say'; + +my @tree = (5, [4, [11, [7], [2]]], [8, [13], [9, [1]]]) ; +my $total = $ARGV[0]||22; + +sub traverse { + my ($t,$sum,$path) = @_; + + if ($t->[1]) { + traverse ($t->[1],$sum+$t->[0],"$path->$t->[0]"); + } elsif ($t->[0]+$sum == $total) { + say "$path->$t->[0]"; + } + if ($t->[2]) { + traverse ($t->[2],$sum+$t->[0],"$path->$t->[0]"); + } +} +traverse(\@tree,0,""); + +=begin +perl .\ch-2.pl 22 +->5->4->11->2 + +perl .\ch-2.pl 26 +->5->8->13 + +perl .\ch-2.pl 23 +->5->8->9->1 +=cut
\ No newline at end of file |
