diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-01-02 14:42:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-02 14:42:25 +0000 |
| commit | 6a4197e76ffcc535278f05d82b09c5266ddc073c (patch) | |
| tree | eda0fddc78d9fc17734c41469858b89f8160d9d6 | |
| parent | e2f2f0613343e027f947facdc835557b835e5284 (diff) | |
| parent | d3059df229345b82dcc8241da5e43b3197e13ea6 (diff) | |
| download | perlweeklychallenge-club-6a4197e76ffcc535278f05d82b09c5266ddc073c.tar.gz perlweeklychallenge-club-6a4197e76ffcc535278f05d82b09c5266ddc073c.tar.bz2 perlweeklychallenge-club-6a4197e76ffcc535278f05d82b09c5266ddc073c.zip | |
Merge pull request #1099 from kolcon/master
Challenge 041 LK
| -rw-r--r-- | challenge-041/lubos-kolouch/perl5/ch-1.pl | 45 | ||||
| -rw-r--r-- | challenge-041/lubos-kolouch/perl5/ch-2.pl | 33 | ||||
| -rw-r--r-- | challenge-041/lubos-kolouch/python/ch-1.py | 24 | ||||
| -rw-r--r-- | challenge-041/lubos-kolouch/python/ch-2.py | 8 |
4 files changed, 110 insertions, 0 deletions
diff --git a/challenge-041/lubos-kolouch/perl5/ch-1.pl b/challenge-041/lubos-kolouch/perl5/ch-1.pl new file mode 100644 index 0000000000..72218333c5 --- /dev/null +++ b/challenge-041/lubos-kolouch/perl5/ch-1.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-1.pl +# +# USAGE: ./ch-1.pl +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-041/ +# +# Write a script to display attractive number between 1 and 50. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: YOUR NAME (), +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 01/02/2020 02:23:28 PM +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use Math::Factor::XS qw/count_prime_factors/; +use Math::Prime::XS qw/is_prime/; + +sub is_attractive { + my $what = shift; + + return is_prime(count_prime_factors($what)); +} + +# TESTS + +use Test::More; + +is(is_attractive(20),1); +is(is_attractive(23),''); +is(is_attractive(28),1); +is(is_attractive(256),''); + +done_testing; + + diff --git a/challenge-041/lubos-kolouch/perl5/ch-2.pl b/challenge-041/lubos-kolouch/perl5/ch-2.pl new file mode 100644 index 0000000000..53a59715a3 --- /dev/null +++ b/challenge-041/lubos-kolouch/perl5/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-2.pl +# +# USAGE: ./ch-2.pl +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-041/ +# +# Write a script to display first 20 Leonardo Numbers. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 01/02/2020 02:33:02 PM +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use Data::Dumper; + +my @l = (1,1); + +for (2..19) { + $l[$_] = $l[$_-2] + $l[$_-1]+1; +} + +warn Dumper @l; diff --git a/challenge-041/lubos-kolouch/python/ch-1.py b/challenge-041/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..e32db9a798 --- /dev/null +++ b/challenge-041/lubos-kolouch/python/ch-1.py @@ -0,0 +1,24 @@ +#!python3 + +import sys +from sympy.ntheory import factorint, isprime +import unittest + +def is_attractive(what): + factors = factorint(int(what)) + return (isprime(sum(factors.values()))) + + +# TESTS + +class PrimeTest(unittest.TestCase): + def test_20(self): + self.assertEqual(is_attractive(20),True) + def test_128(self): + self.assertEqual(is_attractive(128),True) + def test_256(self): + self.assertEqual(is_attractive(256),False) + +if __name__ == "__main__": + unittest.main() + diff --git a/challenge-041/lubos-kolouch/python/ch-2.py b/challenge-041/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..02b509279e --- /dev/null +++ b/challenge-041/lubos-kolouch/python/ch-2.py @@ -0,0 +1,8 @@ +#!python3 + +l = [1,1] + +for i in range(2,20): + l.append(l[i-2]+l[i-1]+1) + +print(l) |
