LoginSignup
1
0

More than 1 year has passed since last update.

paiza.ioでelixir その226

Last updated at Posted at 2023-05-22

概要

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

練習問題

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

写真

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) do
        IO.puts "$date"
        IO.puts "  Sat Mar 27 16:11:10 2022"
        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 "$upscope $end"
        IO.puts "$enddefinitions $end"
        IO.puts "#0"
        IO.puts "$dumpvars"
        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)}#"
    	            n = n + 1
    	        else
    	            n
	            end
	        end)
        end)
    end
end

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




成果物

以上。

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