GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — codility/triangle.rb at master · skillgrid/codility Expand file tree/ Copy pathtriangle.rbMore file actions 30 lines (24 loc) · 571 Bytes / Copy pathtriangle.rbFile metadata and controls30 lines (24 loc) · 571 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 # http://stackoverflow.com/a/7139391/233852 def triangle(a) a.sort! a.each_cons(3) do |a, b, c| next if c <= 0 return 1 if a + b > c end 0 end require 'minitest/autorun' class Tests < MiniTest::Unit::TestCase def test_example_input assert_equal 0, triangle([10, 50, 5, 1]) end def test_success assert_equal 1, triangle([10, 2, 5, 1, 8, 20]) end def test_success2 assert_equal 1, triangle([10,0, -10, 2, 5,5, 1, 8, 20]) end def test_large2 assert_equal 1, triangle([1] + 20.step(100_000, 2).to_a + [1, 5, 10]) end end |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |