defmodule Exercise do def string_ex1 do word = "had we but world enough, and time" String.split(word, ~r{,}, parts: 2) String.codepoints(word) String.reverse(word) String.to_charlist(word) counter_word = "had we but bacon enough, and treacle" String.myers_difference(word, counter_word) end def string_ex2 do IO.puts("today we are: #{Time.utc_now()}") IO.puts(~s) word = ~w[now is the time] IO.inspect(word) IO.inspect(~W/now is the time/) end def regex_ex do word = IO.gets("enter any word: ") |> String.trim() IO.puts("does it match: #{word =~ ~r/a.c/}") "cat has pooped on my cat paper" |> String.replace(~r/cat/, "dog", global: false) |> IO.puts() "cat has pooped on my cat paper" |> String.replace(~r/cat/, "dog") |> IO.puts() end def playing_around(t = {a, b}) do IO.puts("a=#{a}, b=#{b}") IO.puts(is_tuple(t)) end def swap_tups({a, b}) do {b, a} end def check_match(a, a) do true end def len([]) do 0 end def len([_ | t]) do 1 + len(t) end def sum([]) do 0 end def sum([h | t]) do h + sum(t) end def square([]) do [] end def square([h | t]) do [h * h | square(t)] end def map([], _fn) do [] end def map([h | t], fun) do [fun.(h) | map(t, fun)] end def check_match(_, _) do false end def sum_pairs([]) do [] end def sum_pairs([h, h1 | t]) do [h + h1 | sum_pairs(t)] end def even_length([]) do true end def even_length([_h | t]) do !even_length(t) end def understand_rec([]) do 0 end def understand_rec([_head | tail]) do understand_rec(tail) + 1 end end