brewersfan1976

is_info_consistent.rb

May 21st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.79 KB | None | 0 0
  1. def isInformationConsistent(evidences)
  2.     x = 0
  3.     y = 0
  4.     x_length = evidences.length
  5.     y_length = evidences[0].length
  6.     verdict = 0
  7.  
  8.     while (y < y_length)
  9.       while (x < x_length)
  10.             if evidences[x][y] == 1 and verdict == -1 then
  11.                return false
  12.             end
  13.              
  14.             if evidences[x][y] == -1 and verdict == 1 then
  15.                return false
  16.             end
  17.              
  18.             if evidences[x][y] == 1 then
  19.                verdict = 1
  20.             end
  21.              
  22.             if evidences[x][y] == -1 then
  23.                verdict = -1
  24.             end
  25.              
  26.             x = x + 1
  27.         end
  28.        
  29.         y = y + 1
  30.         x = 0
  31.         verdict = 0        
  32.     end
  33.              
  34.     return true
  35. end
Advertisement
Add Comment
Please, Sign In to add comment