Third Highest
Task
You are given an array of integers.
Write a script to find out the Third Highest if found otherwise return the maximum.
Solution
|
|
Discussion
The task does not state that the list consists of unique numbers, so it makes sense to create a list of unique elements before sorting:
|
|
After sorting we need to check the number of elements in the list. This is done using the ternary operator:
|
|
The rest of the script uses Raku’s special handling of the MAIN
subroutine.
Supplying no arguments or test
runs the examples from the
challenge website
The third multi sub MAIN
accepts an arbitrary number of integers which the
user can supply on the command line.
Maximum XOR
Task
You are given an array of integers.
Write a script to find the highest value obtained by XORing any two distinct members of the array.
Solution
|
|