aboutsummaryrefslogtreecommitdiff
path: root/challenge-198/duncan-c-white/README
blob: dffa7605cf90e5ee6f0f4de12d16adc4e68ae0bb (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
Task 1: Max Gap

You are given a list of integers, @list.

Write a script to find the total pairs in the sorted list where 2
consecutive elements has the max gap. If the list contains less then 2
elements then return 0.

Example 1

Input:  @list = (2,5,8,1)
Output: 2

Since the sorted list (1,2,5,8) has 2 such pairs (2,5) and (5,8)

Example 2

Input: @list = (3)
Output: 0


MY NOTES: very easy.  sort, then sequence through the sorted list,
finding the max gap so far and all pairs with that gap.

GUEST LANGUAGE: As a bonus, I also had a go at translating ch-1.pl
into C (look in the C directory for the translation)


Task 2: Prime Count

You are given an integer $n > 0.

Write a script to print the count of primes less than $n.
Example 1

Input: $n = 10
Output: 4 as in there are 4 primes less than 10 are 2, 3, 5 ,7.

Example 2

Input: $n = 15
Output: 6

Example 3

Input: $n = 1
Output: 0

Example 4

Input: $n = 25
Output: 9

MY NOTES: very easy, specially if you have a prime finding module lying
around:-)

GUEST LANGUAGE: As a bonus, I also had a go at translating ch-2.pl
into C (look in the C directory for the translation)