diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-07-10 12:00:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-10 12:00:29 +0100 |
| commit | 729eb9bbb476e9ad29207de8640e555fb65e400d (patch) | |
| tree | 7ca06982dadafc78a86c920fd8d090aed69c75d2 | |
| parent | f110580d06fcb571490efd2390ec208321a58b6d (diff) | |
| parent | ab2fa0617e62b569534ba452cbb211075c48c5c6 (diff) | |
| download | perlweeklychallenge-club-729eb9bbb476e9ad29207de8640e555fb65e400d.tar.gz perlweeklychallenge-club-729eb9bbb476e9ad29207de8640e555fb65e400d.tar.bz2 perlweeklychallenge-club-729eb9bbb476e9ad29207de8640e555fb65e400d.zip | |
Merge pull request #357 from kolcon/lubos_kolouch_16
LK Challenges 16
| -rw-r--r-- | challenge-016/lubos-kolouch/perl5/ch-1.pl | 58 | ||||
| -rw-r--r-- | challenge-016/lubos-kolouch/perl5/ch-2.pl | 56 |
2 files changed, 114 insertions, 0 deletions
diff --git a/challenge-016/lubos-kolouch/perl5/ch-1.pl b/challenge-016/lubos-kolouch/perl5/ch-1.pl new file mode 100644 index 0000000000..da168eb73d --- /dev/null +++ b/challenge-016/lubos-kolouch/perl5/ch-1.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: 2019_16_1.pl +# +# USAGE: ./2019_65_1.pl +# +# DESCRIPTION: Perl Weekly challenge w16 #1 +# +# At a party a pie is to be shared by 100 guest. The first guest gets 1% of the pie, the second guest gets 2% of the remaining pie, the third gets 3% of the remaining pie, the fourth gets 4% and so on. +# +# Write a script that figures out which guest gets the largest piece of pie. +# Write a script to generate first 10 strong and weak prime numbers. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# REVISION: --- +#=============================================================================== + +use warnings; +use strict; +use feature qw{ say }; + +my $pie_left = 1; +my $max_portion = 0; + +sub get_portion { + my $pie = shift; + my $n = shift; + + return $pie * $n / 100; +} + +for my $n (1..100) { + + my $portion = get_portion( $pie_left, $n ); + + if ( $portion < $max_portion ) { + $n--; + say 'Biggest portion has guest '. $n .' , portion size '.sprintf("%.2f%%\n",$max_portion*100); + last; + } + + $max_portion = $portion; + $pie_left -= $portion; +} + +use Test::More; + +is( get_portion( 1, 1 ), 0.01, 'test if rest 1 == 0.01' ); +is( get_portion( 2, 99 / 100 ), 99 / 100 * 2 / 100, 'test if rest 2 == 0.02*99' ); + +done_testing(); diff --git a/challenge-016/lubos-kolouch/perl5/ch-2.pl b/challenge-016/lubos-kolouch/perl5/ch-2.pl new file mode 100644 index 0000000000..4acdab2df1 --- /dev/null +++ b/challenge-016/lubos-kolouch/perl5/ch-2.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: 2019_16_2.pl +# +# USAGE: ./2019_16_2.pl +# +# DESCRIPTION: Perl Weekly challenge w16 #2 +# Write a script to validate a given bitcoin address. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 07/02/2019 09:47:38 PM +# REVISION: --- +#=============================================================================== + +use warnings; +use strict; +use feature qw{ say }; +use WWW::Mechanize; + +sub is_valid_bitcoin { + my $test_id = shift; + + my $mech = WWW::Mechanize->new; + $mech->get( 'https://cointools.org/valid-address-checker/?address=' . $test_id ); + + return 'valid' if $mech->content =~ /is\h+a\h+valid\h+bitcoin\h+address/msx; + return 'invalid'; +} + +# ----------- MAIN ---------- + +my $test_address = shift // die 'No bitcoin address passed'; + +say "$test_address address is " . is_valid_bitcoin($test_address); + +# ----------- TESTS ---------- +use Test::More; + +is( is_valid_bitcoin('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2'), + 'valid', 'test valid 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2' ); +is( is_valid_bitcoin('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy'), + 'valid', 'test valid 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy' ); + +is( is_valid_bitcoin('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN3'), + 'invalid', 'test invalid 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN3' ); +is( is_valid_bitcoin('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLi'), + 'invalid', 'test invalid 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLi' ); + +done_testing(); |
