Post Reply 
Number of triangles Puzzle
07-11-2016, 05:00 PM (This post was last modified: 07-11-2016 05:30 PM by chromos.)
Post: #1
Number of triangles Puzzle
The program calculates the number of triangles in the geometrical figures.

Example 1:
How many triangles are in this puzzle?
   

a) First we mark every important point on every line (doesn't matter in which order):
   

b) Next we insert every line with their points as sublists into list L0 (doesn't matter in which order):
L0:= {
{1,2,3},
{1,4,5,6},
{6,10,9},
{3,7,8,9},
{5,11,12,13,14,15,7},
{6,16,17,13,18,19,3},
{2,4},
{4,11,16,20},
{20,21,14},
{14,18,23,2},
{22,19,15,8},
{8,10},
{10,21,17,12},
{12,23,22},
}

c) Now run the program. :-)
=====================

Example 2:
How many triangles are in this puzzle?
   

a) First we mark every important point on every line (doesn't matter in which order):
   

b) Next we insert every line with their points as sublists into list L0 (doesn't matter in which order):
L0:= {
{1,2,3},
{3,4,5,6},
{6,7,1},
{1,8,10,4},
{1,9,11,5},
{2,8,9,7},
{3,10,11,7}
}

c) Now run the program. :-)
=====================

PHP Code:
// The program calculates the number of triangles in the geometrical figures (puzzles).
// Mark all the vertices and intersections (i.e. number it).
// Write each straight line with all its points as sublist into L0 list.
// Example:
// Consider a triangle with its three medians.
// Fill list L0 as follows:
//L0(1):={1,2,5}
//L0(2):={1,3,7}
//L0(3):={1,4,6}
//L0(4):={2,4,7}
//L0(5):={3,4,5}
//L0(6):={5,6,7}
//Run the program, output will be in list L4 in which each sublist is one triangel with its vertices.

EXPORT NumOfTrianglesRiddle()
BEGIN
LOCAL count
:=0,p,q,r,s,t,u;
L1:={};
L2:={};
L3:={};
L4:={};
PRINT();
FOR 
p FROM 1 TO (SIZE(L0)-2) DO
 FOR 
q FROM (p+1TO (SIZE(L0)-1) DO
  FOR 
r FROM (q+1TO SIZE(L0) DO
   
L1:=L0(p);
   
L2:=L0(q);
   
L3:=L0(r);
   FOR 
s FROM 1 TO SIZE(L1) DO
    IF (
member(L1(s),L2)) THEN
     
FOR t FROM 1 TO SIZE(L2) DO
      IF (
member(L2(t),L3)) THEN
       
FOR u FROM 1 TO SIZE(L3) DO
        IF (
member(L3(u),L1)) THEN
         
IF (L1(s)<>L2(t) AND L2(t)<>L3(u) AND L3(u)<>L1(s)) THEN
          count
:=count+1;
          
L4(0):={L1(s),L2(t),L3(u)};
          
L4(count):=SORT(L4(count));
          PRINT(
count+":   "+L4(count,1)+" - "+L4(count,2)+" - "+L4(count,3));
         
END;
        
END;
       
END;
      
END;
     
END;
    
END;
   
END;
  
END;
 
END;
END;
PRINT(
"END");

END


Attached File(s)
.hpprgm  NumOfTrianglesRiddle.hpprgm (Size: 2.65 KB / Downloads: 6)

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)