LoginSignup
1
0

paiza.ioでelixir その253

Posted at

概要

paiza.ioでelixirやってみた。
練習問題、やってみた。

練習問題

gtkwaveのvcdファイルを生成せよ。
3ch、実装せよ。

写真

image.png

サンプルコード


defmodule Va do
	use Agent
	def start_link() do
		Agent.start_link(fn ->
			0
		end, name: __MODULE__)
	end
	def get() do
		Agent.get(__MODULE__, fn v ->
			v
		end)
	end
	def inc() do
		Agent.update(__MODULE__, fn v ->
			v + 1
		end)
	end
end

defmodule Main do
    def main(src0, src1, src2) do
        IO.puts "$date"
        IO.puts "  Sat Mar 27 16:11:10 2023"
        IO.puts "$end"
        IO.puts "$version"
        IO.puts "  plunker"
        IO.puts "$end"
        IO.puts "$timescale"
        IO.puts "  1ms"
        IO.puts "$end"
        IO.puts "$scope module test $end"
        IO.puts "$var reg 1 ! a $end"
        IO.puts "$var reg 1 # b $end"
        IO.puts "$var reg 1 % c $end"
        IO.puts "$upscope $end"
        IO.puts "$enddefinitions $end"
        IO.puts "#0"
        IO.puts "$dumpvars"
        IO.puts "x!"
        IO.puts "x#"
        IO.puts "x%"
        IO.puts "$end"
        Enum.map(0..2, fn i ->
	        Enum.reduce(String.split(src0, ""), 0, fn x, n ->
	            if x != "" do
	                Va.inc
	                IO.puts "##{Va.get}"
	                IO.puts "#{String.slice(src0, n, 1)}!"
	                IO.puts "#{String.slice(src1, n, 1)}#"
	                IO.puts "#{String.slice(src2, n, 1)}%"
    	            n = n + 1
    	        else
    	            n
	            end
	        end)
        end)
    end
end

Va.start_link
Main.main("111111111000", "111111000111", "110001111111")



実行結果

$date
  Sat Mar 27 16:11:10 2023
$end
$version
  plunker
$end
$timescale
  1ms
$end
$scope module test $end
$var reg 1 ! a $end
$var reg 1 # b $end
$var reg 1 % c $end
$upscope $end
$enddefinitions $end
#0
$dumpvars
x!
x#
x%
$end
#1
1!
1#
1%
#2
1!
1#
1%
#3
1!
1#
0%
#4
1!
1#
0%
#5
1!
1#
0%
#6
1!
1#
1%
#7
1!
0#
1%
#8
1!
0#
1%
#9
1!
0#
1%
#10
0!
1#
1%
#11
0!
1#
1%
#12
0!
1#
1%
#13
1!
1#
1%
#14
1!
1#
1%
#15
1!
1#
0%
#16
1!
1#
0%
#17
1!
1#
0%
#18
1!
1#
1%
#19
1!
0#
1%
#20
1!
0#
1%
#21
1!
0#
1%
#22
0!
1#
1%
#23
0!
1#
1%
#24
0!
1#
1%
#25
1!
1#
1%
#26
1!
1#
1%
#27
1!
1#
0%
#28
1!
1#
0%
#29
1!
1#
0%
#30
1!
1#
1%
#31
1!
0#
1%
#32
1!
0#
1%
#33
1!
0#
1%
#34
0!
1#
1%
#35
0!
1#
1%
#36
0!
1#
1%

成果物

以上。

1
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
1
0