Skip to content

Commit

Permalink
Use bfs instead of dfs. It's faster for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 16, 2023
1 parent 0ccffa4 commit 8d90166
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions solutions/src/2023/16.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Maintainer : emertens@gmail.com
<https://adventofcode.com/2023/day/16>
This is a pretty straight forward depth-first traversal of the
This is a pretty straight forward breadth-first traversal of the
state space. I represent nodes of the "graph" being searched
as pairs of a location and a direction vector. At each step
the location is used to look up the tile and the direction
Expand Down Expand Up @@ -36,7 +36,7 @@ module Main (main) where

import Advent (getInputArray, arrIx, ordNub)
import Advent.Coord (east, invert, invert', north, origin, south, west, Coord(C))
import Advent.Search (dfs)
import Advent.Search (bfs)
import Data.Array.Unboxed (inRange, bounds, UArray )

-- | Parse the input grid and print answers to both parts.
Expand All @@ -52,7 +52,7 @@ main =

-- | Count the number of energized tiles given an input beam.
solve :: UArray Coord Char -> (Coord, Coord) -> Int
solve input = length . ordNub . map fst . dfs (step input)
solve input = length . ordNub . map fst . bfs (step input)

-- | Find all the incoming light possibilities for part 2
edges :: (Coord, Coord) -> [(Coord, Coord)]
Expand Down

0 comments on commit 8d90166

Please sign in to comment.