diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-02-05 13:42:11 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-02-05 13:42:11 +0100 |
| commit | b778490b4ecb792b6698a95f22332a13aff9c9a7 (patch) | |
| tree | ec920562c7953204986a55352fa0cfb027a0047d | |
| parent | fd2b8a0c3bc66d366e1a26939dff6ccd44ad93bf (diff) | |
| download | perlweeklychallenge-club-b778490b4ecb792b6698a95f22332a13aff9c9a7.tar.gz perlweeklychallenge-club-b778490b4ecb792b6698a95f22332a13aff9c9a7.tar.bz2 perlweeklychallenge-club-b778490b4ecb792b6698a95f22332a13aff9c9a7.zip | |
Challenge 150 LK Task 1 2 Perl Python
| -rw-r--r-- | challenge-150/lubos-kolouch/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-150/lubos-kolouch/perl/ch-2.pl | 34 | ||||
| -rw-r--r-- | challenge-150/lubos-kolouch/python/ch-1.py | 11 | ||||
| -rw-r--r-- | challenge-150/lubos-kolouch/python/ch-2.py | 24 |
4 files changed, 88 insertions, 0 deletions
diff --git a/challenge-150/lubos-kolouch/perl/ch-1.pl b/challenge-150/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..dc6ea75c7f --- /dev/null +++ b/challenge-150/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; + +sub get_fib_word { + my ($word1, $word2) = @_; + + while (length($word2) < 51) { + my $new_word = $word1.$word2; + $word1 = $word2; + $word2 = $new_word; + } + + return substr($word2,50,1); +} + +use Test::More; + +is(get_fib_word('1234', '5678'), 7); +done_testing; diff --git a/challenge-150/lubos-kolouch/perl/ch-2.pl b/challenge-150/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..dcab18b498 --- /dev/null +++ b/challenge-150/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,34 @@ +use strict; +use warnings; +use Math::Prime::Util qw/factor/; + +sub get_sq_free_int{ + my $limit = shift; + my @result; + + for my $i (1..$limit) { + my @factors = factor($i); + + my %fact_hash; + my $is_ok = 1; + + for my $fact(@factors) { + $fact_hash{$fact} += 1; + if ($fact_hash{$fact}== 2) { + $is_ok =0; + last; + } + } + + push @result, $i if $is_ok; + } + return join ', ', @result; + +} + +print get_sq_free_int(500)."\n"; + +use Test::More; + +is(get_sq_free_int(30), '1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30'); +done_testing; diff --git a/challenge-150/lubos-kolouch/python/ch-1.py b/challenge-150/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..131db696a6 --- /dev/null +++ b/challenge-150/lubos-kolouch/python/ch-1.py @@ -0,0 +1,11 @@ +def get_fib_word(word1: str, word2: str): + """Generate the Fibonacci word""" + + while len(word2) < 51: + new_word = word1 + word2 + word1, word2 = word2, new_word + + return word2[50] + + +assert get_fib_word("1234", "5678") == "7" diff --git a/challenge-150/lubos-kolouch/python/ch-2.py b/challenge-150/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..cd2fc56bbc --- /dev/null +++ b/challenge-150/lubos-kolouch/python/ch-2.py @@ -0,0 +1,24 @@ +from sympy.ntheory import factorint + + +def get_sq_free_int(limit: int): + """Get the none-sqare factors number""" + result = [] + + for i in range(1, limit + 1): + factors = factorint(i) + + if any(value > 1 for value in factors.values()): + continue + + result.append(str(i)) + + return ", ".join(result) + + +print(get_sq_free_int(500)) + +assert ( + get_sq_free_int(30) + == "1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30" +) |
