Cantor set: Difference between revisions

no edit summary
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
No edit summary
Line 857:
{{out}}
Same result of Java
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
defmodule Cantor do
@pos "█"
@neg " "
 
def run(lines) do
Enum.map(0..lines, fn line ->
segment_size = 3 ** (lines - line - 1) # lines = 2, segment_size = 3
chars = (3 ** line)
 
Enum.map(0..chars, fn char ->
char
|> Integer.digits(3)
|> Enum.any?(fn x -> x === 1 end)
|> case do
true -> @neg
false -> @pos
end
end)
|> Enum.reduce([], fn el, acc -> duplicate_char(acc, el, segment_size) end)
|> Enum.join()
|> String.trim_trailing()
end)
|> Enum.filter(fn line -> line !== "" end)
end
 
def duplicate_char(acc, el, segment_size) when segment_size >= 1, do: acc ++ [String.duplicate(el, segment_size)]
def duplicate_char(acc, _el, segment_size) when segment_size < 1, do: acc
end
 
Cantor.run(5)
|> IO.inspect()
</syntaxhighlight>
{{out}}
["█████████████████████████████████████████████████████████████████████████████████",
"███████████████████████████ ███████████████████████████",
"█████████ █████████ █████████ █████████",
"███ ███ ███ ███ ███ ███ ███ ███",
"█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █"]
 
=={{header|Excel}}==
===LAMBDA===
4

edits