From 43ab0a3a7a1e095f5f33f224ce73c413f49e156c Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sun, 2 Dec 2018 12:41:05 +0000 Subject: Initial commit --- day02/Dockerfile | 7 ++ day02/Makefile | 10 +++ day02/entrypoint | 10 +++ day02/input | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ day02/part1 | 26 ++++++ day02/part2 | 33 ++++++++ 6 files changed, 336 insertions(+) create mode 100644 day02/Dockerfile create mode 100644 day02/Makefile create mode 100755 day02/entrypoint create mode 100644 day02/input create mode 100755 day02/part1 create mode 100755 day02/part2 (limited to 'day02') diff --git a/day02/Dockerfile b/day02/Dockerfile new file mode 100644 index 0000000..5e0a8b7 --- /dev/null +++ b/day02/Dockerfile @@ -0,0 +1,7 @@ +FROM ruby:2.5-slim + +WORKDIR /opt + +COPY . . + +ENTRYPOINT ["./entrypoint"] diff --git a/day02/Makefile b/day02/Makefile new file mode 100644 index 0000000..40af6b1 --- /dev/null +++ b/day02/Makefile @@ -0,0 +1,10 @@ +DAY = 02 + +.PHONY: run + +run: build + sudo docker run -it --rm aoc2018day$(DAY) + +build: + sudo docker build -t aoc2018day$(DAY) . + touch build diff --git a/day02/entrypoint b/day02/entrypoint new file mode 100755 index 0000000..cff9f4c --- /dev/null +++ b/day02/entrypoint @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ -x part1 ] ; then + echo -ne "Part 1:\n\t" + ./part1 < input +fi +if [ -x part2 ] ; then + echo -ne "Part 2:\n\t" + ./part2 < input +fi diff --git a/day02/input b/day02/input new file mode 100644 index 0000000..69850ae --- /dev/null +++ b/day02/input @@ -0,0 +1,250 @@ +tjxmoewpqkyaiqvmndgflunszc +tjxmobwpqkyaihvrndgfjubszm +tjxmzewpqkyaihvrydgflrbszc +tjxmoeypqkyvihvrndgflubsza +tjcmoewpqkytihvrndgflgbszc +tjvmoewpqkyanevrndgflubszc +tjxmoewpqkdiihirndgflubszc +tjxboewpqkyaihbrnogflubszc +ojpmoewpqkyaihvjndgflubszc +tjxyoewpqkyaiuvrndgflutszc +tjxmoewpqkyalhvrndmflebszc +tjxmoewpqzyaihhrndgflubszf +tjxmrewpqkyaihirndgfjubszc +pjxmoewpqkyaihvendgfbubszc +txxmkewpqkyjihvrndgflubszc +tjxmoewcqkyaihvrnmgflubczc +tjxmoewkqkyaghvrndgfluvszc +tjxmoewfqkhaihvrndgflubhzc +jjqmoewpqkyaihvrndzflubszc +tjxmoewmqksaihvcndgflubszc +tjrmoewpqkyaihvrvdgflubzzc +tjxxoewpqkyaiiwrndgflubszc +cjxmoawxqkyaihvrndgflubszc +tjxdoewpvkyaihvrndgflubsoc +tjxmsewpqkyaihvrndgfluzozc +tjxmoewpqkyafhvrnyeflubszc +tjxmlewpqkyawhvondgflubszc +tjxmonwpqkyaiqvrnxgflubszc +tjxmoewcqkyaihvrnjgflumszc +tjvmoewpqkyaihveadgflubszc +tjxmogfpqkyaigvrndgflubszc +tybmoewpqkyaihvrndgllubszc +tjxmoewpdkyaihvrndgfluwbzc +etxmbewpqkyaihvrndgflubszc +tjxmoeapqcynihvrndgflubszc +tbxmoewpqkyaihvrndgfdebszc +haxmoewpqyyaihvrndgflubszc +ojxmoewpqkyaihvrnegflubszr +tjxmoewpqkyaihvrndoflubarc +ljxmoewpqkykihvrndgflvbszc +tjxmovwpqkyaihvrndgfluzsyc +tvxmoewpqkyanhvrkdgflubszc +tjxmoewpqkyaihkrndgfluwwzc +zjxmoewpfkyaihvrndgfrubszc +tjxyoegpqkyaihvrndlflubszc +tjxmoewpqkyamhvrnsgflubmzc +tjmmoewpqkyaihvrndgftuwszc +tjxmoewpqbraihvrncgflubszc +tjxmeeepqkyainvrndgflubszc +tjemoegpqkyaihvredgflubszc +tjxmoewpqkyaihvdndgfzubqzc +tjxmoegrqkyaihfrndgflubszc +tjxmoewpqxyaihvrndgfluyvzc +qjxmoewpqkyaiwvrnfgflubszc +tjxwoewpqkyashkrndgflubszc +tjzmoewiqkyaihurndgflubszc +tjumuewpqkyaihvrndgflubssc +tyxooewpukyaihvrndgflubszc +tjxvoewpqkyaiivindgflubszc +ijxmoqwpqkyaihvradgflubszc +tjxmlewpqkyaihvrhdgflubwzc +tjxmkewpqkyajhqrndgflubszc +tjxmoewpqkqaiherndgflurszc +tjamoewpqkyaizvondgflubszc +tjxgogwpqkyalhvrndgflubszc +tjxmoewpqkyachvrndgflubuzq +tjxmowqpqkyaihvrnegflubszc +mjxmoewpwkyaihvrndgfkubszc +tpbmoewpqkyaihvrzdgflubszc +tjbmoewpqkyaiuvrndgflsbszc +tjxmoewpqklaghvrndgflubazc +tjxmoewpqkyrihvrndgwlpbszc +tjcmoewpqksaiyvrndgflubszc +tjxmoeapqkymihvindgflubszc +tjxmdewpqkyafhvrndgflqbszc +tjxmoewpqxyaihvrndsflubszi +tjxmoeppqkyaihvrcdgflubszd +tjxmomwpqkyainvrmdgflubszc +tjxmovwpqkyaihvrndgfdubdzc +tjxmoewwqkiaihvrjdgflubszc +tmxmoewpqkyaifvrndgflubszs +tbxmoewpqkyaihvrbdgflunszc +tjxmoewrqkyaihvxndgflubszp +ujxmoewpqkyaihvxndgflubpzc +tdxmotwpqkyaihvdndgflubszc +tjxmvewpqkyaihfrndgtlubszc +tjfmoewpqkyaihvrnyqflubszc +tjxfolwzqkyaihvrndgflubszc +ojrmoiwpqkyaihvrndgflubszc +tjsmoqwpqkyqihvrndgflubszc +tjxmohwpqkyaihvrudgflubslc +tjxtoiwpqkyaihvrnogflubszc +taxmoewpqkyaiyvrndgfwubszc +tjxwnezpqkyaihvrndgflubszc +tjxmyevpqkyaivvrndgflubszc +tjxdoeopqkyaihvgndgflubszc +tjxaoewpqkmaihvrndgflufszc +tjxmoewpqkyaxhvrndgflubncc +tjxmoewpqkyaihurndgflubbjc +tjxmjewpqgyaihvrnngflubszc +tjxmogwpqkyaihvrndgflubbcc +tjxmoewplkyaihvrnpgflibszc +tjwmoewpqkyaohvrndgfbubszc +tjwmoewpqkyaihvrndgfsubszm +tjxmogwpqkyaihvrndiflubqzc +tjxmoewpqkyaihvrndgflopshc +rjxmlewpvkyaihvrndgflubszc +tjxmogwpakyaihvrndgflzbszc +tjxmoeppqkyaihvrndgflmxszc +tjxmoewpqkyhihgrndgfzubszc +tjxqoewpqkyaihtrndgwlubszc +tjxnoespqkyaihvrndgflubsuc +tjmmoewpqkraihvrndgflfbszc +tjxmoewnqkwaihvrndgflubstc +tjxmoewpqqyaihvrndgfljbszi +tjxmoewpqkyaihkrkdgalubszc +tjxmoewpqkyaihvradgjlurszc +tvxmoewpqkybihvrndbflubszc +tjxvoewpqkyaihvradgfoubszc +tjxmoewpqfyaihvlodgflubszc +tjxmoewmnkyaiivrndgflubszc +kjxmoewpqkyaihprndgflcbszc +hjxmoewpqkcaihvrndgvlubszc +tjxmoewcqkyaihvrncgfllbszc +tuxmoewpckyaihvrndoflubszc +tjxmdewpokyaihvrndgflubszn +mjxmaewpqkyaqhvrndgflubszc +tjxmoewpmzyaihvrndgfiubszc +tjxmoewnqkyvihvrndgflubszk +tjxmoewpmnyaihvrndgftubszc +zjxmoewpqkysihvrndgfmubszc +tjxmoewpqkyaihzrntgflubbzc +tjxmoewpqkgaihwrndsflubszc +tjxjoewpqkyaihvrndgflgbizc +oqxmoewpqkyaihvrndgfldbszc +wjamoewpqkyaihvfndgflubszc +tjxmoewtmkyvihvrndgflubszc +tjlmojwpqkyaihvrndgfludszc +tjxmowwpqkyaihvrndefludszc +tjxmoewpqkbaihvrndgfluaszt +tjxmoewpqkzaahvrodgflubszc +tjxmoewpqkgaihvrndgflubtpc +tjxmoenpqkyaihcrndgfqubszc +tbxmoewpqbyaihvrndgalubszc +tjvmoewqqkyaihvrndvflubszc +tjxmoewpqkeaihvundgfaubszc +txxmoewpqkyaihvrwdgflpbszc +tzxmoewpqkijihvrndgflubszc +tjxmoewoqkytiuvrndgflubszc +tjxmrejplkyaihvrndgflubszc +tjxmoewpqkynihvrpxgflubszc +tjxmoewpqkvanhvrndgvlubszc +tjxmoewpdkyiihvrndgflubszs +tpxmyewpqkyaihvrndgfeubszc +tpxmoewpqyyaihvrndhflubszc +tjsmoewpqkyaihvrndhflubnzc +tjxmoewpukyaihvrnmgflubwzc +txxmoewpqlyaihwrndgflubszc +tjxmoewprkyaiovrndgflubxzc +tjxmouwpqkyaihzrodgflubszc +tjxmojwpqkywimvrndgflubszc +tjxsoewpqkyaihvrzdgqlubszc +tfxmoewpakyaihvrndgllubszc +tjhmoewpqiyaihvrndgflubsac +tjxmoewpqkoaihvrndoflubsxc +tjxmoewpqkyzpjvrndgflubszc +tjxmoewpqkyaiharndgzlnbszc +tjimoevpqkyaihvrndgflubbzc +tjxsoewpqkyahhvrndgfzubszc +txxmoewpqkyaimvrrdgflubszc +tjxmoewpwkyaihvrndpylubszc +tjxmoewpskyaghvrndgfbubszc +tjxmuewpqmyaihvrndgfyubszc +tjxmoewpqkyaihvdndgglubsxc +xjxmoewpqkyjiovrndgflubszc +gjxmoewpqkyaihvrndodlubszc +tjbmoewpqkyaihvridgflvbszc +tjxmozwpqkyapbvrndgflubszc +tjxeoewpqkyqihvrndgflubhzc +tjxdoewpqzyaihvrndgflubsmc +tjxmwewpqkyathvcndgflubszc +tjxmoewpszyaihvrndgflusszc +tuxmoewpqkyaihvrndgfluasxc +tjemoewpnvyaihvrndgflubszc +tjxmoewpjkyaihvrndgjlufszc +tjomoewppkyaihvzndgflubszc +tjxmvewpqkyaimvrntgflubszc +rjxmoewpqkyaihvpndgflubszq +hjxzoewpqkyaihvridgflubszc +texmoejpqkyaihvrndgflubszx +tjxcoewpqkyaihbrxdgflubszc +tjxmoewpnkyaihvrndgfltbsze +tjxmoewpdkyaihvrndwfluwbzc +tjxmoewpqryjihkrndgflubszc +tjlmoewpqkhaihvrndgflubsnc +tjxmovapqkjaihvrndgflubszc +tjxvoewpqkyaihqrndgfluyszc +tjxwoewnqkyaihvrndgfgubszc +tjdmoewpqklaihvcndgflubszc +tjxmoewpvkynihvrndgflubskc +tjxmtewpqkyaihvhndgfluaszc +tjxmoewpqkyanhvrnpgfluvszc +tjxmoewpqkyaifvbndgflubspc +tjxmoexpqknaihvrndgxlubszc +qjxmoewqqkyaihvrndgflubpzc +tjxmoewppkyaihvaxdgflubszc +myxmoewpqkyaihvrudgflubszc +tjxmwewpmkyaihvrndgflubssc +tjxmoewpqkyaihvrndgfxqbszq +tjxmoewhqkyaahvrndgflubbzc +tbxmoewmqkyaihvrndgflubszu +toxmolwpqkyaihvrndnflubszc +tjxmoewhqkyaihvrnrgflubvzc +yjxmoewcqkyaihvrndgflubfzc +tjxmoewpqkyamhvrgdgflmbszc +tjxmtewpqkyaizvrndgfluoszc +tjxmoewpqzyaihvrntsflubszc +fjxmoewpqkyaihyrmdgflubszc +tjxwoewpqcyaihbrndgflubszc +tjxmoebpqkzaihvrndcflubszc +tjxmoewpqkyaihvrndnlmubszc +tjxmoewpqkyaihvrndgeyubskc +tfxmoewpqryaihvrndgfluiszc +tjxmoewpqkjaihvynngflubszc +tjxmoewpqkqaihvonjgflubszc +tjfmokwpqkyeihvrndgflubszc +djxmoewpkkyaihvrnmgflubszc +tjxmiewpqkyaihvrndgflubhlc +tjxmmejpqkyaihvrnhgflubszc +djxmoewmqkyaihvrnggflubszc +tjxmoewpqkyaihvrkggflubsze +gjxmoewpqkyaihjrndgflvbszc +tjxmoewpqkyaidvrndgkzubszc +tjxmoewpqkyaedvrnpgflubszc +sjxmoewpqkyaihvrnngfluhszc +tjxmoewpqkuaihvrndghlubxzc +tjxmoewgqkyuihvrndgftubszc +tjxmoewpqsyaifvrkdgflubszc +tjxrrewpqkyaihvrnpgflubszc +tjxmoezpqkyaihvrwdgflabszc +tjfmoewpqknaihvrndgflubkzc +tjxmoewnqkxaihvrndgflubtzc +tjxmoewpkkyaihvrndgfrnbszc +tjxmorwpnkqaihvrndgflubszc +tsxmoewwqkyathvrndgflubszc +tjxmoeupqkyaihvrndyflubszp +bjxmoewdqkyaihvrndgflurszc +tjxmoewpvkyaihvrndoflubszq +sjxmoewpqkyaihvrndgflubyec +tjxmoewpqkyaizcrndgfnubszc diff --git a/day02/part1 b/day02/part1 new file mode 100755 index 0000000..dca8ec2 --- /dev/null +++ b/day02/part1 @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby + +class Integer + def two? + self == 2 + end + def three? + self == 3 + end +end + +input = $stdin.readlines.map(&:chomp) + +twos = 0 +threes = 0 + +input.each do |i| + hash = Hash.new(0) + i.chars.each do |c| + hash[c] += 1 + end + twos += 1 if hash.values.map(&:two?).any? + threes += 1 if hash.values.map(&:three?).any? +end + +puts twos * threes diff --git a/day02/part2 b/day02/part2 new file mode 100755 index 0000000..aa82247 --- /dev/null +++ b/day02/part2 @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby + +class String + def distance(other) + sa = self.chars + oa = other.chars + d = 0 + (0...self.length).each do |i| + d += 1 if sa[i] != oa[i] + end + return d + end + + def difference(other) + sa = self.chars + oa = other.chars + (0...self.length).each do |i| + sa[i] = nil if sa[i] != oa[i] + end + return sa.join + end +end + +input = $stdin.readlines.map(&:chomp) + +(0...input.length).each do |i| + (i...input.length).each do |j| + if input[i].distance(input[j]) == 1 + puts input[i].difference(input[j]) + exit + end + end +end -- cgit v1.2.1