Skip to content

Instantly share code, notes, and snippets.

@hangingman
Created November 12, 2017 07:28
Show Gist options
  • Save hangingman/1ec7e672ff19fc98d1671d71e33c2bc5 to your computer and use it in GitHub Desktop.
Save hangingman/1ec7e672ff19fc98d1671d71e33c2bc5 to your computer and use it in GitHub Desktop.
AtCoder C - コイン
lines = <<'EOS'
3
2
4
8
EOS
#lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
C = array[1..N].map(&:to_i)
puts N
puts C.to_s
puts "---"
coins = C.permutation(N).map do |arr|
arr
end
coins = coins.map do |coin|
coin_tmp = coin.dup
for i in 0..coin.length
puts "coin = #{coin}"
coin_tmp.each_with_index do |sub_coin, index|
if index > i
puts " coin_tmp = #{coin_tmp}"
puts " index_coin = #{coin_tmp[i]}, sub_coin = #{sub_coin}"
coin_tmp[index] = coin_tmp[index]*-1 if sub_coin % coin_tmp[index] == 0
end
end
puts " => #{coin_tmp}"
end
coin_tmp
end
coins.each{|c| puts c.to_s}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment