This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factorial = fn (x) -> | |
calc_factorial = fn | |
(_, 0) -> 1 | |
(calc_fn, n) -> n * calc_fn.(calc_fn, n - 1) | |
end | |
calc_factorial.(calc_factorial, x) | |
end | |
IO.inspect factorial.(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a macro to alias columns and collect them | |
defmodule ColumnAlias do | |
defmacro __using__(_) do | |
quote do | |
Module.register_attribute(__MODULE__, :column_aliases, accumulate: true) | |
import ColumnAlias, only: [alias_field: 3] | |
@before_compile ColumnAlias | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RedBlackTree do | |
# elixir translation of https://gist.github.com/mjn/2648040 | |
# stucture of node: {Key, Value, Color, Smaller, Bigger} | |
# tree = nil | |
# tree = RedBlackTree.insert(tree, 2, 3) | |
# IO.inspect tree | |
# tree = RedBlackTree.insert(tree, 3, 4) | |
# IO.inspect tree | |
# tree = RedBlackTree.insert(tree, 6, 9) | |
# IO.inspect tree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configures Elixir's Logger to log to file | |
# ensure https://github.com/onkel-dirtus/logger_file_backend | |
# is installed in deps of the project in mix.exs | |
# reuses the original phoenix logging format. | |
config :logger, backends: [{LoggerFileBackend, :request_log}], | |
format: "$time $metadata[$level] $message\n", | |
metadata: [:request_id] | |
# Keep a seperate log file for each env. | |
# logs are stored in the root directory of the application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SetMember do | |
defstruct val: 0, lt: 0, rt: 0, children: [] | |
end | |
defmodule Test do | |
# function header for defaults | |
def assign_counts(set_member, count\\1) | |
# no child just assign counts and return last used count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def getAllSentences(input_data): | |
""" | |
take cartesian cross product of list and join to form the sentences to get all sentences. | |
Assumption: The order for sentences is that for every element in ith list create all sentences from i-1..0th list | |
i.e. if list = [[1,2],[3,4],[5]] | |
order of sentences = [135,145,235,245] | |
""" | |
return [" ".join(sentence) for sentence in list(itertools.product(*input_data))] |