Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #016 (“Pythagoras Pie Puzzle” and “Validating Bitcoin Addresses”)

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge

The tasks for challenge #016 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 016-1: Pythagoras Pie Puzzle
Proposed by Jo Christian Oterhals.
At a party a pie is to be shared by 100 guests. 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.

I simply performed the calculations described. What happened, I found surprising.

Robbie Hatley's Perl Solution to The Weekly Challenge 016-1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 016-2: Validating Bitcoin Addresses
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,
see here: https://en.bitcoin.it/wiki/Address
Here are some valid bitcoin addresses:
1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy

This was rather elaborate, involving conversion from base 58 to base 16, custom collation sequences, packing, unpacking, and two iterations of SHA-256 hashing.

Robbie Hatley's Perl Solution to The Weekly Challenge 016-2

Comments

Popular posts from this blog

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #347 (“Format Date” and “Format Phone”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #351 (“Special Average” and “Arithmetic Progression”)

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #357 (“Kaprekar Constant” and “Unique Fraction Generator”)