This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(teams). | |
-export([start/0, sets/1]). | |
start() -> | |
Pid = spawn(fun loop/0), | |
spawn(teams, sets, [Pid]). | |
loop() -> | |
process_flag(trap_exit, true), | |
loop([], 0). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FenwickTree | |
def initialize(n) | |
@n = n | |
@t = Array.new(n, 0) | |
end | |
def update(i, delta) | |
while i < @n do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FenwickTree | |
def initialize(n) | |
@n = n | |
@t = Array.new(n, 0) | |
end | |
def update(i, delta) | |
while i < @n do | |
@t[i] += delta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FenwickTree | |
def initialize(n) | |
@n = n | |
@t = Array.new(n, 0) | |
end | |
def update(i, delta) | |
while i < @n do | |
@t[i] += delta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SumCheckerHash | |
def initialize(file_name) | |
@hsh = {} | |
File.open(file_name).each{|line| @hsh[line.to_i] = @hsh[line.to_i].nil? ? 1 : (@hsh[line.to_i]+1)} | |
end | |
def check(sum) | |
@hsh.each_key{|i| return true if @hsh.has_key?(sum - i) && ((2*i != sum) || (@hsh[i] > 1))} | |
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MySortedArray < Array | |
def initialize(ary) | |
super(ary.sort!) | |
end | |
def search_binary(el, start_pos=0, end_pos=self.length-1) | |
if start_pos == end_pos - 1 | |
if self[start_pos] == el or self[end_pos] == el | |
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class File | |
attr_reader :pos_start_line, :eol_length | |
def set_eol_length | |
rewind | |
str = gets | |
@eol_length = self.pos - str.length + 1 | |
rewind | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class File | |
attr_reader :pos_start_line | |
def seek_line(pos) | |
if pos < 1 | |
seek(0) | |
@pos_start_line = 0 | |
return gets | |
else |