aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/duncan-c-white/README
blob: 8cb1e349ee305bf7ed5a4e96d3d68c2b9d8e6152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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.