Welcome To baselogics.blogspot.in

Welcome to baselogics.blogspot.com

Place to Learn Programmes.

Bits and Bytes....

Computer Scientists Love Their Algorithms and Data Structures

Explore all new Mathematical Puzzles......

Jasper Roberts - Blog
Showing posts with label Triangle puzzle. Show all posts
Showing posts with label Triangle puzzle. Show all posts

Thursday, September 4, 2014

Programming Puzzle Problem

Triangular Vertices

Consider the points on an infinite grid of equilateral triangles as shown 
below:
               x
              x x
             x x x
            x x x x
           x x x x x
               .
               .


Note that if we number the points from left to right and top to bottom, 
then groups of these points form the vertices of certain geometric shapes. For 
example, the sets of points {1,2,3} and {7,9,18} are the vertices of 
triangles, the sets {11,13,26,24} and {2,7,9,18} are the vertices of 
parallelograms, and the sets {4,5,9,13,12,7} and {8,10,17,21,32,34} are the 
vertices of hexagons.

Write a program which will repeatedly accept a set of points on this 
triangular grid, analyze it, and determine whether the points are the vertices 
of one of the following acceptable figures: triangle, parallelogram, or 
hexagon. In order for a figure to be acceptable, it must meet the following 
two conditions:
      1) Each side of the figure must coincide with an edge in the grid.
and   2) All sides of the figure must be of the same length.