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
|
Challenge 1: "Write a script to find the intersection of two straight
lines. The co-ordinates of the two lines should be provided as command
line parameter. For example:
The two ends of Line 1 are represented as co-ordinates (a,b) and (c,d).
The two ends of Line 2 are represented as co-ordinates (p,q) and (r,s).
The script should print the co-ordinates of point of intersection of
the above two lines."
My notes: Clearly defined, very easy if I can remember the formulae - let's
have a go.. after doing it, I decided to run Gnuplot to display the results
as it's an intensely graphical concept..
Challenge 2: "Write a script that allows you to capture/display historical
data. It could be an object or a scalar. For example
my $x = 10; $x = 20; $x -= 5;
After the above operations, it should list $x historical value in order."
My notes: The idea is easy, but we're not told the API to implement. I'm
certainly not going to introspect into Perl to find out whenever a scalar
variable is assigned to! I have chosen to implement this for numeric
variables, using an input sequence of VARNAME OP VALUE triples (where OP='=',
'+=', '-=', '*=', '/=' or '%='), where each input triple N occurs at time N,
and we track the historic value of each variable over time.
I did that, using __DATA__ (at the end of this file) for the default sequence,
or the contents of a named input file if given.
I also graphed the time-series results via Gnuplot as I seem to be having
a Gnuplot kick this week:-) It's not really the ideal output format, but
it's relatively cute.
|