Skip to content

Instantly share code, notes, and snippets.

@k-hamada
Created September 14, 2015 06:57
Show Gist options
  • Save k-hamada/d82419c59bb203957aa8 to your computer and use it in GitHub Desktop.
Save k-hamada/d82419c59bb203957aa8 to your computer and use it in GitHub Desktop.
#ciqprocon
hands = %w(G C P G)
puts hands[(hands.index(gets.chomp)||0) + 1]
n = gets.chomp.to_i
p (Math.log(2*n+1)/Math.log(3)).ceil
class RamenMap
Tile = Struct.new(:word, :next)
class << self
def parse(data)
map_data = {}
data.each.with_index do |line, y|
line.each.with_index do |word, x|
map_data[[x, y]] = Tile.new(word, next_point(x, y))
end
end
map_data.update(map_data) do |_, tile|
tile.next.select!{|next_point| map_data.key?(next_point) }
tile
end
end
def next_point(x, y)
[[0, 1], [1, 0], [0, -1], [-1, 0]].map do |mx, my|
[x + mx, y + my]
end
end
end
end
map_data = $stdin.read.split(?\n).map{|str| str.each_char.to_a }
ramen_map = RamenMap.parse(map_data)
result =
ramen_map.keys
.select{|point| ramen_map[point].word == 'A' }
.flat_map{|point| ramen_map[point].next }
.select{|point| ramen_map[point].word == 'M' }
.flat_map{|point| ramen_map[point].next }
.select{|point| ramen_map[point].word == 'N' }
.flat_map{|point| ramen_map[point].next }
.select{|point| ramen_map[point].word == 'E' }
.flat_map{|point| ramen_map[point].next }
.any?{|point| ramen_map[point].word == 'M' }
puts result ? 'yes' : 'no'
p [*1..gets.chomp.to_i]
.repeated_combination(2)
.group_by{|x,y| x ** 3 + y ** 3 }
.select{|k,v| v.size > 1 }
.sort.last.last.last
.map{|i| i ** 3 }
.inject(:+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment