Skip to content

Instantly share code, notes, and snippets.

@fschuindt
fschuindt / loop.rb
Last active July 9, 2016 00:50
loop.rb is faster, besides that recusion.rb faces "stack level too deep" with approximately 8 thousands interactions.
def print_msg_n_times(msg, n)
n.times do
puts msg
end
end
print_msg_n_times('Hello world', 6_000)
@fschuindt
fschuindt / elixir_notes.md
Last active December 15, 2023 22:32
My personal study notes on Elixir. It's basically a resume of http://elixir-lang.org/getting-started/ (Almost everything is copied). Still working on it!
:: Elixir study notes.
# get some help:
iex> i 'hello'
Term
'hello'
Data type
List
Description
...
@fschuindt
fschuindt / list_sum.exs
Last active April 25, 2016 19:49
Sum of elements on a list. "The process of taking a list and reducing it down to one value is known as a reduce algorithm and is central to functional programming."
defmodule Math do
def sum_list([head | tail], accumulator) do
sum_list(tail, head + accumulator)
end
def sum_list([], accumulator) do
accumulator
end
end
@fschuindt
fschuindt / recursion.exs
Last active April 24, 2016 00:20
Recursion rather than ground-level loop structures in Elixir.
defmodule Recursion do
def print_multiple_times(msg, n) when n <= 1 do
IO.puts msg
end
def print_multiple_times(msg, n) do
IO.puts msg
print_multiple_times(msg, n - 1)
end
end
defmodule Math do
def zero?(0) do
true
end
def zero?(x) when is_integer(x) do
false
end
end