aboutsummaryrefslogtreecommitdiff
path: root/challenge-143/duncan-c-white/README
blob: 917ee497cbd9119716f709fa72f9e8dff8a41e19 (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
TASK #1 - Calculator

You are given a string, $s, containing mathematical expression.

Write a script to print the result of the mathematical expression. To
keep it simple, please only accept + - * ().

Example 1:

    Input: $s = "10 + 20 - 5"
    Output: 25

Example 2:

    Input: $s = "(10 + 20 - 5) * 2"
    Output: 50

MY NOTES: Ok, so a mini parser of a string in one or more command
   line arguments.   What's the easiest way?
   - use Parse::RecDescent?
   - hand write a recursive descent parser?
   - convert to RPN and evaluate RPN?


TASK #2 - Stealthy Number

You are given a positive number, $n.

Write a script to find out if the given number is Stealthy Number.

A positive integer N is stealthy, if there exist positive integers
a, b, c, d such that a * b = c * d = N and a + b = c + d + 1.

Example 1

	Input: $n = 36
	Output: 1

	Since 36 = 4 (a) * 9 (b) = 6 (c) * 6 (d) and
	4 (a) + 9 (b) = 6 (c) + 6 (d) + 1.

Example 2

	Input: $n = 12
	Output: 1

	Since 2 * 6 = 3 * 4 and 2 + 6 = 3 + 4 + 1

Example 3

	Input: $n = 6
	Output: 0

	Since 2 * 3 = 1 * 6 but 2 + 3 != 1 + 6 + 1


MY NOTES: hmm..  need some kind of brute force search, presumably.
what are the limits of a..d?  first thought: each <= $n,
hang on, (a,b) must be a factor pair of n (where a is a factor of n
<= sqrt(n) and b is n/a), and (c,d) must also be a factor pair of n.

As a bonus, I've also implemented the --firstn flag which makes it
find and display the first $n stealthy numbers.