Skip to content

Instantly share code, notes, and snippets.

@whatalnk
whatalnk / cf330-div2-a.rb
Last active November 10, 2015 04:07
Codeforces #330 Div2
# [Problem - A - Codeforces](http://codeforces.com/contest/595/problem/A)
n, m = gets.chomp.split(" ").map(&:to_i)
ans = 0
n.times do |i|
rooms = gets.chomp.split(" ").map(&:to_i)
rooms.each_slice(2) do |a, b|
if (a == 1) or (b == 1) then
ans += 1
end
end
@whatalnk
whatalnk / Vagrantfile
Last active November 18, 2015 09:29
Vagrantfile for iRuby
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
$forbuild = <<SCRIPT
apt-get update -y
apt-get install -y git
@whatalnk
whatalnk / srm673-easy-BearSong.py
Last active November 19, 2015 05:55
TopCoder SRM 673 Div 2
from collections import defaultdict
class BearSong():
def countRareNotes(self, notes):
d = defaultdict(int)
for i in notes:
d[i] += 1
return(len([i for i in d.values() if i == 1]))
@whatalnk
whatalnk / cfEdu1-a-TrickySum.rb
Created November 19, 2015 10:39
Educational Codeforces Round 1
t = gets.chomp.to_i
t.times do
n = gets.chomp.to_i
power2 = []
snd = 1
i = 1
while snd <= n
power2 << snd
snd = 2**i
i += 1
n = gets.chomp.to_i
coors = []
n.times do
coors << gets.chomp.split(" ").map(&:to_i)
end
if n == 3 or n == 4 then
coors_t = coors.transpose
dx = coors_t[0].max - coors_t[0].min
dy = coors_t[1].max - coors_t[1].min
puts dx * dy
@whatalnk
whatalnk / docx-to-md.pl
Created November 20, 2015 12:49
Git: textconv for .docx files
#!/usr/bin/perl
use strict;
use warnings;
my $stdout = `pandoc --to=markdown --no-wrap --reference-links --atx-headers $ARGV[0]`;
my @lines = split(/(?<=[.])\s/, $stdout);
print join("\n", @lines)
@whatalnk
whatalnk / cf332-div2-a-Patrick-and-Shopping.rb
Last active November 21, 2015 03:27
Codeforces 332 Div2
# [Problem - A - Codeforces](http://codeforces.com/contest/599/problem/A)
d1, d2, d3 = gets.chomp.split(" ").map(&:to_i)
puts [2*(d1+d2), d1+d2+d3, 2*(d1+d3), 2*(d2+d3)].min
@whatalnk
whatalnk / abc031-a-game.rb
Last active November 24, 2015 04:14
AtCoder ABC 031
a, d = gets.chomp.split(" ").map(&:to_i)
if a == d then
puts a * (a + 1)
elsif a < d then
puts (a + 1) * d
else
puts a * (d + 1)
end
@whatalnk
whatalnk / cf333-div2-a-two-base.rb
Last active November 25, 2015 11:23
Codeforces 333 Div2
n, bx = gets.chomp.split(" ").map(&:to_i)
xs = gets.chomp.split(" ").map(&:to_i)
m, by = gets.chomp.split(" ").map(&:to_i)
ys = gets.chomp.split(" ").map(&:to_i)
bxx = (0..(n-1)).map{|i| bx**i}.reverse
byy = (0..(m-1)).map{|i| by**i}.reverse
x = xs.zip(bxx).map{|i, j| i*j}.inject(:+)
y = ys.zip(byy).map{|i, j| i*j}.inject(:+)
@whatalnk
whatalnk / cfEdu2-A-Extract-Numbers.rb
Last active December 1, 2015 10:21
Educational Codeforces Round 2
# [Problem - A - Codeforces](http://codeforces.com/contest/600/problem/A)
s = gets.chomp.split(/[,;]/, -1)
number = []
nonnumber = []
s.each do |w|
if w.match(/^[0-9]+$/) then
if w.length >= 2 and w[0] == "0" then
nonnumber << w
else
number << w