aboutsummaryrefslogtreecommitdiff
path: root/challenge-093/duncan-c-white/README
blob: 895ec1ea71bdff8de2abbed27b2e6056898b406f (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
Task 1: "Max Points

You are given set of co-ordinates @N.

Write a script to count maximum points on a straight line when given co-ordinates plotted on 2-d plane.

Example 1:

	|
	|     x
	|   x
	| x
	+ _ _ _ _

	Input: (1,1), (2,2), (3,3)
	Output: 3

Example 2:

	|
	|
	| x       x
	|   x
	| x   x
	+ _ _ _ _ _

	Input: (1,1), (2,2), (3,1), (1,3), (5,3)
	Output: 3
"

My notes: hmm.. I can't see an obvious way to do this cleanly.  Some thought needed.
Perhaps try every pair of points, make a line, then check all remaining points to
see if they're on that same line?  Sounds like quite a lot of work.  Also, how does
one element of @N store an (X,Y) point?


Task 2: "Sum Path

You are given binary tree containing numbers 0-9 only.

Write a script to sum all possible paths from root to leaf.

Example 1:

	Input:
	     1
	    /
	   2
	  / \
	 3   4

	Output: 13
	as sum two paths (1->2->3) and (1->2->4)

Example 2:

	Input:
	     1
	    / \
	   2   3
	  /   / \
	 4   5   6

	Output: 26
	as sum three paths (1->2->4), (1->3->5) and (1->3->6)
"

My notes: interesting.  No notes on how to represent binary tree, or how
to input it from the command line, but I think we did this in an earlier task.
Oh yes, challenge 56 was also about path summing over binary trees, but that time
we were looking for a specific path sum, whereas now we're summing all the path sums..
so let's reuse most of that mechanism.