aboutsummaryrefslogtreecommitdiff
path: root/challenge-132/duncan-c-white/README
blob: 4918f2b94ab2d6e7fada874d9cfd0e2c499d13f8 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
TASK #1 - Mirror Dates

You are given a date (yyyy/mm/dd).

Assuming, the given date is your date of birth. Write a script to find
the mirror dates of the given date.

Assuming today is 2021/09/22.

Example 1:

Input: 2021/09/18
Output: 2021/09/14, 2021/09/26

On the date you were born, someone who was your current age, would have
been born on 2021/09/14.  Someone born today will be your current age
on 2021/09/26.

Example 2:

Input: 1975/10/10
Output: 1929/10/27, 2067/09/05

On the date you were born, someone who was your current age, would have
been born on 1929/10/27.  Someone born today will be your current age
on 2067/09/05.

Example 3:

Input: 1967/02/14
Output: 1912/07/08, 2076/04/30

On the date you were born, someone who was your current age, would have
been born on 1912/07/08.  Someone born today will be your current age
on 2076/04/30.

MY NOTES: Sounds like a pretty easy date manipulation exercise:  dob - delta,
today + delta where delta = today - date.  The hardest part is working out
which Date manipulation module to use, as Perl has so many.


TASK #2 - Hash Join

Write a script to implement Hash Join algorithm as suggested by wikipedia.

1. For each tuple r in the build input R
    1.1 Add r to the in-memory hash table
    1.2 If the size of the hash table equals the maximum in-memory size:
        1.2.1 Scan the probe input S, and add matching join tuples to the output relation
        1.2.2 Reset the hash table, and continue scanning the build input R
2. Do a final scan of the probe input S and add the resulting join tuples to the output relation

Example

Input:

    @player_ages = (
        [20, "Alex"  ],
        [28, "Joe"   ],
        [38, "Mike"  ],
        [18, "Alex"  ],
        [25, "David" ],
        [18, "Simon" ],
    );

    @player_names = (
        ["Alex", "Stewart"],
        ["Joe",  "Root"   ],
        ["Mike", "Gatting"],
        ["Joe",  "Blog"   ],
        ["Alex", "Jones"  ],
        ["Simon","Duane"  ],
    );

Output:

    Based on index = 1 of @players_age and index = 0 of @players_name.

    20, "Alex",  "Stewart"
    20, "Alex",  "Jones"
    18, "Alex",  "Stewart"
    18, "Alex",  "Jones"
    28, "Joe",   "Root"
    28, "Joe",   "Blog"
    38, "Mike",  "Gatting"
    18, "Simon", "Duane"

MY NOTES: Ok, I think I understand, but I'm going to ignore the
whole "out of memory" part as that's too complicated.
Also, I can't see what logical order the example output is ordered by,
as far as I can see, the described algorithm leads to the order that I
produce - not the order the above example output shows; so I'm going to
ignore that too.  After all, in a relation, order doesn't matter, right?

So for the example I build %name2ages containing:
"Alex" => [20, 18],
"Joe" => [28],
"Mike" => [38],
"David" => [25],
"Simon" => [18].
Then use %name2ages while iterating over @player_names.

There's also the question of how to provide the relations,
in ch-2.pl I hard-coding them as arrays of pairs as shown above,
but see also ch-2a.pl which generalises them as files, read by Text::CSV
and containing fieldnames in row 1.