This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Advent of Code Day 4




Hyperlinks



Highlights

  • Nothing too extraordinary with right now’s downside. For the second half, I began by solely checking to see if both endpoint of 1 elf was throughout the endpoints of the opposite elf. Truthfully, I nonetheless cannot determine why this did not work, and I needed to do the identical examine within the different route. Perhaps it would come to me in some unspecified time in the future right now.
defmodule Day04 do
  use AOC

  def part1 do
    enter(4)
    ~> String.break up("n")
    ~> Enum.map(fn pair ->
      ends = Regex.named_captures(~r/(?<l1>.*)-(?<h1>.*),(?<l2>.*)-(?<h2>.*)/, pair)
      ~> Map.new(fn {key, worth} -> {String.to_atom(key), String.to_integer(worth)} finish)
      (ends.l1 <= ends.l2 && ends.h1 >= ends.h2) ||
      (ends.l2 <= ends.l1 && ends.h2 >= ends.h1)
    finish)
    ~> Enum.depend(&Perform.id(&1))
  finish

  def part2 do
    enter(4)
    ~> String.break up("n")
    ~> Enum.map(fn pair ->
      ends = Regex.named_captures(~r/(?<l1>.*)-(?<h1>.*),(?<l2>.*)-(?<h2>.*)/, pair)
      ~> Map.new(fn {key, worth} -> {String.to_atom(key), String.to_integer(worth)} finish)
      (ends.l1 >= ends.l2 && ends.l1 <= ends.h2) ||
      (ends.h1 >= ends.l2 && ends.h1 <= ends.h2) ||
      (ends.l2 >= ends.l1 && ends.l2 <= ends.h1) ||
      (ends.h2 >= ends.l1 && ends.h2 <= ends.h1)
    finish)
    ~> Enum.depend(&Perform.id(&1))
  finish

finish
Enter fullscreen mode

Exit fullscreen mode

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?