aboutsummaryrefslogtreecommitdiff
path: root/challenge-115/duncan-c-white/README
blob: d6cdf5924e21f7a211b08ae3977596b214cb3414 (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
Task 1: "String Chain

You are given an array of strings.

Write a script to find out if the given strings can be chained to form
a circle. Print 1 if found otherwise 0.

A string $S can be put before another string $T in circle if the last
character of $S is same as first character of $T.

Examples:

  Input: @S = ("abc", "dea", "cd")
  Output: 1 as we can form circle e.g. "abc", "cd", "dea".

  Input: @S = ("ade", "cbd", "fgh")
  Output: 0 as we can't form circle.
"

My notes: word chains are often quite hard. HOWEVER, this time it's a circular word chain
using ALL the words, so that's much easier:
1. we don't have to try "what if we start with this word (for each word)", just pick one.
2. we must use every word.

(2) also implies an obvious shortcut to speed up failure (0) case:
fail if numwords(starting_with_a_letter) != numwords(ending_with_that_letter).
But I don't think I need implement that.


Task 2: "Largest Multiple (Even)

You are given a list of positive integers (0-9), single digit.

Write a script to find the largest multiple of 2 that can be formed from the list.

Examples

  Input: @N = (1, 0, 2, 6)
  Output: 6210

  Input: @N = (1, 4, 2, 8)
  Output: 8412

  Input: @N = (4, 1, 7, 6)
  Output: 7614
"

My notes: should be easy (multiple of 2 == even number).  Obvious heuristic is: put biggest digit
first, but I suppose it's possible that no even numbers would result.  Hell, just try all perms..