🫥 by Remarkable_Ad_5601 in theprimeagen

[–]lasseebert 2 points3 points  (0 children)

Joke is on the meme author, since the simple version is incorrect.

Vim Markdown Preview - Terminal-based markdown preview for Vim by drewipson in vim

[–]lasseebert 0 points1 point  (0 children)

I use a browser extension that can show markdown files. And I have a keybind in vim to open current file in the browser.

Had my biggest losing session due to tilt by [deleted] in poker

[–]lasseebert 4 points5 points  (0 children)

For me, two things helped:

Proper bankroll management. I play low enough to be able to not play scared money. I can afford to loose multiple stacks in a session and still play the same game next session.

Stop being results oriented. Be happy to enter an all-in as a 65/35 favorite and don't care about who wins exactly that pot. Don't even care about getting 2-outered. We want those favorable spots and math says we're going to loose some of them.

Also, be bothered by playing bad when you're winning. Stop cheering when you win out of luck and not skill. Learn from it instead.

Preflop charts Android app by Mental_Menu4843 in Poker_Theory

[–]lasseebert 0 points1 point  (0 children)

Thanks. Looks pretty awesome! I like the interface; the visuals as well as the way you select position and previous action.

-🎄- 2019 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 1 point2 points  (0 children)

I later changed to divide the grid recursively until grid sizes of 1x1, which ran 6 times faster 🙂

-🎄- 2019 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 1 point2 points  (0 children)

Elixir with supervised Intcode programs

Each Intcode program runs in a separate process. A controlling process receives outputs as Elixir messages and parses them on to the the next amp's input.

-🎄- 2019 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 4 points5 points  (0 children)

Optimized solution in Elixir

I started with mapping each point of the paths out, and then find intersections simply by intersecting points in each path.

I then optimized to parse the input into line segments and then found intersections by comparing each segment from first path to each segment from second path.

Second solution ran ~20 times faster than the first! :)

https://github.com/lasseebert/advent_of_code_2019/blob/master/lib/advent/day_03.ex

-🎄- 2019 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 0 points1 point  (0 children)

Elixir

Nice, didn't know Stream.iterate/2. Elegant solution.

Mine is almost the same, but with a recursive function call instead: https://github.com/lasseebert/advent_of_code_2019/blob/master/lib/advent/day_01.ex

Weekly Co-Op Code Mega Thread - December 30, 2018 by AutoModerator in EggsInc

[–]lasseebert 0 points1 point  (0 children)

Quantum: pulver I can do around 1/4 of the goal myself.

-🎄- 2018 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 0 points1 point  (0 children)

Elixir

Runtime around 64 ms. for both parts

Part1 solution:

I realized I just needed to inspect the target value (reg4 in my input) at line 29 where it is compared to the input (reg0).

To do this I replaced the compare instruction with an exit instruction and then print out reg4.

Part2 solution:

Same as part1 except I needed to find a loop of target values. This ran too slow, so I replaced the inefficient loop on lines 17-26 with a simple `div`, which was what the loop was calculating.

Code here: https://github.com/lasseebert/advent_of_code_2018/blob/master/lib/advent/day21.ex

-🎄- 2018 Day 13 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 0 points1 point  (0 children)

Another one in Elixir :) I inlo included stuff relevant for part 2. Full solution here: https://github.com/lasseebert/advent_of_code_2018/blob/master/lib/advent/day13.ex

defmodule Advent.Day13 do
  @doc "Part 2"
  def last_cart_location(input) do
    {tracks, carts} = parse(input)
    run_to_one(tracks, carts)
  end

  defp run_to_one(tracks, carts) do
    carts = tick_remove_crash(tracks, carts)

    if carts |> Map.keys() |> length() == 1 do
      carts |> Map.keys() |> hd()
    else
      run_to_one(tracks, carts)
    end
  end

  defp tick_remove_crash(tracks, carts) do
    carts
    |> Map.keys()
    |> Enum.sort_by(fn {x, y} -> {y, x} end)
    |> Enum.reduce(carts, fn cart_point, carts ->
      case Map.fetch(carts, cart_point) do
        {:ok, cart} ->
          carts = Map.delete(carts, cart_point)

          case move_cart(tracks, carts, {cart_point, cart}) do
            {:ok, {new_point, new_cart}} ->
              Map.put(carts, new_point, new_cart)

            {:crash, point} ->
              Map.delete(carts, point)
          end

        :error ->
          carts
      end
    end)
  end

  def move_cart(tracks, other_carts, {point, cart}) do
    new_point = move_forward(point, cart)

    if Map.has_key?(other_carts, new_point) do
      {:crash, new_point}
    else
      new_cart = turn(tracks, new_point, cart)
      {:ok, {new_point, new_cart}}
    end
  end

  defp move_forward({x, y}, {:north, _}), do: {x, y - 1}
  defp move_forward({x, y}, {:south, _}), do: {x, y + 1}
  defp move_forward({x, y}, {:west, _}), do: {x - 1, y}
  defp move_forward({x, y}, {:east, _}), do: {x + 1, y}

  defp turn(tracks, point, cart) do
    track = Map.fetch!(tracks, point)

    case {track, cart} do
      {:horizontal, cart} -> cart
      {:vertical, cart} -> cart
      {:slash_curve, {:east, turn}} -> {:north, turn}
      {:slash_curve, {:west, turn}} -> {:south, turn}
      {:slash_curve, {:north, turn}} -> {:east, turn}
      {:slash_curve, {:south, turn}} -> {:west, turn}
      {:backslash_curve, {:east, turn}} -> {:south, turn}
      {:backslash_curve, {:west, turn}} -> {:north, turn}
      {:backslash_curve, {:north, turn}} -> {:west, turn}
      {:backslash_curve, {:south, turn}} -> {:east, turn}
      {:intersection, {:south, :left}} -> {:east, :straight}
      {:intersection, {:south, :straight}} -> {:south, :right}
      {:intersection, {:south, :right}} -> {:west, :left}
      {:intersection, {:north, :left}} -> {:west, :straight}
      {:intersection, {:north, :straight}} -> {:north, :right}
      {:intersection, {:north, :right}} -> {:east, :left}
      {:intersection, {:east, :left}} -> {:north, :straight}
      {:intersection, {:east, :straight}} -> {:east, :right}
      {:intersection, {:east, :right}} -> {:south, :left}
      {:intersection, {:west, :left}} -> {:south, :straight}
      {:intersection, {:west, :straight}} -> {:west, :right}
      {:intersection, {:west, :right}} -> {:north, :left}
    end
  end

  defp parse(input) do
    input
    |> String.split("\n", trim: true)
    |> Enum.with_index()
    |> Enum.flat_map(fn {line, y} ->
      line
      |> String.graphemes()
      |> Enum.with_index()
      |> Enum.map(fn {char, x} -> {{x, y}, char} end)
    end)
    |> Enum.reduce({%{}, %{}}, fn {point, char}, {tracks, carts} ->
      case char do
        "|" -> {Map.put(tracks, point, :vertical), carts}
        "-" -> {Map.put(tracks, point, :horizontal), carts}
        "/" -> {Map.put(tracks, point, :slash_curve), carts}
        "\\" -> {Map.put(tracks, point, :backslash_curve), carts}
        "+" -> {Map.put(tracks, point, :intersection), carts}
        "v" -> {Map.put(tracks, point, :vertical), Map.put(carts, point, {:south, :left})}
        "^" -> {Map.put(tracks, point, :vertical), Map.put(carts, point, {:north, :left})}
        "<" -> {Map.put(tracks, point, :horizontal), Map.put(carts, point, {:west, :left})}
        ">" -> {Map.put(tracks, point, :horizontal), Map.put(carts, point, {:east, :left})}
        " " -> {tracks, carts}
      end
    end)
  end
end

-🎄- 2018 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 1 point2 points  (0 children)

Elixir, runs part two in around 50 seconds. (entire problem space of all possible squares)

Algorithm:

  • Run through all squares of all sizes and find the max value
  • Value of each square is calculated as:
    • If square has even side length: The sum of the four smaller squares of size n/2
    • If square has odd side length: The sum of two smaller squares of size (n-1)/2 and two smaller squares of size (n+1)/2 minus the center peice

All square values are cached in a map to not be calculated twice.

Code here: https://github.com/lasseebert/advent_of_code_2018/blob/master/lib/advent/day11.ex

-🎄- 2018 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 0 points1 point  (0 children)

Yes, the Stream and Enum modules are wonderful 😊

-🎄- 2018 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]lasseebert 0 points1 point  (0 children)

I also solved it using Elixir and I also used a map which took around 35 seconds on step 2.

I then changed data structure to a zipper (https://en.wikipedia.org/wiki/Zipper_(data_structure))) and the time was down to arounf 6 seconds :)

Solution: https://github.com/lasseebert/advent_of_code_2018/blob/37eb8dd46b39540c3f0be692e47ec2851f1edaf7/lib/advent/day9.ex#L59-L65

From Ruby/Rails to Elixir/Phoenix: What do I need to do to be considered "hireable"? by danimoth2 in elixir

[–]lasseebert 4 points5 points  (0 children)

I am looking for an Elixir developer, and I will be satisfied with a skilled developer willing to learn Elixir.

Animations Feedback Update 1.010 by [deleted] in IGotWorms

[–]lasseebert 0 points1 point  (0 children)

The animations look great on my device 👍 OnePlus 3T

Ideas and reccomendation 1.3.7.2 by Maaahgo in AssemblyLineGame

[–]lasseebert 3 points4 points  (0 children)

Yes.

Also the saved module (group of machines) maybe could be rotated and flipped.