diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-12-31 19:09:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-31 19:09:55 +0000 |
| commit | 40b026cc5c552a4cf9d987c05c3fba5360a0f0a6 (patch) | |
| tree | 2449552360f9e3be27d8fecf9cbdd69b0dcc3da3 /challenge-041 | |
| parent | 91f522e1493ae47efdeaad7965bdf4b2bad11f30 (diff) | |
| parent | e33772e722e3a88f63376566c75642b934f5c57a (diff) | |
| download | perlweeklychallenge-club-40b026cc5c552a4cf9d987c05c3fba5360a0f0a6.tar.gz perlweeklychallenge-club-40b026cc5c552a4cf9d987c05c3fba5360a0f0a6.tar.bz2 perlweeklychallenge-club-40b026cc5c552a4cf9d987c05c3fba5360a0f0a6.zip | |
Merge pull request #1095 from kyzn/master
My solutions for W041
Diffstat (limited to 'challenge-041')
| -rw-r--r-- | challenge-041/kivanc-yazan/.gitignore (renamed from challenge-041/kivanc-yazan/perl5/.gitignore) | 2 | ||||
| -rwxr-xr-x | challenge-041/kivanc-yazan/perl5/ch-1.pl | 14 | ||||
| -rwxr-xr-x | challenge-041/kivanc-yazan/perl5/ch-2.pl | 17 | ||||
| -rwxr-xr-x | challenge-041/kivanc-yazan/python3/ch-1.py | 10 | ||||
| -rwxr-xr-x | challenge-041/kivanc-yazan/python3/ch-2.py | 9 |
5 files changed, 51 insertions, 1 deletions
diff --git a/challenge-041/kivanc-yazan/perl5/.gitignore b/challenge-041/kivanc-yazan/.gitignore index 5657e34d94..8ce1b629e0 100644 --- a/challenge-041/kivanc-yazan/perl5/.gitignore +++ b/challenge-041/kivanc-yazan/.gitignore @@ -1,2 +1,2 @@ _Inline/ -*.swp +*.sw* diff --git a/challenge-041/kivanc-yazan/perl5/ch-1.pl b/challenge-041/kivanc-yazan/perl5/ch-1.pl new file mode 100755 index 0000000000..cdc742acc3 --- /dev/null +++ b/challenge-041/kivanc-yazan/perl5/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use Math::Prime::Util qw/is_prime factor/; + +# Problem: Write a script to display attractive number between 1 and 50. + +for my $i (1..50){ + my @factors = factor($i); + my $factor_count = scalar(@factors); + if (is_prime($factor_count)){ + print "$i (@factors)\n"; + } +} diff --git a/challenge-041/kivanc-yazan/perl5/ch-2.pl b/challenge-041/kivanc-yazan/perl5/ch-2.pl new file mode 100755 index 0000000000..04c2db4edb --- /dev/null +++ b/challenge-041/kivanc-yazan/perl5/ch-2.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use Memoize; + +# Problem: Write a script to display first 20 Leonardo Numbers. + +sub leonardo { + my $i = shift; + return 1 if $i <= 1; + return leonardo($i-2)+leonardo($i-1)+1; +} +memoize('leonardo'); + +foreach my $i (0..20){ + print leonardo($i)."\n"; +} diff --git a/challenge-041/kivanc-yazan/python3/ch-1.py b/challenge-041/kivanc-yazan/python3/ch-1.py new file mode 100755 index 0000000000..6a24685c39 --- /dev/null +++ b/challenge-041/kivanc-yazan/python3/ch-1.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +from sympy import isprime, factorint + +# Problem: Write a script to display attractive number between 1 and 50. + +for i in range(1,51): + factors = factorint(i) + factor_count = sum(factors.values()) + if isprime(factor_count): + print(i,' ',factors) diff --git a/challenge-041/kivanc-yazan/python3/ch-2.py b/challenge-041/kivanc-yazan/python3/ch-2.py new file mode 100755 index 0000000000..bce7054db7 --- /dev/null +++ b/challenge-041/kivanc-yazan/python3/ch-2.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +# Problem: Write a script to display first 20 Leonardo Numbers. + +leonardo = [1,1] +for i in range(2,21): + leonardo.append(leonardo[i-2] + leonardo[i-1] + 1) + +print(leonardo) |
