Guest User

Untitled

a guest
Nov 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. require 'csv'
  3. x, y = [], []
  4. cnt = 0
  5. CSV.foreach("triangles.txt") {|row|
  6. x = [row[0], row[2], row[4]].map(&:to_i)
  7. y = [row[1], row[3], row[5]].map(&:to_i)
  8. cnt += 1 if [x[0]*y[1]-y[0]*x[1],
  9. x[1]*y[2]-y[1]*x[2],
  10. x[2]*y[0]-y[2]*x[0]].map {|e| e >= 0 ? true : false }.uniq.size == 1
  11. }
  12. p cnt
Add Comment
Please, Sign In to add comment