Robbie Hatley's Solutions To The Weekly Challenge #285

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here:

The Weekly Challenge

The Weekly Challenge for the week of 2024-09-01 through 2024-09-07 is #285. Its tasks are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 285-1: "No Connection"
Submitted by: Mohammad Sajid Anwar
You are given a list of routes, @routes. Write a script to find
the destination with no further outgoing connection.

Example 1:
Input: @routes = (["B","C"], ["D","B"], ["C","A"])
Output: "A"
"D" -> "B" -> "C" -> "A".
"B" -> "C" -> "A".
"C" -> "A".
"A".

Example 2:
Input: @routes = (["A","Z"])
Output: "Z"

This is just a matter of checking for end destinations which do not also appear in other-than-last-place in the given routes. For loops and if statements will be involved.

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 285-2: "Making Change"
Submitted by: David Ferrone
Compute the number of ways to make change for a given value in
cents by using the coins Penny, Nickel, Dime, Quarter and
Half-dollar. Order of coin selection does not matter.
A penny (P) is equal to 1 cent.
A nickel (N) is equal to 5 cents.
A dime (D) is equal to 10 cents.
A quarter (Q) is equal to 25 cents.
A half-dollar (H) is equal to 50 cents.

Example 1:
Input: $amount = 9
Ouput: 2
1: 9P
2: N + 4P

Example 2:
Input: $amount = 15
Ouput: 6
1: D + 5P
2: D + N
3: 3N
4: 2N + 5P
5: N + 10P
6: 15P

Example 3:
Input: $amount = 100
Ouput: 292

This task is a bit more complicated than the first, but not really hard. The trick is to first consider what numbers of half-dollars one can use; then for each of those numbers, what numbers of quarters one can use; then for each of those numbers, what numbers of dimes one can use; then for each of those numbers, what numbers of nickels one can use; then the number of pennies needed will be forced by those 4 numbers. Nested for loops makes this easy.

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

That's it for challenge 285; see you on challenge 286!

Comments

Popular posts from this blog

Robbie Hatley's Solutions To The Weekly Challenge #262

Robbie Hatley's Solutions To The Weekly Challenge #239

Robbie Hatley's Solutions To The Weekly Challenge #266