Skip to content

Instantly share code, notes, and snippets.

View peterdk's full-sized avatar

Peter de Kraker peterdk

View GitHub Profile
@peterdk
peterdk / 3 - find the min.rb
Last active December 11, 2015 21:48
My O(K) solution for hackercup 2013, qualification round, problem 3: find the min. Ran in 0.3 seconds on my core 2 duo macbook, using Ruby 1.9.3 =update= Unfortunately the code is not fully correct. It failed on 1/20 cases.
require 'set'
def find_min_better3(a,b,c,r,k,n)
m = []
m << a
(k - 1).times do |k|
m << ((b * m[k] + c) % r)
end