Skip to content

Instantly share code, notes, and snippets.

defmodule PascalsTriangle do
@doc """
Calculates the rows of a pascal triangle
with the given height
Calculated from the bottom up.
"""
@spec rows(integer) :: [[integer]]
def rows(0, acc), do: acc
def rows(num) do
num
defmodule BracketPush do
@doc """
Checks that all the brackets and braces in the string are matched correctly, and nested correctly
"""
@matches %{"}"=> "{", ")"=> "(", "]"=> "["}
@opening ["{", "(", "["]
@spec check_brackets(String.t) :: boolean
def check_brackets(""), do: true
defmodule BracketPush do
@doc """
Checks that all the brackets and braces in the string are matched correctly, and nested correctly
"""
@matches %{"}"=> "{", ")"=> "(", "]"=> "["}
@opening ["{", "(", "["]
@spec check_brackets(String.t) :: boolean
def check_brackets(""), do: true
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory

Keybase proof

I hereby claim:

  • I am terakilobyte on github.
  • I am terakilobyte (https://keybase.io/terakilobyte) on keybase.
  • I have a public key ASDo8waM9ecH9Z_QF7W61dPPrQMgrKzAZFbrxqpp1mGLOAo

To claim this, I am signing this object:

defmodule Luhn do
@spec is_luhn?(number()) :: boolean()
def is_luhn?(number) do
number |>
Integer.digits |>
Enum.reverse |>
sort_and_sum_numbers |>
verify?
end
defmodule PrimeFactors do
@doc """
Compute the prime factors for 'number'.
The prime factors are prime numbers that when multiplied give the desired
number.
The prime factors of 'number' will be ordered lowest to highest.
"""
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
.idea
.env
defmodule Roman do
@doc """
Convert the number to a roman number.
"""
@ones %{"0" => "", "1" => "I", "2" => "II", "3" => "III", "4" => "IV", "5" => "V", "6" => "VI", "7" => "VII", "8" => "VIII", "9" => "IX"}
@tens %{"0" => "", "1" => "X", "2" => "XX", "3" => "XXX", "4" => "XL", "5" => "L", "6" => "LX", "7" => "LXX", "8" => "LXXX", "9" => "XC"}
@hundos %{"0" => "", "1" => "C", "2" => "CC", "3" => "CCC", "4" => "CD", "5" => "D", "6" => "DC", "7" => "DCC", "8" => "DCCC", "9" => "CM"}
@kilos %{"0" => "", "1" => "M", "2" => "MM", "3" => "MMM"}
@spec numerals(pos_integer) :: String.t
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory