diff options
| -rw-r--r-- | challenge-016/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-016/paulo-custodio/python/ch-1.py | 32 | ||||
| -rw-r--r-- | challenge-016/paulo-custodio/python/ch-2.py | 25 | ||||
| -rw-r--r-- | challenge-016/paulo-custodio/t/test-1.yaml | 5 | ||||
| -rw-r--r-- | challenge-016/paulo-custodio/t/test-2.yaml | 30 | ||||
| -rw-r--r-- | challenge-016/paulo-custodio/test.pl | 27 |
6 files changed, 94 insertions, 27 deletions
diff --git a/challenge-016/paulo-custodio/Makefile b/challenge-016/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-016/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-016/paulo-custodio/python/ch-1.py b/challenge-016/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..e4ce675a5d --- /dev/null +++ b/challenge-016/paulo-custodio/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +# Challenge 016 +# +# Task #1 +# Pythagoras Pie Puzzle, proposed by Jo Christian Oterhals. +# +# 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. + +import operator + +class Slice(): + def __init__(self, guest, slice): + self.guest = guest + self.slice = slice + def __str__(self): + return f"Slice({self.guest}, {self.slice})" + +slices = [] +pie = 1 +for guest in range(1, 101): + slice = guest/100*pie + pie -= slice + slices.append(Slice(guest, slice)) +slices.sort(key=operator.attrgetter('slice')) +slice = slices[-1] + +print("Guest {} gets {:.4f}% of the pie.".format(slice.guest, 100*slice.slice)) diff --git a/challenge-016/paulo-custodio/python/ch-2.py b/challenge-016/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..dea3be6947 --- /dev/null +++ b/challenge-016/paulo-custodio/python/ch-2.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +# Challenge 016 +# +# Task #2 +# Write a script to validate a given bitcoin address. Most Bitcoin addresses +# are 34 characters. They consist of random digits and uppercase and lowercase +# letters, with the exception that the uppercase letter "O", uppercase letter "I", +# lowercase letter "l", and the number "0" are never used to prevent visual +# ambiguity. A bitcoin address encodes 25 bytes. The last four bytes are a +# checksum check. They are the first four bytes of a double SHA-256 digest +# of the previous 21 bytes. For more information, please refer wiki page. +# Here are some valid bitcoin addresses: +# +# 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 +# 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy + +import sys +from cryptoaddress import BitcoinAddress + +try: + bitcoin_address = BitcoinAddress(sys.argv[1], network_type='mainnet') + print(1) +except ValueError: + print(0) diff --git a/challenge-016/paulo-custodio/t/test-1.yaml b/challenge-016/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..a2751e2584 --- /dev/null +++ b/challenge-016/paulo-custodio/t/test-1.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: + input: + output: Guest 10 gets 6.2816% of the pie. diff --git a/challenge-016/paulo-custodio/t/test-2.yaml b/challenge-016/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..f45312b812 --- /dev/null +++ b/challenge-016/paulo-custodio/t/test-2.yaml @@ -0,0 +1,30 @@ +- setup: + cleanup: + args: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 + input: + output: 1 +- setup: + cleanup: + args: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy + input: + output: 1 +- setup: + cleanup: + args: 2BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 + input: + output: 0 +- setup: + cleanup: + args: 4J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy + input: + output: 0 +- setup: + cleanup: + args: 1lvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 + input: + output: 0 +- setup: + cleanup: + args: 3O98t1WpEZ73CNmQviecrnyiWrnqRhWNLy + input: + output: 0 diff --git a/challenge-016/paulo-custodio/test.pl b/challenge-016/paulo-custodio/test.pl deleted file mode 100644 index 1017049192..0000000000 --- a/challenge-016/paulo-custodio/test.pl +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/perl - -use Modern::Perl; -use Test::More; - -is capture("perl perl/ch-1.pl binary"), <<END; -Guest 10 gets 6.2816% of the pie. -END - -is capture("perl perl/ch-2.pl 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2"), "1\n"; -is capture("perl perl/ch-2.pl 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy"), "1\n"; - -is capture("perl perl/ch-2.pl 2BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2"), "0\n"; -is capture("perl perl/ch-2.pl 4J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy"), "0\n"; - -is capture("perl perl/ch-2.pl 1lvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2"), "0\n"; -is capture("perl perl/ch-2.pl 3O98t1WpEZ73CNmQviecrnyiWrnqRhWNLy"), "0\n"; - - -done_testing; - -sub capture { - my($cmd) = @_; - my $out = `$cmd`; - $out =~ s/[ \t\v\f\r]*\n/\n/g; - return $out; -} |
