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 copy | |
def peers(i, j): | |
row = set([(i, x) for x in range(9)]) | |
column = set([(x, j) for x in range(9)]) | |
start_row = 3 * (i // 3) | |
start_col = 3 * (j // 3) | |
square = set([ |
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
# Sudoku Solver | |
# | |
# Go to the SudokuSolver module at the bottom to see the main module. | |
# To run the solver on a example input board, call `SudokuSolver.run/0`. | |
# The high-level backtracking logic is in the `SudokuSolver.solve/2` function; | |
# the other modules and their functions provide the supporting code for representing | |
# the board and performing simple tasks or providing utility functionality. | |
defmodule SudokuSolver.Cell do |
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 ArrayWrapper do | |
@behaviour Access | |
defstruct erlang_array: :array.new() | |
@impl Access | |
def fetch(%ArrayWrapper{erlang_array: array}, key) | |
when is_integer(key) and (key >= 0) do | |
case :array.get(key, array) do | |
:undefined -> :error |
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
/* | |
Small and bare-bones Lisp parser and evaluator inspired by the respective problem posed at: https://www.recurse.com/pairing-tasks. | |
NOTE: This was my first time, as I had no previous experience with Lisp languages and only had some vague notions of them | |
besides the fact that their notation is prefix-based, so this implementation might not be totally correct. | |
This was just for the sake of learning and experimenting. And only implements four function: +, *, list and first. | |
*/ | |
function tokenize(input) { | |
let validTokensRegExp = /(\w+|\(|\)|\+|\*)/g; | |
let tokens = input.match(validTokensRegExp); |
To run in the console, without supervision trees, do the following:
$ iex -S mix
iex> Plug.Adapters.Cowboy2.http(NormalRouter, [], [dispatch: PlugDispatch.dispatch()])
To run inside a supervision tree, make sure to call child_spec
(or use a tuple) with the correct arguments, like in the following example: