The Ruby Game

## the question is can you write the fastest or shortest code?
## do you dare to take on your peers in a game of speed?

View 3 comments about this challenge

  1. 31

    D171590f55d7e5b649500bcc6e828f1e normal

    Runs in 10.904119s 123 characters Submitted by jenseng on December 11th, 2013 18:00 +1

    require 'time'
    c=m=0
    l=nil
    quacks.split(", ").each{|d|
    t=Time.parse(d)
    c=[l&&t-l<=2?c+1:-1,1].max
    l=t
    m=c>m ?c:m}
    m
  2. 32

    D171590f55d7e5b649500bcc6e828f1e normal

    Runs in 11.308779s 99 characters Submitted by jenseng on December 11th, 2013 20:10 +1

    c=m=0;l=nil;quacks.split(?,).map{|d|t=DateTime.parse(d).to_time;c=l&&t-l<=2?c+1:1;l=t;m=c>m ?c:m};m
  3. 33

    D171590f55d7e5b649500bcc6e828f1e normal

    Runs in 11.517283s 119 characters Submitted by jenseng on December 11th, 2013 17:49 +1 2 similars

    c=m=0
    l=nil
    quacks.split(", ").each{|d|
    t=DateTime.parse(d).to_time
    c=[l&&t-l<=2?c+1:-1,1].max
    l=t
    m=c>m ?c:m}
    m
  4. 34

    3a9dd51ec1c341ca03a2cfac82cac1cd?d=https%3a%2f%2fidenticons.github.com%2fc379ff649730ae0eedf2ca808070bb6f

    Runs in 20.329985s 184 characters Submitted by mthelander on December 11th, 2013 20:38 +1

    require 'date'
    a = quacks.split(', ').map{|d|DateTime.parse(d)}
    (0...a.size).reduce{|m,i|
      j=i+1
      j+=1 while j < a.size && a[j] < a[j-1]+Rational(3,86400)
      (j-i>m) ? j-i : m
    }

Sponsors

aTech Media provide development time & hosting resources for this site. Why not check out some of their other things?