Skip to content

Latest commit

 

History

History

204-straight-lines

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Straight lines

Challenge Description:

It’s high time you remembered geometry lessons at school: graphs, coordinates, shapes, and others.
You have the coordinates of the points. The point location is determined by X and Y coordinate system. Your task is to count how many straight lines that will cross three or more points you can create.
For example, in the figure #1, the number of such lines is one, while in the figures #2 and #3, we can create two lines.

Figure 1

Input sample:

The first argument is a path to a file. Each line includes a test case with point coordinates that are separated by the pipe symbol '|'. Point coordinates might be negative; they are in a range from -20 to 20.

For example:

1 1 | 1 2 | 1 4 | 3 2
1 1 | 1 2 | 1 4 | 3 2 | 4 2
1 2 | 1 4 | 2 3 | 3 2 | 3 4

Output sample:

Print the number of lines that cross three or more points in a straight line.

For example:

1
2
2

Constraints:

  1. A straight line is a line that contains three or more coordinate points. That is, if you add a point with coordinates [2, 2] to the figure #2, there will be two straight lines anyway.
  2. Point coordinates can be in a range from -20 to 20.
  3. The number of test cases is 40.