aboutsummaryrefslogtreecommitdiff
path: root/challenge-200/duncan-c-white/README
blob: 280aa5aefd53d70cf49baf86e2fb068886fc321b (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
Task 1: Arithmetic Slices

You are given an array of integers.

Write a script to find out all Arithmetic Slices for the given array
of integers.  An integer array is called arithmetic if it has at least
3 elements and the differences between any three consecutive elements
are the same.


Example 1

Input: @array = (1,2,3,4)
Output: (1,2,3), (2,3,4), (1,2,3,4)

Example 2

Input: @array = (2)
Output: () as no slice found.


MY NOTES: pretty easy.  generate and test: generate all subarrays of len > 2
via two nested for loops.  then test for all-elements-one-apart.  (Actually,
that's not quite what the spec said, but I noticed that too late).

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: Seven Segment 200
Submitted by: Ryan J Thompson

A seven segment display is an electronic component, usually used to
display digits. The segments are labeled 'a' through 'g' as shown:

      a
     --- 
    |   |
  f |   | b
    | g |
     --- 
    |   |
  e |   | c
    | d |
     --- 
  
Seven Segment

The encoding of each digit can thus be represented compactly as a truth table:

my @truth = qw<abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg>;

For example, $truth[1] = "bc". The digit 1 would have segments "b" and "c"
enabled.

Write a program that accepts any decimal number and draws that number as a horizontal sequence of ASCII seven segment displays, similar to the following:

-------  -------  -------
      |  |     |  |     |
      |  |     |  |     |
-------
|        |     |  |     |
|        |     |  |     |
-------  -------  -------

To qualify as a seven segment display, each segment must be drawn (or
not drawn) according to your @truth table.

The number "200" was of course chosen to celebrate our 200th week!

MY NOTES: not quite so easy, but doable.

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)