-module( geometry1).
-export([ test/ 0, area/ 1]).
test() ->
12 = area({ rectangle, 3, 4}),
144 = area({ square, 12}),
tests_worked.
This file contains 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
# In an Elixir app using https://github.com/beatrichartz/csv | |
defmodule CSVDecoder do | |
def perform(content) do | |
Enum.reduce(content, %{}, &set_key/2) | |
end | |
defp set_key([key, name, status, email, joined, email_status, moderation_status], acc) do | |
Map.put(acc, key, %{ | |
name: name, |
This file contains 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
module WebStore.Catalog.Product | |
@moduledoc """ | |
This is a module that might sit inside of a Phoenix application in our | |
umbrella. We'll need to make calls to several contexts and merge the results | |
together if successful. | |
""" | |
alias Revzilla.CoreModel.{Assets, Images, Merchandizing, Skus, Videos} | |
alias Revzilla.Recommendation.SimilarProduct | |
alias Revzilla.WebStore.{AssetMapper, ImageMapper, ProductMapper} |
This file contains 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 SumJawn do | |
@moduledoc """ | |
As any number greater than 9 is represented by several digits, we can | |
calculate the sum of these digits. For example, for numbers 1492 and 1776 | |
we get: | |
```1 + 4 + 9 + 2 = 16 | |
1 + 7 + 7 + 6 = 21 | |
``` |
This file contains 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 Thing do | |
@moduledoc """ | |
Sort a string by cardinality of repeating characters, then alphabetically within each partition created by cardinality sorting. | |
An example: "abcdddeeeffff" would be sorted "ffffdddeeeabc" | |
In the above, 'f' appears the most(4), so it comes first, followed by 'd's and 'e's (3), in alaphabetical order, since they have equal cardinality. Then follow 'a', 'b', and 'c' in alphabetical order since they all have the same cardinality(1). | |
Another example: "cardinality" would be sorted "aaiicdlnrty" | |
""" |
This file contains 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 Sorter do | |
@doc """ | |
Takes a list and prints the list with the non zero index position before it was sorted. | |
## Example | |
iex> Sorter.sortit([34, 7, 38, 1]) | |
"1 was in position 3" | |
"7 was in position 1" | |
"34 was in position 0" | |
"38 was in position 2" |
This file contains 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 HammingDistance do | |
@moduledoc """ | |
Write a program that can calculate the Hamming distance between two DNA | |
strands. | |
A mutation is simply a mistake that occurs during the creation or copying of a | |
nucleic acid, in particular DNA. Because nucleic acids are vital to cellular | |
functions, mutations tend to cause a ripple effect throughout the cell. | |
Although mutations are technically mistakes, a very rare mutation may equip | |
the cell with a beneficial attribute. In fact, the macro effects of |
This file contains 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
class HammingDistance | |
def self.hammit(left, right) | |
fail 'lengths don\'t match' if different_lengths?(left, right) | |
(0..compare_length(left, right)).map { |index| | |
left[index] == right[index] | |
}.select { |result| | |
result == false | |
}.count | |
end |
This file contains 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 AplhaBet do | |
@moduledoc """ | |
The word `chimps` is an example of a word that's in alphabetical order. Write | |
a program that prints out if the word is in alphabetical order. For bonus | |
make it test backwards too! | |
""" | |
@doc """ | |
Returns true if the given string is in alphabetical or reverse-alphabetical | |
order |
This file contains 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 MagicSquare do | |
@moduledoc """ | |
Today's daily programmer challenge is to test a magic square. This challenge | |
is stolen verbatim from r/dailyprogrammer. A 3x3 magic square is a 3x3 grid | |
of the numbers 1-9 such that each row, column, and major diagonal adds up to | |
15. Here's an example: | |
``` | |
8 1 6 | |
3 5 7 | |
4 9 2 |
NewerOlder