Round 1 answers in Ruby:
1. Lost in Stupid Parentheses
---------------------------------------
ARGF.each do |line|
chars = line.chomp.split(//)
max_depth = 0
depth = 0
begin
chars.each do |c|
case c
when '(': depth += 1
when ')': depth -= 1
else raise "invalid character"
end
raise "unmatched" if depth < 0
max_depth = depth if max_depth < depth
end
raise "unmatched" if depth != 0
rescue
max_depth = 0
end
puts max_depth
end
2. Multiples of Seven
---------------------------------------
ARGF.each do |line|
n = line.chomp.to_i
i = (n / 7) * 7
while i >= 0
if (i.to_s.reverse.to_i % 7).zero?
puts i
end
i -= 7
end
end
3. Sum Numbers Only Please
---------------------------------------
sum = 0
ARGF.each do |line|
chars = line.chomp.split(//)
chars.each do |c|
next unless c =~ /\d/
sum += c.to_i
end
end
puts sum
4. Mozy Words
---------------------------------------
puts ARGF.select{ |line| line =~ /m.*o.*z.*y/ }.size
5. Socket To Ya'
---------------------------------------
require 'socket'
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 8787, 'mozy.com' )
socket.connect( sockaddr )
results = socket.read
puts results[13484].chr
6. NP-Butt-Hard
---------------------------------------
ARGF.each do |line|
chars = line.chomp.split(//)
rot1 = chars.map do |c|
case c
when /[a-y]/i ; (c[0] + 1).chr
when /z/i ; (c[0] - 25).chr
else c
end
end
puts rot1.join('')
end
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/