Skip to content

Instantly share code, notes, and snippets.

def flatten(input, output = [])
input.each do |el|
if el.is_a? Array
flatten(el, output)
else
output << el
end
end
output
end
@dukeimg
dukeimg / .bat
Created April 26, 2016 19:28
Railsinstaller missiong gems fix
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
GOTO :EOF
:WinNT
@"%~dp0ruby.exe" "%~dpn0" %*
@dukeimg
dukeimg / apu_spec.rb
Last active April 26, 2016 13:42
APU redux
require './lib/scheme'
describe Scheme do
describe '.check' do
let(:scheme) { Scheme.new(:height => 4, :width => 4,
:cells => [
['0', '0', '.', '0'],
['0', '.', '0', '0'],
['.', '0', '.', '0'],
@dukeimg
dukeimg / solution.rb
Created April 22, 2016 03:51
Mars Lander
STDOUT.sync = true # DO NOT REMOVE
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
@surface_n = gets.to_i # the number of points used to draw the surface of Mars.
@surface_n.times do
# land_x: X coordinate of a surface point. (0 to 6999)
# land_y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
land_x, land_y = gets.split(" ").collect {|x| x.to_i}
end
@dukeimg
dukeimg / solution.rb
Created April 22, 2016 03:48
The Descent
STDOUT.sync = true # DO NOT REMOVE
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
# game loop
loop do
highest = 0
index = 0
@dukeimg
dukeimg / solution.rb
Created April 22, 2016 03:46
Power of Thor
STDOUT.sync = true # DO NOT REMOVE
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
# ---
# Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
# light_x: the X position of the light of power
# light_y: the Y position of the light of power
# initial_tx: Thor's starting X position
# initial_ty: Thor's starting Y position
@dukeimg
dukeimg / solution.rb
Created April 22, 2016 03:43
Skynet: the Chasm
STDOUT.sync = true # DO NOT REMOVE
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
@road = gets.to_i # the length of the road before the gap.
@gap = gets.to_i # the length of the gap.
@platform = gets.to_i # the length of the landing platform.
required_speed = @gap + 1
@dukeimg
dukeimg / solution.rb
Created April 22, 2016 03:38
Temperatures
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
@n = gets.to_i # the number of temperatures to analyse
@temps = gets.chomp # the n temperatures expressed as integers ranging from -273 to 5526
if @n == 0
puts 0
return
end
@dukeimg
dukeimg / solution.rb
Last active July 30, 2016 09:58
APU: Init Phase
STDOUT.sync = true # DO NOT REMOVE
# Don't let the machines win. You are humanity's last hope...
@width = gets.to_i # the number of cells on the X axis
@height = gets.to_i # the number of cells on the Y axis
@cells = Array.new
@height.times do
line = gets.chomp # width characters, each either 0 or .
@dukeimg
dukeimg / apu_init_phase.rb
Last active April 22, 2016 03:32
Решения codingame
STDOUT.sync = true # DO NOT REMOVE
# Don't let the machines win. You are humanity's last hope...
@width = gets.to_i # the number of cells on the X axis
@height = gets.to_i # the number of cells on the Y axis
cells = Array.new
@height.times do
line = gets.chomp # width characters, each either 0 or .