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 その347

Posted at

概要

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

参考にしたページ

練習問題

ABC 083 B - Some Sums
1以上N以下の整数のうち、10進法での各桁の和がA以上B以下であるものの総和を求める問題です。

投入するソース

20 2 5

期待値

84

サンプルコード

defmodule Main do
	def dsum(n) do
		if div(n, 10) == 0 do
			n
		else
			rem(n, 10) + dsum(div(n, 10))
		end
	end
	def main do
		[n, a, b] = IO.gets("") 
		    |> String.trim()
			|> String.split(" ", trim: true)
			|> Enum.map(&String.to_integer(&1))
		sum = 1..n
		    |> Enum.map(fn n ->
		        if a <= dsum(n) and dsum(n) <= b do 
		            n 
		        else 
		            0 
		        end 
		    end) 
		    |> List.foldl(0, fn (x, acc) -> 
		        x + acc 
		    end)
		sum 
		|> IO.puts
	end
end

実行結果

84

成果物

以上。

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?