Created
September 14, 2015 06:57
-
-
Save k-hamada/d82419c59bb203957aa8 to your computer and use it in GitHub Desktop.
#ciqprocon
This file contains hidden or 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
hands = %w(G C P G) | |
puts hands[(hands.index(gets.chomp)||0) + 1] |
This file contains hidden or 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
n = gets.chomp.to_i | |
p (Math.log(2*n+1)/Math.log(3)).ceil |
This file contains hidden or 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 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' |
This file contains hidden or 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
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