summary refs log tree commit diff homepage
path: root/2021
diff options
context:
space:
mode:
Diffstat (limited to '2021')
-rw-r--r--2021/day03.pl17
1 files changed, 17 insertions, 0 deletions
diff --git a/2021/day03.pl b/2021/day03.pl
new file mode 100644
index 0000000..8a62021
--- /dev/null
+++ b/2021/day03.pl
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+my @nums;
+while (<>) {
+	chomp;
+	push @nums, oct("0b".$_);
+}
+my $gamma = 0;
+for (my $i = 0; $i < 12; $i++) {
+	my $ones = 0;
+	foreach (@nums) {
+		$ones++ if $_ & (1 << $i);
+	}
+	$gamma |= 1 << $i if $ones > @nums / 2;
+}
+my $epsilon = ~$gamma & 0xFFF;
+print $gamma * $epsilon, "\n";
atgirl/commit/ui.c?h=somasis/tokipona&id=5bb96a79e76d92fa7ce9839a151a778f79d0ef06&follow=1'>Initialize all possible color pairsJune McEnroe 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe 2018-08-04Handle /topicJune McEnroe