Skip to content

Commit

Permalink
Fix issues reported by credo
Browse files Browse the repository at this point in the history
  • Loading branch information
code-shoily committed Dec 4, 2023
1 parent aed4899 commit 9f18a9d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/2015/day_18.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule AdventOfCode.Y2015.Day18 do
--- Day 18: Like a GIF For Your Yard ---
Problem Link: https://adventofcode.com/2015/day/18
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
alias AdventOfCode.Algorithms.Grid
alias AdventOfCode.Helpers.{InputReader, Transformers}

def input, do: InputReader.read_from_file(2015, 18)
@repetitions 1..100
Expand Down
2 changes: 1 addition & 1 deletion lib/2016/day_08.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule AdventOfCode.Y2016.Day08 do
end)
end

defp empty_grid() do
defp empty_grid do
for w <- 0..(@width - 1), h <- 0..(@height - 1), into: %{} do
{{w, h}, @off}
end
Expand Down
93 changes: 52 additions & 41 deletions lib/2017/day_23.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,59 @@ defmodule AdventOfCode.Y2017.Day23 do
when index > map_size(commands) - 1 or index < 0,
do: muls

defp process(%{index: index, registers: registers, muls: muls} = state, commands) do
defp process(%{index: index} = state, commands) do
case commands[index] do
{"set", x, y} ->
y_value = (is_integer(y) && y) || registers[y]

state
|> Map.merge(%{registers: %{registers | x => y_value}, index: index + 1})
|> process(commands)

{"sub", x, y} ->
y_value = (is_integer(y) && y) || registers[y]

state
|> Map.merge(%{
registers: %{registers | x => registers[x] - y_value},
index: index + 1
})
|> process(commands)

{"mul", x, y} ->
y_value = (is_integer(y) && y) || registers[y]

state
|> Map.merge(%{
registers: %{registers | x => registers[x] * y_value},
index: index + 1,
muls: muls + 1
})
|> process(commands)

{"jnz", 0, _} ->
state
|> Map.put(:index, index + 1)
|> process(commands)

{"jnz", x, y} ->
y_value = (is_integer(y) && y) || registers[y]
jump_value = (registers[x] == 0 && 1) || y_value

state
|> Map.put(:index, index + jump_value)
|> process(commands)
{"set", x, y} -> process(:set, state, commands, x, y)
{"sub", x, y} -> process(:sub, state, commands, x, y)
{"mul", x, y} -> process(:mul, state, commands, x, y)
{"jnz", 0, _} -> process(:jnz, state, commands)
{"jnz", x, y} -> process(:jnz, state, commands, x, y)
end
end

defp process(:set, %{index: index, registers: registers} = state, commands, x, y) do
y_value = (is_integer(y) && y) || registers[y]

state
|> Map.merge(%{registers: %{registers | x => y_value}, index: index + 1})
|> process(commands)
end

defp process(:sub, %{index: index, registers: registers} = state, commands, x, y) do
y_value = (is_integer(y) && y) || registers[y]

state
|> Map.merge(%{
registers: %{registers | x => registers[x] - y_value},
index: index + 1
})
|> process(commands)
end

defp process(:mul, %{index: index, registers: registers, muls: muls} = state, commands, x, y) do
y_value = (is_integer(y) && y) || registers[y]

state
|> Map.merge(%{
registers: %{registers | x => registers[x] * y_value},
index: index + 1,
muls: muls + 1
})
|> process(commands)
end

defp process(:jnz, %{index: index, registers: registers} = state, commands, x, y) do
y_value = (is_integer(y) && y) || registers[y]
jump_value = (registers[x] == 0 && 1) || y_value

state
|> Map.put(:index, index + jump_value)
|> process(commands)
end

defp process(:jnz, %{index: index} = state, commands) do
state
|> Map.put(:index, index + 1)
|> process(commands)
end
end
2 changes: 1 addition & 1 deletion lib/2020/day_03.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule AdventOfCode.Y2020.Day03 do
--- Day 3: Toboggan Trajectory ---
Problem Link: https://adventofcode.com/2020/day/3
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
alias AdventOfCode.Algorithms.Grid
alias AdventOfCode.Helpers.{InputReader, Transformers}

@default_slope {3, 1}
@slopes [{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}]
Expand Down
2 changes: 1 addition & 1 deletion lib/2022/day_12.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule AdventOfCode.Y2022.Day12 do
--- Day 12: Hill Climbing Algorithm ---
Problem Link: https://adventofcode.com/2022/day/12
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
alias AdventOfCode.Algorithms.Grid
alias AdventOfCode.Helpers.{InputReader, Transformers}

def input, do: InputReader.read_from_file(2022, 12)

Expand Down
2 changes: 1 addition & 1 deletion lib/2022/day_22.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule AdventOfCode.Y2022.Day22 do
--- Day 22: Monkey Map ---
Problem Link: https://adventofcode.com/2022/day/22
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
alias AdventOfCode.Algorithms.Grid
alias AdventOfCode.Helpers.{InputReader, Transformers}

def input, do: InputReader.read_from_file(2022, 22, false)

Expand Down
2 changes: 1 addition & 1 deletion lib/2023/day_03.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ defmodule AdventOfCode.Y2023.Day03 do
Difficulty: m
Tags: grid-walk
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
alias AdventOfCode.Algorithms.Grid
alias AdventOfCode.Helpers.{InputReader, Transformers}

def input, do: InputReader.read_from_file(2023, 3)

Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/summarizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule AdventOfCode.Helpers.Summarizer do

@year_range 2015..2023

def summarize() do
def summarize do
metadata = Map.new(@year_range, &{&1, Meta.get_info(&1, true)})

total_stars =
Expand Down

0 comments on commit 9f18a9d

Please sign in to comment.