From 2e2b95b0d1cc70d2306ae29173f6ff5dd0a960be Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Thu, 2 Jan 2020 14:32:22 +0100 Subject: Challenge 1 week 41 LK Perl --- challenge-041/lubos-kolouch/perl5/ch-1.pl | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 challenge-041/lubos-kolouch/perl5/ch-1.pl 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; + + -- cgit From 0f7227192a4022423f5ea56b67b7e5af43fe05b3 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Thu, 2 Jan 2020 14:35:31 +0100 Subject: Challenge 2 Week 041 LK --- challenge-041/lubos-kolouch/perl5/ch-2.pl | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 challenge-041/lubos-kolouch/perl5/ch-2.pl 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; -- cgit From 05b682fe65d547b1625af8f037753d09e27dc43b Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Thu, 2 Jan 2020 15:04:34 +0100 Subject: Challenge 1 Week 41 Python --- challenge-041/lubos-kolouch/python/ch-1.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 challenge-041/lubos-kolouch/python/ch-1.py 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() + -- cgit From d3059df229345b82dcc8241da5e43b3197e13ea6 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Thu, 2 Jan 2020 15:06:50 +0100 Subject: Challenge 2 Week 41 Python --- challenge-041/lubos-kolouch/python/ch-2.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 challenge-041/lubos-kolouch/python/ch-2.py 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) -- cgit