Thanks for your reorganization of the code. You need: load'plot'
To see the results use: dolindaplots '' All the different cases will appear sooner or later. I was trying to avoid using explicit definitions which means that you must not use control structures. This was my own restriction which I seemed unable to achieve very successfully Each of the plots has a third point, and the next problem is to divide the square in three parts which show the areas that are closest to each of the three points. If possible, eventually extend to 8 points, as I did in the viewmat example, or even beyond. The code for the viewmat solution is based on a finite lattice of points. This approach involves an infinite collection of points. I think an area approach conveys the concept better than the lattice approach. The many examples of the voronoi problem found on wiki or the web are based upon lattices. My solution is similar to many of my strategies. I tend to think of how to start to develop a concept with high school students. Thus, especially in this case, it is simplistic. I really am using J as a tool for teaching mathematics. This problem would be probably more interesting to consider than some of the Euclidean proofs that are so much of the focus of geometry. However, I do think the problem is worth pushing forward as the real applications seem to apply to area rather than to lattices. I look forward to images which divide the region into three parts and beyond. Linda -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Mike Day Sent: Monday, July 23, 2012 10:28 AM To: [email protected] Subject: Re: [Jprogramming] Challenge 13 Plot Alot Is this the sort of thing you wanted? It's pretty simple- minded and hardly worth bothering you or the Forum with.... code follows my sign-off. usage: dolindaplot '' output: the plot you want and an smoutput line showing which mask won. Please note that I'm censoring earlier messages below. Mike dolindadata =: 3 : 0 NB. Globals still global P=:1+?(2,8)$6 Q=:0 1{"1 P MID=:-:+/"1 Q MP=:-%/-/"1 Q X1=:0 Y1=:(MP*( X1- 0{MID)) + 1{MID Y2=:7 X2=:(Y2+(MP*0{MID)-1{MID)%MP X3=:7 Y3=:(MP*( X3- 0{MID)) + 1{MID Y4=:0 X4=:(Y4+(MP*0{MID)-1{MID)%MP V=:Y1,X2,Y3,X4 POS=:(2=+/"1#:i.16)##:i.16 R=:|:(0,0,0, X2,7,7, 7,X4),.0,Y1,7,7, 7 , Y3,0,0 S=:(*./"2 (0<:R)*. R<:7)#"1 R Y1=:(0>.Y1) Y1=:(Y1<.7) X2=:(0>.X2) T1=:6($"1)3 5 4 {"1 S T2=:6($"1)3 5 0 1 2 {"1 S T3=:6($"1)5 2 3 4 {"1 S T4=:6($"1)5 2 1 0 {"1 S T5=:6($"1)2 4 3 {"1 S T6=:6($"1)2 4 5 0 1 {"1 S T7=:6($"1)1 5 0 {"1 S T8=:6($"1)1 5 4 3 2 {"1 S T9=:6($"1)1 4 3 2{"1 S T10=:6($"1)1 4 5 0 {"1 S T11=:6($"1)3 1 2 {"1 S T12=:6($"1)3 1 0 5 4 {"1 S T=:(T1,T2);(T3,T4);(T5,T6);(T7,T8);(T9,T10);(T11,T12) TESTVP =: *./"1((0<:V)*.V<:7)="1 POS ) dolindaplots=: 3 : 0 # dolindadata 1 for_i. i.#T do. dat =.(<"2)>2 2$0 2 1 3 { >i{T mask =. 1 i} 0#~#T if. *./ mask = TESTVP do. lindaplot dat;P smoutput mask end. end. '' ) lindaplot =: 3 : 0 'dat P'=. y pd 'reset' pd 'aspect 1' pd 'type poly' pd 'itemcolor blue, yellow, green, red' pd dat pd 'type marker' pd 'markersize 1.2' pd 'itemcolor black' pd (<"1) 0 1 2{"1 P pd 'show' ) On 23/07/2012 11:39 AM, Linda Alvord wrote: > Can you help me show only the correct solution for this code. It is > the one image that is preceded by a 1. Any simplifications would be fun too. > > load 'plot' > pd 'reset' > P=:1+?(2,8)$6 > Q=:0 1{"1 P > MID=:-:+/"1 Q > MP=:-%/-/"1 Q > X1=:0 > Y1=:(MP*( X1- 0{MID)) + 1{MID > Y2=:7 > X2=:(Y2+(MP*0{MID)-1{MID)%MP > X3=:7 > Y3=:(MP*( X3- 0{MID)) + 1{MID > Y4=:0 > X4=:(Y4+(MP*0{MID)-1{MID)%MP > V=:Y1,X2,Y3,X4 > POS=:(2=+/"1#:i.16)##:i.16 > R=:|:(0,0,0, X2,7,7, 7,X4),.0,Y1,7,7, 7 , Y3,0,0 > S=:(*./"2 (0<:R)*. R<:7)#"1 R > Y1=:(0>.Y1) > Y1=:(Y1<.7) > X2=:(0>.X2) > T1=:6($"1)3 5 4 {"1 S > T2=:6($"1)3 5 0 1 2 {"1 S > T3=:6($"1)5 2 3 4 {"1 S > T4=:6($"1)5 2 1 0 {"1 S > T5=:6($"1)2 4 3 {"1 S > T6=:6($"1)2 4 5 0 1 {"1 S > T7=:6($"1)1 5 0 {"1 S > T8=:6($"1)1 5 4 3 2 {"1 S > T9=:6($"1)1 4 3 2{"1 S > T10=:6($"1)1 4 5 0 {"1 S > T11=:6($"1)3 1 2 {"1 S > T12=:6($"1)3 1 0 5 4 {"1 S > dat=:(<"2)>2 2$0 2 1 3 { T1,T2 > 'aspect 1'plot dat > P > V > ]*./ 1 0 0 0 0 0=*./"1((0<:V)*.V<:7)="1 POS pd 'type poly' > pd 'itemcolor blue, yellow, green, red' > pd dat > pd 'type marker' > pd 'markersize 1.2' > pd 'itemcolor black' > pd (<"1) 0 1 2{"1 P > pd 'show' > ]*./ 0 1 0 0 0 0=*./"1((0<:V)*.V<:7)="1 POS > dat=:(<"2)>2 2$0 2 1 3 { T3,T4 > pd 'type poly' > pd 'itemcolor blue, yellow, green, red' > pd dat > pd 'type marker' > pd 'markersize 1.2' > pd 'itemcolor black' > pd (<"1) 0 1 2{"1 P > pd 'show' > ]*./ 0 0 1 0 0 0=*./"1((0<:V)*.V<:7)="1 POS > dat=:(<"2)>2 2$0 2 1 3 { T5,T6 > pd 'type poly' > pd 'itemcolor blue, yellow, green, red' > pd dat > pd 'type marker' > pd 'markersize 1.2' > pd 'itemcolor black' > pd (<"1) 0 1 2{"1 P > pd 'show' > ]*./ 0 0 0 1 0 0=*./"1((0<:V)*.V<:7)="1 POS > dat=:(<"2)>2 2$0 2 1 3 { T7,T8 > pd 'type poly' > pd 'itemcolor blue, yellow, green, red' > pd dat > pd 'type marker' > pd 'markersize 1.2' > pd 'itemcolor black' > pd (<"1) 0 1 2{"1 P > pd 'show' > ]*./ 0 0 0 0 1 0=*./"1((0<:V)*.V<:7)="1 POS > ]dat=:(<"2)>2 2$0 2 1 3 { T9,T10 > pd 'type poly' > pd 'itemcolor blue, yellow, green, red' > pd dat > pd 'type marker' > pd 'markersize 1.2' > pd 'itemcolor black' > pd (<"1) 0 1 2{"1 P > pd 'show' > ]*./ 0 0 0 0 0 1=*./"1((0<:V)*.V<:7)="1 POS > dat=:(<"2)>2 2$0 2 1 3 { T11,T12 > pd 'type poly' > pd 'itemcolor blue, yellow, green, red' > pd dat > pd 'type marker' > pd 'markersize 1.2' > pd 'itemcolor black' > pd (<"1) 0 1 2{"1 P > pd 'show' > > Linda > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
