diff options
Diffstat (limited to 'challenge-326/duncan-c-white/README')
| -rw-r--r-- | challenge-326/duncan-c-white/README | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/challenge-326/duncan-c-white/README b/challenge-326/duncan-c-white/README new file mode 100644 index 0000000000..8cb1e349ee --- /dev/null +++ b/challenge-326/duncan-c-white/README @@ -0,0 +1,76 @@ +Task 1: Sorted Matrix + +You are given a n x n matrix where n >= 2. +Write a script to find 3rd smallest element in the sorted matrix. + +Example 1 + + Input: @matrix = [3, 1, 2], [5, 2, 4], [0, 1, 3] + Output: 1 + + The sorted list of the given matrix: 0, 1, 1, 2, 2, 3, 3, 4, 5. + The 3rd smallest of the sorted list is 1. + +Example 2 + + Input: @matrix = ([2, 1], [4, 5]) + Output: 4 + + The sorted list of the given matrix: 1, 2, 4, 5. + The 3rd smallest of the sorted list is 4. + +Example 3 + + Input: @matrix = ([1, 0, 3], [0, 0, 0], [1, 2, 1]) + Output: 0 + + The sorted list of the given matrix: 0, 0, 0, 0, 1, 1, 1, 2, 3. + The 3rd smallest of the sorted list is 0. + +MY NOTES: So basically flatten the matrix onto an array, sort it, +pick out element 2.. easy. BTW, why does the matrix have to be square, +any matrix could be flattened and sorted. + +GUEST LANGUAGE: As a bonus, I've had a go at translating ch-1.pl into C, +look in the C/ directory for that. + + +Task 2: Max Number + +You are given a list of positive integers. +Write a script to concatenate the integers to form the highest possible value. + +Example 1: + + Input: @list = (1, 23) + Output: 231 + +Example 2: + + Input: @list = (10, 3, 2) + Output: 3210 + +Example 3: + + Input: @list = (31, 2, 4, 10) + Output: 431210 + +Example 4: + + Input: @list = (5, 11, 4, 1, 2) + Output: 542111 + +Example 5: + + Input: @list = (1, 10) + Output: 110 + +MY NOTES: First thought: try all combinations. Second thought: hang on, +don't we always pick the number with the biggest initial digit, and if +there's a tie, pick from the numbers with the biggest initial digit the +one with the biggest prefix? For example, if we vary example 4 to be: +Input: @list = (5, 12, 4, 1, 2), the output would be 542121, ie. 5-4-2-12-1. +Third thought: do I just mean "sort the numbers alphabetically"? + +GUEST LANGUAGE: As a bonus, I had a go at translating ch-2.pl into C, +look in the C/ directory for that. |
