0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その345

Posted at

概要

paiza.ioでelixirやってみた。
atcoder、見つけたので、やってみた。

参考にしたページ

練習問題

ABC 081 B - Shift Only
N個の整数値を受け取り、一度の操作ですべての数を2で割る。割り切れなくなるまで割っていった時、何回割ることが出来るか?

投入するソース

3
8 12 40

期待値

2

サンプルコード

defmodule Main do
	def pow2(n) do
		if rem(n, 2) == 0 do
			1 + pow2(div(n, 2))
		else
			0
		end
	end
	def main do
		_ = IO.gets("") 
		    |> String.trim() 
		    |> String.to_integer
		a = IO.gets("") 
		    |> String.trim() 
		    |> String.split(" ", trim: true) 
		    |> Enum.map(&String.to_integer(&1))
		a   
		|> Enum.map(&pow2(&1)) 
		|> List.foldr(100000, (fn x, ac -> 
		    if x > ac do 
		        ac 
		    else 
		        x 
		    end 
		end)) 
		|> IO.puts
	end
end

実行結果

2

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?