Skip to content

Instantly share code, notes, and snippets.

def change_state(xstate, d)
directions = "NESW"
i = "NESW".index(xstate)
if d == "R"
directions[i+1] ? directions[i+1] : "N"
else
directions[i-1] ? directions[i-1] : "W"
end
end
defmodule Day1 do
def main(file_path) do
file_path |> File.read! |> process |> IO.puts
end
def process(input) do
input
|> String.split(", ")
|> Enum.reduce(%{x: 0, y: 0, dir: "N"}, &reducer/2)
|> extract_answer

Keybase proof

I hereby claim:

  • I am ericdykstra on github.
  • I am ericd (https://keybase.io/ericd) on keybase.
  • I have a public key ASAv966Qu1nq0p8ibkcTXgdP5DYqGCMXbNA-FMJWrNKEQQo

To claim this, I am signing this object:

% ...
read_array(0,D) -> [];
read_array(N,D) ->
{ok, [X]} = io:fread("", D),
[X | read_array(N-1,D)].
read_2darray(0,M,D) -> [];
read_2darray(N,M,D) ->
Q=read_array(M,D),
[Q | read_2darray(N-1,M,D)].
@EricDykstra
EricDykstra / gist:3f97d9e052e3a8b99650
Created February 17, 2016 08:16
Compile and run elixir script
function exrun() {
mix escript.build && ./${PWD##*/}
}
# uncomment for part 1 num_groups = 3
# uncomment for part 2 num_groups = 4
start = 1
until answer = array.combination(start).select{|c| c.inject(:+) == (array.inject(:+) / num_groups)}.sort_by{|c| c.inject(:*)}.first
start += 1
end
p answer.inject(:*)
class Battle
SPELLS = {
"Magic Missile" => {cost: 53, damage: 4},
"Drain" => {cost: 73, damage: 2, heal: 2},
"Shield" => {cost: 113, timer: 6, effect: "armor", amount: 7},
"Poison" => {cost: 173, timer: 6, effect: "poison", amount: 3},
"Recharge" => {cost: 229, timer: 5, effect: "recharge", amount: 101},
}
@EricDykstra
EricDykstra / instructions.md
Last active August 29, 2015 13:58
Hiring Efficiency Problem

You've just been hired by a SF tech company that is looking to expand operations into new cities. Your first task: launch Salt Lake City. To launch into a new city of this size, you need to hire a general manager, 3 salespeople, 2 customer support agents, an office manager, and a marketing manager. You have pulled together a list of all the potential employees for these 8 positions, as well as their salary requirement and a quantified amount of "impact" that they can bring your team.

Your goal is to fill all 8 positions for $350,000 or less with the employees that will maximize "impact".

Not challenging enough? 5500 candidates applied to the same 8 positions for the New York City office, and our budget here is $450,000. Maximize impact while staying under budget again with this group.

http://en.wikipedia.org/wiki/Knapsack_problem

Keybase proof

I hereby claim:

  • I am ericdykstra on github.
  • I am ericd (https://keybase.io/ericd) on keybase.
  • I have a public key whose fingerprint is 0F12 55A0 3A2A C56E F189 219D E653 1EE6 9498 4DB9

To claim this, I am signing this object:

@EricDykstra
EricDykstra / index.html
Created July 8, 2013 07:16 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>