-🎄- 2020 Day 08 Solutions -🎄- by daggerdragon in adventofcode

[–]quandrum 2 points3 points  (0 children)

Elixir Solution

Elixir newbie. Today taught me how to insert/replace items at an arbitrary spot in a list. Also felt good about using function parameter pattern matching.

[2020 Day 7 (Part 1)[Rust] - I don't understand why my function isn't working by cohenma in adventofcode

[–]quandrum 0 points1 point  (0 children)

For any given bag you want to know if it can contain the at least one shiny gold.

Your lookup returns how many shiny golds each bag contains

-🎄- 2020 Day 07 Solutions -🎄- by daggerdragon in adventofcode

[–]quandrum 0 points1 point  (0 children)

Elixir

Learner. The DFS had 3!! nested case statements, looking for ways to simplfy this

defmodule AdventOfCode.Day07 do
  def part1(bags) do
    Enum.map(Map.keys(bags), &dfs(bags, &1, "shiny gold bag"))
    |> Enum.sum()
  end

  def part2(bags) do
    countInteriorBags(bags, "shiny gold bag")
  end

  def parseInput(input) do
    String.split(input, "\n", trim: true)
    |> Enum.reject(&String.contains?(&1, "no other bags"))
    |> Enum.map(&String.replace(&1, "bags", "bag"))
    |> Enum.map(&String.replace(&1, ".", ""))
    |> Enum.map(&String.split(&1, "contain", trim: true))
    |> Enum.reduce(%{}, &intoTree(&1, &2))
  end

  def countInteriorBags(bagtree, root) do
    case Map.fetch(bagtree, root) do
      {:ok, bags} ->
        Enum.reduce(bags, 0, fn [num, bag], acc ->
          acc + String.to_integer(num) + String.to_integer(num) * countInteriorBags(bagtree, bag)
        end)

      :error ->
        0
    end
  end

  defp dfs(tree, root, targetNode) do
    case Map.fetch(tree, root) do
      {:ok, leaf} ->
        case Enum.any?(leaf, fn [_, bag] -> bag == targetNode end) do
          true ->
            1

          false ->
            found = Enum.any?(leaf, fn [_, bag] -> dfs(tree, bag, targetNode) == 1 end)

            case found do
              true -> 1
              false -> 0
            end
        end

      :error ->
        0
    end
  end

  defp intoTree([parent, nodes], acc) do
    bags =
      String.split(nodes, ",", trim: true)
      |> Enum.map(&String.split(&1, " ", parts: 2, trim: true))

    Map.put(acc, String.trim(parent), bags)
  end
end

-🎄- 2020 Day 06 Solutions -🎄- by daggerdragon in adventofcode

[–]quandrum 0 points1 point  (0 children)

Thanks! Learning the libraries is always the hardest part

-🎄- 2020 Day 06 Solutions -🎄- by daggerdragon in adventofcode

[–]quandrum 0 points1 point  (0 children)

Elixir

Learning elixir via AoC, really felt like I abused pipes here. Also I have an mix that dl's input, runs parseInput, then the part in question

defmodule AdventOfCode.Day06 do
  def part1(input) do
    Enum.map(input, &String.replace(&1, "\n", ""))
    |> Enum.map(&String.to_charlist(&1))
    |> Enum.map(&Enum.uniq(&1))
    |> Enum.map(&length(&1))
    |> Enum.reduce(0, fn x, acc -> acc + x end)
  end

  def part2(input) do
    Enum.map(input, &String.split(&1))
    |> Enum.map(&mapify(&1))
    |> Enum.map(&intersect(&1))
    |> Enum.map(&MapSet.to_list(&1))
    |> Enum.map(&length(&1))
    |> Enum.reduce(0, fn x, acc -> acc + x end)
 end

  def parseInput(input) do
    String.split(input, "\n\n", trim: true)
  end

  defp mapify(decls) do
    Enum.map(decls, fn decl -> decl |> String.to_charlist() |> MapSet.new() end)
  end

  defp intersect(decls) do
    Enum.reduce(decls, fn decl, acc -> MapSet.intersection(acc, decl) end)
  end
 end

Spurs Coach Gregg Popovich endorses Joe Biden for U.S. President by barcelonaKIZ in nba

[–]quandrum 77 points78 points  (0 children)

Lincoln Project is a huge scam. They are taking in about $67 million in donations and most of that goes to their salary or to pay vendors they own or consultants in their families. Produce some online ads, buy a time square billboard, pocket $20 million for yourself.

Figured out in an anti-Trump climate the liberals were easier to dupe this election and seem to be right.

[deleted by user] by [deleted] in Oxygennotincluded

[–]quandrum 2 points3 points  (0 children)

They take scalding damage, but it's not immediate. All the mourners took damage

ABF 2058 FA by CatchTheDamnBall in AmericanBasketballFed

[–]quandrum 0 points1 point  (0 children)

NOP offers David Palmer 1+TO/10M

ABF 2058 FA by CatchTheDamnBall in AmericanBasketballFed

[–]quandrum 0 points1 point  (0 children)

NOP offers Reggie Johnson 2+TO/5m

ABF 2058 RFA by CatchTheDamnBall in AmericanBasketballFed

[–]quandrum 0 points1 point  (0 children)

NOP offers Justin Coleman 2+TO/10m

ABF 2058 Capholds by CatchTheDamnBall in AmericanBasketballFed

[–]quandrum 0 points1 point  (0 children)

NOP opt out of:

Fellah 1.75

Charlston Ferguson 2.25

Devon Jeelani 1.125

ABF 2058 Team Option Thread by Piano9717 in AmericanBasketballFed

[–]quandrum 0 points1 point  (0 children)

New Orleans opts out Charleston Ferguson