From cc8f474aeca07cebe23fa60c153c84b6a256f2e0 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 12 Dec 2021 12:38:09 -0500 Subject: Solve day 12 part 1 --- 2021/day12.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2021/day12.pl (limited to '2021') diff --git a/2021/day12.pl b/2021/day12.pl new file mode 100644 index 0000000..ceef3e0 --- /dev/null +++ b/2021/day12.pl @@ -0,0 +1,27 @@ +use strict; +use warnings; +my %edges; +while (<>) { + /(\w+)-(\w+)/; + $edges{$1} //= []; + $edges{$2} //= []; + push @{$edges{$1}}, $2; + push @{$edges{$2}}, $1; +} +my $paths = 0; +my @queue = (['start']); +while (@queue) { + my @path = @{shift @queue}; + my %visited = map { $_ => 1 } @path; + for (@{$edges{$path[0]}}) { + if ($_ eq 'end') { + $paths++; + } elsif (/[a-z]/ && $visited{$_}) { + next; + } else { + my @next = ($_, @path); + push @queue, \@next; + } + } +} +print "$paths\n"; -- cgit 1.4.1 --- web frontend for git
about summary refs log tree commit diff
path: root/filters (unfollow)
Commit message (Expand)Author
2014-01-12cache: don't leave cache_slot fields uninitializedJohn Keeping
2014-01-10filter: split filter functions into their own fileJason A. Donenfeld
2014-01-10filter: make exit status localJason A. Donenfeld
2014-01-10parsing: fix header typoJason A. Donenfeld
2014-01-10cgit.c: Fix comment on bit mask hackLukas Fleischer
2014-01-10cgit.c: Use "else" for mutually exclusive branchesLukas Fleischer
2014-01-10ui-snapshot.c: Do not reinvent suffixcmp()Lukas Fleischer
2014-01-10Refactor cgit_parse_snapshots_mask()Lukas Fleischer
2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer
2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer
2014-01-09README: Fix dependenciesLukas Fleischer
2014-01-08README: Spelling and formatting fixesLukas Fleischer
2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch
2014-01-08Add a suggestion to the manpagePřemysl Janouch
2014-01-08Fix the example configurationPřemysl Janouch
2014-01-08Fix about-formatting.shPřemysl Janouch
2014-01-08Fix some spelling errorsPřemysl Janouch
2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts