MCPcopy Create free account
hub / github.com/AxlLind/AdventOfCode / create_graph

Function create_graph

2019/src/bin/20.rs:183–196  ·  view source on GitHub ↗
(map: &[Vec<char>], portals: &[(String, usize, usize)])

Source from the content-addressed store, hash-verified

181}
182
183fn create_graph(map: &[Vec<char>], portals: &[(String, usize, usize)]) -> Graph {
184 let mut g = (0..W).cartesian_product(0..H)
185 .filter(|&(i,j)| map[i][j] == '.')
186 .map(|(i,j)| {
187 let neighbours = [(i-1,j), (i+1,j), (i,j-1), (i,j+1)].iter()
188 .filter(|&&(x,y)| map[x][y] == '.')
189 .map(|&(x,y)| (x,y,EdgeType::Normal))
190 .collect();
191 ((i,j), neighbours)
192 })
193 .collect();
194 connect_portals(&mut g, portals);
195 g
196}
197
198fn bfs_part_one(graph: &Graph, (x,y): (usize,usize), goal: (usize,usize)) -> usize {
199 let mut queue = VecDeque::new();

Callers 1

mainFunction · 0.85

Calls 1

connect_portalsFunction · 0.85

Tested by

no test coverage detected