Re: HHC 2012 RPL Programming Contest, and a not-so-Mini Challenge Message #26 Posted by C.Ret on 26 Sept 2012, 9:32 a.m., in response to message #25 by Werner
Quote:
If the entry list was a list of complex points, it would be easy:
I agree with that !
But, we have to recognised that we are not far from it, a couple of instructions will do it!
Please consider the following trace :
PROGRAM STEPS STACK AND DISPLAY
-------------------- ---------------------------------------
« 1: { 1 1 0 0 2 3 3 4 1 0 }
LIST-> 11: 1
10: 1
9: 0
8: 0
7: 2
6: 3
5: 3
4: 4
3: 1
2: 0
1: 10.
2. / 11: 1
10: 1
9: 0
8: 0
7: 2
6: 3
5: 3
4: 4
3: 1
2: 0
1: 5.
-> n « 10: 1
9: 1
8: 0
7: 0
6: 2
5: 3
4: 3
3: 4
2: 1
1: 0
{ n 2 } ->ARRY 1: [[ 1 1 ]
[ 0 0 ]
[ 2 3 ]
[ 3 4 ]
[ 1 0 ]]
[ (1,0) (0,1) ] 2: [[ 1 1 ][ 0 0 ][ 2 3 ][ 3 4 ][ 1 0]]
1: [ (1,0) (0,1) ]
* 1: [(1,1) (0,0) (2,3) (3,4) (1,0)]
-> D « 0 1: 0
1 n FOR i 1: 0
D 2: 0
1: [(1,1) (0,0) (2,3) (3,4) (1,0)]
DUP DUP 4: 0
3: [(1,1) (0,0) (2,3) (3,4) (1,0)]
2: [(1,1) (0,0) (2,3) (3,4) (1,0)]
1: [(1,1) (0,0) (2,3) (3,4) (1,0)]
i GET CON 3: 0
2: [(1,1) (0,0) (2,3) (3,4) (1,0)]
1: [(1,1) (1,1) (1,1) (1,1) (1,1)]
- 2: 0
1: [(0,0) (-1,-1) (1,2) (2,3) (0,-1)]
RNRM 2: 0
1: 3.60555127546
MAX 1: 3.60555127546
NEXT 1: 3.60555127546
D 2: 3.60555127546
1: [(1,1) (0,0) (2,3) (3,4) (1,0)]
DUP DUP 4: 3.60555127546
3: [(1,1) (0,0) (2,3) (3,4) (1,0)]
2: [(1,1) (0,0) (2,3) (3,4) (1,0)]
1: [(1,1) (0,0) (2,3) (3,4) (1,0)]
i GET CON 3: 3.60555127546
2: [(1,1) (0,0) (2,3) (3,4) (1,0)]
1: [(0,0) (0,0) (0,0) (0,0) (0,0)]
- 2: 3.60555127546
1: [(1,1) (0,0) (2,3) (3,4) (1,0)]
RNRM 2: 3.60555127546
1: 5.
MAX 1: 5.
NEXT 1: 5.
.........
RNRM 2: 5.
1: 4.472135955
MAX 1: 5.
NEXT 1: 5.
» » » 1: 5.
-------------------- ---------------------------------------
« LIST-> 2 / -> n
« { n 2 } ->ARRY [ 1 (0,1) ] * -> D
« 0
1 n FOR i
D DUP DUP i GET CON - RNRM MAX NEXT
»
»
»
The initial list is easely converted into a row array contening the coordinate of the points as complex coordinates by the two first line of the code.
Edited: 26 Sept 2012, 9:39 a.m.
|