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
|
Task 1: Special Bit Characters
You are given an array of binary bits that ends with 0.
Valid sequences in the bit string are:
[0] -decodes-to-> "a"
[1, 0] -> "b"
[1, 1] -> "c"
Write a script to print 1 if the last character is an 'a' otherwise
print 0.
Example 1
Input: @bits = (1, 0, 0)
Output: 1
The given array bits can be decoded as 2-bits character (10) followed
by 1-bit character (0).
Example 2
Input: @bits = (1, 1, 1, 0)
Output: 0
Possible decode can be 2-bits character (11) followed by 2-bits
character (10) i.e. the last character is not 1-bit character.
MY NOTES: very easy. decode string then check last letter of decoded version.
I wonder if there's a way of decoding-and-checking together, though.
GUEST LANGUAGE: As a bonus, I also had a go at translating ch-1.pl into C
(look in the C directory for that).
Task 2: Merge Account
You are given an array of accounts i.e. name with list of email addresses.
Write a script to merge the accounts where possible. The accounts can
only be merged if they have at least one email address in common.
Example 1:
Input: @accounts = [ ["A", "a1@a.com", "a2@a.com"],
["B", "b1@b.com"],
["A", "a3@a.com", "a1@a.com"] ]
]
Output: [ ["A", "a1@a.com", "a2@a.com", "a3@a.com"],
["B", "b1@b.com"] ]
Example 2:
Input: @accounts = [ ["A", "a1@a.com", "a2@a.com"],
["B", "b1@b.com"],
["A", "a3@a.com"],
["B", "b2@b.com", "b1@b.com"] ]
Output: [ ["A", "a1@a.com", "a2@a.com"],
["A", "a3@a.com"],
["B", "b1@b.com", "b2@b.com"] ]
MY NOTES: fiddly and rather inelegant, especially only being allowed to
merge two entries if the intersection of the email lists is non empty.
Will also need to choose an input format, how about a list of words of the
form A:a1@a.com,a2@a.com, B:b1@b.com, A:a3@a.com and B:b2@b.com,b1@b.com
GUEST LANGUAGE: As a bonus, I also had a go at translating ch-2.pl into C
(look in the C directory for that)
|