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

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
Enum.reduce使ってみた。

サンプルコード

                c = 140
                l = 4
                b = "fizz"
		        s = String.split(b, "", trim: true)
		        #IO.inspect(s)
			    str = Enum.reduce(s, ["", c], fn x, y ->
			        pc = Enum.at(y, 1)
			        str = Enum.at(y, 0) <> 
			            "            #{pc}:\n" <>
			            "            begin\n" <>
                        "                out <= \"#{x}\";\n" <>
                        "                pc <= #{pc + 1};\n" <>
                        "            end\n"
                    pc = pc + 1
                    [str, pc]
                    
			    end)
			    str = Enum.at(str, 0) <>
    			    "            #{c + l}:\n" <>
		            "            begin\n" <>
                    "                out <= \" \";\n" <>
                    "                pc <= #{c + 10};\n" <>
                    "            end\n"
			    IO.puts str
			    
			    
			    
			    

実行結果

            140:
            begin
                out <= "f";
                pc <= 141;
            end
            141:
            begin
                out <= "i";
                pc <= 142;
            end
            142:
            begin
                out <= "z";
                pc <= 143;
            end
            143:
            begin
                out <= "z";
                pc <= 144;
            end
            144:
            begin
                out <= " ";
                pc <= 150;
            end

成果物

以上。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?