Skip to content

Instantly share code, notes, and snippets.

@devster31
Last active December 25, 2015 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devster31/4553990226d3369a0e1c to your computer and use it in GitHub Desktop.
Save devster31/4553990226d3369a0e1c to your computer and use it in GitHub Desktop.
Advent of Code challenges - http://adventofcode.com
string = "<example string>"
string.count('(') - string.count(')')
count = 0
string.split('').each_with_index { |char, index|
if char == '(' then
count += 1
elsif char == ')' then
count -= 1
end
if count == -1 then
puts "#{count} #{index + 1}"
end
}
'use strict';
var string = '3113322113';
let input = string // or var for before 2015 , document.querySelector('.puzzle-input').textContent,
lookAndSay = s => s.match(/(\d)\1*/g).map(s => s.length + s[0]).join(''),
iterate = (n, s) => new Array(n).fill().reduce(lookAndSay, s);
let step40 = iterate(40, input);
console.log(step40.length, iterate(10, step40).length);
from itertools import groupby
def look_and_say(input_string, num_iterations):
for i in xrange(num_iterations):
input_string = ''.join([str(len(list(g))) + str(k) for k, g in groupby(input_string)])
return input_string
input = '3113322113'
50.times { input = input.gsub(/(.)\1*/) { |s| s.size.to_s + s[0] } }
puts input.length
##################################################
def look_and_say(input)
input.slice_when{|i, j| i != j}.to_a.map{|el| [el.length, el.first]}.flatten
end
answers = ["3113322113".chars.map(&:to_i)]
1.upto(50) {|x| answers << look_and_say(answers.last)}
puts answers.last.count
import re
from string import ascii_lowercase
#def consec(string):
# slist = [string[i:i+3] for i in range(0, len(string)-2)]
# condition = False
# for slic in slist:
# slic = [ord(char) for char in slic]
# if slic[0] == slic[1]-1 == slic[2]-2:
# condition = True
# break
# else:
# continue
# return condition
def nextp(string):
if string.endswith('z'):
return edge(string)
else:
return string[:-1] + nextl(string[-1])
#def edge(password):
# temp = password
# bound = 0
# while temp.endswith("z"):
# temp = temp[:-1]
# bound += 1
# return password[:-bound] + nextl(password[-bound]) + "a" * bound
def edge(s):
temp = s
bound = 0
while temp.endswith("z"):
temp = temp[:-1]
bound += 1
ret = ( temp[:-1] + nextl(temp[-1]) ) if len(temp) > 0 else ""
return ret + "a" * bound
def nextl(c):
try:
return ascii_lowercase[ascii_lowercase.index(c) + 1]
except IndexError: # z
return "a"
def validate(s):
# Requirement 1
for i in range(len(s) - 2):
if s[i:i+3] in ascii_lowercase:
break
else:
return False
# Requirement 2
if re.search(r"[iol]", s):
return False
# Requirement 3
return True if re.search(r"(\w)\1.*(\w)\2", s) else False
def main():
passwd = "hxbxwxba"
while not validate(passwd):
passwd = nextp(passwd)
print("Next password: {}".format(passwd))
next_passwd = nextp(passwd)
while not validate(next_passwd):
next_passwd = nextp(next_passwd)
print("Next next password: {}".format(next_passwd))
passwd = 'hxbxwxba'
r = Regexp.union [*?a..?z].each_cons(3).map(&:join)
passwd.succ! until passwd[r] && passwd !~ /[iol]/ && passwd.scan(/(.)\1/).size > 1
p s
import re
import json
s = 'jsonstring'
p = re.compile(r'-?\d+')
ma = re.findall(p, s)
num = list(map(int, ma)) # numbers = [ int(el) for el in x ]
sum(num)
jenc = json.loads(s)
def n(j):
if type(j) == int:
return j
if type(j) == list:
return sum([n(j) for j in j])
if type(j) != dict:
return 0
if 'red' in j.values():
return 0
return n(list(j.values()))
print(n(jenc))
require 'json'
string = 'jsonstring'
mp = JSON.parse(string)
$sum = 0
def dfs(mp)
return if mp.is_a? Hash and mp.values.include?('red')
(mp.is_a?(Array) ? mp : mp.values).each { |y| dfs(y) } if mp.class.method_defined? :each
$sum += mp if mp.is_a? Integer
end
dfs(mp)
p $sum
inp = '''Alice would gain 54 happiness units by sitting next to Bob.
Alice would lose 81 happiness units by sitting next to Carol.
Alice would lose 42 happiness units by sitting next to David.
Alice would gain 89 happiness units by sitting next to Eric.
Alice would lose 89 happiness units by sitting next to Frank.
Alice would gain 97 happiness units by sitting next to George.
Alice would lose 94 happiness units by sitting next to Mallory.
Bob would gain 3 happiness units by sitting next to Alice.
Bob would lose 70 happiness units by sitting next to Carol.
Bob would lose 31 happiness units by sitting next to David.
Bob would gain 72 happiness units by sitting next to Eric.
Bob would lose 25 happiness units by sitting next to Frank.
Bob would lose 95 happiness units by sitting next to George.
Bob would gain 11 happiness units by sitting next to Mallory.
Carol would lose 83 happiness units by sitting next to Alice.
Carol would gain 8 happiness units by sitting next to Bob.
Carol would gain 35 happiness units by sitting next to David.
Carol would gain 10 happiness units by sitting next to Eric.
Carol would gain 61 happiness units by sitting next to Frank.
Carol would gain 10 happiness units by sitting next to George.
Carol would gain 29 happiness units by sitting next to Mallory.
David would gain 67 happiness units by sitting next to Alice.
David would gain 25 happiness units by sitting next to Bob.
David would gain 48 happiness units by sitting next to Carol.
David would lose 65 happiness units by sitting next to Eric.
David would gain 8 happiness units by sitting next to Frank.
David would gain 84 happiness units by sitting next to George.
David would gain 9 happiness units by sitting next to Mallory.
Eric would lose 51 happiness units by sitting next to Alice.
Eric would lose 39 happiness units by sitting next to Bob.
Eric would gain 84 happiness units by sitting next to Carol.
Eric would lose 98 happiness units by sitting next to David.
Eric would lose 20 happiness units by sitting next to Frank.
Eric would lose 6 happiness units by sitting next to George.
Eric would gain 60 happiness units by sitting next to Mallory.
Frank would gain 51 happiness units by sitting next to Alice.
Frank would gain 79 happiness units by sitting next to Bob.
Frank would gain 88 happiness units by sitting next to Carol.
Frank would gain 33 happiness units by sitting next to David.
Frank would gain 43 happiness units by sitting next to Eric.
Frank would gain 77 happiness units by sitting next to George.
Frank would lose 3 happiness units by sitting next to Mallory.
George would lose 14 happiness units by sitting next to Alice.
George would lose 12 happiness units by sitting next to Bob.
George would lose 52 happiness units by sitting next to Carol.
George would gain 14 happiness units by sitting next to David.
George would lose 62 happiness units by sitting next to Eric.
George would lose 18 happiness units by sitting next to Frank.
George would lose 17 happiness units by sitting next to Mallory.
Mallory would lose 36 happiness units by sitting next to Alice.
Mallory would gain 76 happiness units by sitting next to Bob.
Mallory would lose 34 happiness units by sitting next to Carol.
Mallory would gain 37 happiness units by sitting next to David.
Mallory would gain 40 happiness units by sitting next to Eric.
Mallory would gain 18 happiness units by sitting next to Frank.
Mallory would gain 7 happiness units by sitting next to George.'''
import sys
import re
from itertools import permutations
pattern = re.compile(r'(\w+).+(gain|lose).(\d+).+?(\w+)(?=\.)')
people = set()
places = dict()
for line in inp.split("\n"):
found = re.match(pattern, line)
people.add(found.group(1))
people.add(found.group(4))
happy = int(found.group(3)) if found.group(2) == 'gain' else -int(found.group(3))
places.setdefault(found.group(1), dict())[found.group(4)] = happy
people.add('Me')
for x in people:
places.setdefault('Me', dict())[x] = 0
places.setdefault(x, dict())['Me'] = 0
modhappy = 0
for items in permutations(people):
temphappy = 0
for i in range(len(items)):
if i == len(items)-1:
temphappy += places[items[0]][items[-1]] +places[items[-1]][items[0]]
else:
temphappy += places[items[i]][items[i+1]] + places[items[i+1]][items[i]]
modhappy = max(temphappy, modhappy)
print("happyest: {:d}".format(modhappy))
##################################################
from re import findall
from itertools import permutations
m = {}
ppl = set()
for line in inp.split("\n"):
a, s, n, b = findall(r'(\w+) \w+ (\w+) (\d+) .* (\w+)\.', line)[0]
m[a+b] = int(n) * (1 if s == 'gain' else -1)
ppl.add(a)
def c(p):
L = len(p)
t = 0
for i in range(L):
t += m[p[i]+p[i-1]]
t += m[p[i]+p[(i+1) % L]]
return t
print(max([c(p) for p in permutations(ppl)]))
h = {}
r = /(\w+).+(\w) (\d+).+?(\w+)\./
inp.split("\n").each do |x|
x.scan(r).each do |a, mood, units, b|
(h[a] ||= {})[b] = units.to_i * (mood <=> ?i)
end
end
res = h.keys.permutation.map { |p|
# appends first item to the end of array
(p << p[0]).each_cons(2).map { |a, b|
h[a][b] + h[b][a]
}.reduce(:+)
}.max
p res
inp = '''Vixen can fly 19 km/s for 7 seconds, but then must rest for 124 seconds.
Rudolph can fly 3 km/s for 15 seconds, but then must rest for 28 seconds.
Donner can fly 19 km/s for 9 seconds, but then must rest for 164 seconds.
Blitzen can fly 19 km/s for 9 seconds, but then must rest for 158 seconds.
Comet can fly 13 km/s for 7 seconds, but then must rest for 82 seconds.
Cupid can fly 25 km/s for 6 seconds, but then must rest for 145 seconds.
Dasher can fly 14 km/s for 3 seconds, but then must rest for 38 seconds.
Dancer can fly 3 km/s for 16 seconds, but then must rest for 37 seconds.
Prancer can fly 25 km/s for 6 seconds, but then must rest for 143 seconds.'''
import re
import itertools
p = re.compile(r'(\w+).+?(\d+) km\/s.+?(\d+) seconds,.+?(\d+) seconds')
runners = dict()
for name, speed, run, rest in p.findall(inp):
runners[name] = dict([('speed', int(speed)), ('run', int(run)), ('rest', int(rest))])
t = 2503
maxd = 0
for r in runners.keys():
runs = int(t / (runners[r]['run'] + runners[r]['rest']))
extra = t % (runners[r]['run'] + runners[r]['rest'])
last = extra if extra <= runners[r]['run'] else runners[r]['run']
distance = runners[r]['speed'] * runners[r]['run']* runs + runners[r]['speed'] * last
maxd = max(distance, maxd)
print(distance)
## WIP ##
steps = itertools.cycle([runners[r]['speed']]*runners[r]['run'] + [0]*runners[r]['rest'])
list(itertools.accumulate(next(steps) for _ in range(2503)))
##################################################
import re
import itertools
import collections
history = collections.defaultdict(list)
for who, speed, duration, rest in re.findall(regex, text):
steps = itertools.cycle([int(speed)]*int(duration) + [0]*int(rest))
history[who] = list(itertools.accumulate(next(steps) for _ in range(2503)))
by_dist = max(h[-1] for h in history.values())
print(by_dist)
# zip(*history.values()) returns a tuple that matches by index for each key
# a list of all values for each key, i refers to the index
scored = [i for a in zip(*history.values()) for i, v in enumerate(a) if v==max(a)]
# converts scored in a hashed dictionary, values are number of occurrences
# of the index, which means that every time an index was the leader it
# calculates one point, then gets the maximum.
by_points = max(collections.Counter(scored).values())
print(by_points)
##################################################
#import re
#def parse_input(a):
# reindeers = {}
# p = re.compile(r'(\w+).+?(\d+) km\/s.+?(\d+) seconds,.+?(\d+) seconds')
# for name, speed, run, rest in p.findall(a):
# reindeers[name] = dict([('speed', int(speed)), ('mov', int(run)), ('rest', int(rest))])
# reindeers[reindeer] = [int(speed), int(time), int(rest)]
# return reindeers
def parse_input(a):
reindeers = {}
with file(a, 'r') as f:
for line in f:
reindeer, speed, time, rest = line.strip().split(" ")
reindeers[reindeer] = [int(speed), int(time), int(rest)]
return reindeers
def day14(reindeers, time):
names = sorted([reindeer for reindeer in reindeers])
points = [0 for name in names]
for t in range(1, time+1):
distances = [get_distance(reindeers[name], t) for name in names]
points = [points[i] + 1 if distances[i] == max(distances) else points[i] for i in range(len(points))]
return max(distances), max(points)
def get_distance(r, t):
return r[0]*r[1]*(t/(r[1] + r[2])) + r[0]*min([r[1],(t % (r[1] + r[2]))])
# return run['speed'] * run['mov'] * int(time/(run['mov'] + run['rest'])) + \
# run['speed'] * min([run['mov'], (time % (run['mov'] + run['rest']))])
if __name__ == "__main__":
import sys
print day14(parse_input(sys.argv[1]), 2503)
distance = 2503
reindeers = {}
File.readlines("day14.input").each do |line|
name, speed, duration, rest = line.scan(/(\w+) can fly (\d+) km\/s for (\d+) seconds, but then must rest for (\d+) seconds/).flatten
reindeers[name] = Array.new(duration.to_i, speed.to_i) + Array.new(rest.to_i, 0)
reindeers[name] *= (distance / reindeers[name].size) + 1
end
# part 1
p reindeers.values.map { |r| r[0...distance].reduce(:+) }.max
# part 2
lead = 0
points = Hash.new(0)
distance.times do |d|
reindeers.values.map { |r| r[d] += r[d - 1] } if d > 0
lead = reindeers.values.map { |r| r[d] }.max
reindeers.keys.each { |r| points[r] += 1 if reindeers[r][d] == lead }
end
p points.values.max
module.exports = (input, lowcal = false) => {
var p = input.map(s => s.match(/(-?\d)/g).map(Number)), e = []
for (let a = 0; a < 101; a++) for (let b = 1; b < 101; b++)
for (let c = 0; c < 101; c++) for (let d = 0; d < 101; d++)
if (a + b + c + d === 100 && 3 * a - 3 * b - c > 0 &&
4 * c - 2 * d > 0 && 2 * d - 3 * a > 0) e.push([a, b, c, d])
return e.map(a => a.map((b, i) => p[i].map(c => c * b)))
.map(a => a.reduce((r, v) => r.map((a, i) => a + v[i]), [0, 0, 0, 0, 0]))
.filter(a => !lowcal || a[4] === 500)
.map(a => a.slice(0, 4).reduce((r, v) => r * v, 1))
.reduce((r, v) => r > v ? r : v, 0)
}
module.exports = i => require('./part1')(i, true)
# It's easier to use recursive generators for this problem than just pure recursion, because with the latter
# you'll have to drag around a heavy parameter with all ways of splitting a number into parts that were found
# so far (like [0,0, 100], [0, 1, 99] and so on) and mutate it to insert an index of the outermost loop to the
# beginning of each subconfiguration, and with generators you don't have to worry about collecting anything at
# all, you can just spit configurations out or loop over them as you go.
# Basically, what their mixtures generator does is:
# 1.Recreate the outermost loop of a basic nested loop solution that many people have posted here.
# 2.Inside of that loop, request all possible ways of splitting a smaller number (if we're splitting total,
# then it's total minus current loop counter i). Here's where generator magic happens: you can just ask
# mixtures recursively to give you all such configurations one by one; if we are splitting 3 into 3 parts,
# on the first iteration with i = 0 you will receive [0, 3], [1, 2], [2, 1], [3, 0].
# 3.And finally, pastei to the beginning of every configuration and send — or yield — it back to the caller, with ribbons and a bow.
# 4.For an edge (base) case, catch when you are asked to split a number into one part and return it back.
# After all that you can simply loop over each configuration the way you do with any other iterator: for m in mixtures(4, 100):,
# pretending you are in the innermost loop of a not-as-fancy solution with m holding all loop indices.
# Generator for all possible recipes given number of ingredients and total parts.
def mixtures(n, total):
start = total if n == 1 else 0
for i in range(start, total+1):
left = total - i
if n-1:
for y in mixtures(n-1, left):
yield [i] + y
else:
yield [i]
# Calories should always be the last element for each ingredient.
ingredients = [
[1, 0, -5, 1],
[0, 3, 0, 3],
]
def score(recipe, max_calories=0):
proportions = [map(lambda x:x*mul, props) for props, mul in zip(ingredients, recipe)]
dough = reduce(lambda a, b: map(sum, zip(a, b)), proportions)
calories = dough.pop()
result = reduce(lambda a, b: a*b, map(lambda x: max(x, 0), dough))
return 0 if max_calories and calories > max_calories else result
#Then just map score over all possible recipes:
recipes = mixtures(len(ingredients), 100)
print max(map(score, recipes))
print max(map(lambda r: score(r, 500), recipes))
import re
remember = '''Sue 1: children: 1, cars: 8, vizslas: 7
Sue 2: akitas: 10, perfumes: 10, children: 5
Sue 3: cars: 5, pomeranians: 4, vizslas: 1
Sue 4: goldfish: 5, children: 8, perfumes: 3
Sue 5: vizslas: 2, akitas: 7, perfumes: 6
Sue 6: vizslas: 0, akitas: 1, perfumes: 2
Sue 7: perfumes: 8, cars: 4, goldfish: 10
Sue 8: perfumes: 7, children: 2, cats: 1
Sue 9: pomeranians: 3, goldfish: 10, trees: 10
Sue 10: akitas: 7, trees: 8, pomeranians: 4
Sue 11: goldfish: 1, perfumes: 4, cars: 6
Sue 12: samoyeds: 6, trees: 6, perfumes: 2
Sue 13: akitas: 10, pomeranians: 0, vizslas: 2
Sue 14: cars: 2, perfumes: 3, children: 4
Sue 15: goldfish: 2, children: 8, cars: 5
Sue 16: goldfish: 9, cars: 0, vizslas: 5
Sue 17: cats: 5, trees: 6, perfumes: 6
Sue 18: cars: 0, perfumes: 8, pomeranians: 7
Sue 19: trees: 2, goldfish: 5, perfumes: 4
Sue 20: akitas: 4, vizslas: 4, trees: 0
Sue 21: pomeranians: 7, trees: 0, goldfish: 10
Sue 22: cars: 4, vizslas: 0, perfumes: 3
Sue 23: vizslas: 8, trees: 1, akitas: 2
Sue 24: children: 7, trees: 0, akitas: 1
Sue 25: goldfish: 3, akitas: 2, trees: 2
Sue 26: pomeranians: 4, vizslas: 4, samoyeds: 2
Sue 27: cars: 0, trees: 8, akitas: 5
Sue 28: perfumes: 6, cats: 0, cars: 2
Sue 29: trees: 7, akitas: 1, vizslas: 1
Sue 30: perfumes: 9, cars: 9, trees: 10
Sue 31: pomeranians: 5, akitas: 9, samoyeds: 1
Sue 32: pomeranians: 10, vizslas: 5, goldfish: 5
Sue 33: vizslas: 2, akitas: 3, trees: 7
Sue 34: goldfish: 10, perfumes: 0, samoyeds: 7
Sue 35: akitas: 6, cats: 7, perfumes: 10
Sue 36: pomeranians: 8, vizslas: 7, akitas: 6
Sue 37: goldfish: 2, cars: 10, children: 7
Sue 38: goldfish: 2, perfumes: 3, cars: 7
Sue 39: trees: 9, vizslas: 10, cars: 5
Sue 40: goldfish: 1, pomeranians: 0, trees: 2
Sue 41: trees: 2, goldfish: 6, vizslas: 3
Sue 42: akitas: 1, cars: 3, vizslas: 3
Sue 43: akitas: 1, pomeranians: 1, vizslas: 3
Sue 44: goldfish: 7, akitas: 3, vizslas: 10
Sue 45: akitas: 8, samoyeds: 8, goldfish: 2
Sue 46: trees: 0, vizslas: 4, cars: 9
Sue 47: cars: 9, trees: 10, perfumes: 4
Sue 48: akitas: 0, vizslas: 5, perfumes: 4
Sue 49: goldfish: 9, trees: 1, cars: 4
Sue 50: goldfish: 2, perfumes: 5, cars: 2
Sue 51: samoyeds: 1, goldfish: 2, perfumes: 7
Sue 52: cars: 0, perfumes: 4, goldfish: 8
Sue 53: goldfish: 9, vizslas: 2, akitas: 9
Sue 54: trees: 1, goldfish: 9, children: 5
Sue 55: cars: 0, akitas: 5, trees: 4
Sue 56: trees: 4, samoyeds: 5, children: 9
Sue 57: children: 0, vizslas: 8, cars: 3
Sue 58: trees: 4, pomeranians: 5, akitas: 5
Sue 59: vizslas: 10, cats: 3, children: 2
Sue 60: cats: 6, vizslas: 2, cars: 2
Sue 61: akitas: 1, vizslas: 0, children: 4
Sue 62: akitas: 4, trees: 9, children: 10
Sue 63: pomeranians: 6, vizslas: 6, cars: 4
Sue 64: perfumes: 8, pomeranians: 1, children: 8
Sue 65: perfumes: 3, goldfish: 6, trees: 5
Sue 66: goldfish: 10, akitas: 8, vizslas: 4
Sue 67: vizslas: 10, samoyeds: 3, trees: 2
Sue 68: samoyeds: 4, cars: 7, perfumes: 3
Sue 69: perfumes: 2, goldfish: 0, trees: 2
Sue 70: trees: 8, vizslas: 7, akitas: 6
Sue 71: cars: 2, children: 7, perfumes: 3
Sue 72: cars: 1, akitas: 9, perfumes: 0
Sue 73: vizslas: 4, akitas: 7, cars: 5
Sue 74: samoyeds: 3, cars: 3, akitas: 2
Sue 75: trees: 2, cars: 1, vizslas: 7
Sue 76: samoyeds: 9, perfumes: 1, trees: 6
Sue 77: trees: 6, perfumes: 10, cars: 7
Sue 78: trees: 0, children: 8, vizslas: 5
Sue 79: vizslas: 0, trees: 0, samoyeds: 1
Sue 80: trees: 6, goldfish: 8, perfumes: 0
Sue 81: samoyeds: 8, pomeranians: 6, akitas: 5
Sue 82: vizslas: 6, perfumes: 9, akitas: 4
Sue 83: cats: 0, vizslas: 3, pomeranians: 10
Sue 84: cars: 4, perfumes: 6, samoyeds: 5
Sue 85: vizslas: 7, trees: 5, goldfish: 7
Sue 86: goldfish: 2, trees: 2, vizslas: 1
Sue 87: trees: 6, goldfish: 10, pomeranians: 4
Sue 88: vizslas: 1, akitas: 0, perfumes: 8
Sue 89: goldfish: 8, akitas: 3, vizslas: 7
Sue 90: vizslas: 9, akitas: 7, perfumes: 9
Sue 91: children: 7, cars: 7, trees: 9
Sue 92: vizslas: 10, akitas: 8, goldfish: 1
Sue 93: goldfish: 7, vizslas: 2, pomeranians: 0
Sue 94: cats: 2, samoyeds: 6, pomeranians: 3
Sue 95: samoyeds: 4, children: 4, pomeranians: 10
Sue 96: pomeranians: 9, cats: 1, goldfish: 3
Sue 97: trees: 1, akitas: 6, goldfish: 1
Sue 98: vizslas: 7, akitas: 2, perfumes: 7
Sue 99: pomeranians: 6, perfumes: 2, trees: 1
Sue 100: cars: 3, children: 9, trees: 10
Sue 101: children: 0, perfumes: 0, vizslas: 3
Sue 102: cars: 4, goldfish: 5, children: 2
Sue 103: pomeranians: 3, perfumes: 7, cats: 8
Sue 104: akitas: 0, perfumes: 5, vizslas: 5
Sue 105: akitas: 7, vizslas: 2, samoyeds: 8
Sue 106: goldfish: 7, perfumes: 0, cats: 8
Sue 107: cats: 6, pomeranians: 9, cars: 6
Sue 108: akitas: 3, vizslas: 10, cats: 5
Sue 109: akitas: 10, perfumes: 2, cars: 7
Sue 110: goldfish: 7, pomeranians: 1, trees: 1
Sue 111: akitas: 10, samoyeds: 6, vizslas: 6
Sue 112: cats: 6, akitas: 7, trees: 9
Sue 113: akitas: 1, trees: 9, vizslas: 8
Sue 114: vizslas: 2, cats: 1, cars: 4
Sue 115: akitas: 0, trees: 5, goldfish: 7
Sue 116: goldfish: 2, trees: 10, akitas: 2
Sue 117: cars: 4, goldfish: 10, perfumes: 5
Sue 118: cars: 5, perfumes: 6, trees: 0
Sue 119: perfumes: 5, vizslas: 1, cats: 0
Sue 120: perfumes: 8, akitas: 9, vizslas: 4
Sue 121: samoyeds: 2, vizslas: 7, perfumes: 6
Sue 122: children: 6, trees: 9, perfumes: 2
Sue 123: cars: 7, akitas: 0, pomeranians: 0
Sue 124: akitas: 7, cats: 8, vizslas: 5
Sue 125: goldfish: 3, trees: 1, cars: 4
Sue 126: cars: 4, perfumes: 3, akitas: 0
Sue 127: children: 10, vizslas: 5, akitas: 9
Sue 128: akitas: 3, samoyeds: 2, cats: 8
Sue 129: cats: 8, akitas: 1, vizslas: 8
Sue 130: trees: 4, cars: 6, perfumes: 6
Sue 131: akitas: 7, perfumes: 6, goldfish: 9
Sue 132: akitas: 6, vizslas: 7, trees: 1
Sue 133: akitas: 5, vizslas: 7, children: 9
Sue 134: cars: 8, goldfish: 4, pomeranians: 4
Sue 135: samoyeds: 1, pomeranians: 6, akitas: 4
Sue 136: perfumes: 10, goldfish: 1, cars: 3
Sue 137: cars: 3, samoyeds: 6, vizslas: 7
Sue 138: samoyeds: 10, akitas: 3, perfumes: 4
Sue 139: perfumes: 10, vizslas: 2, goldfish: 7
Sue 140: samoyeds: 7, cars: 1, trees: 2
Sue 141: children: 6, cats: 5, cars: 9
Sue 142: cats: 0, trees: 1, akitas: 10
Sue 143: samoyeds: 4, cars: 0, children: 7
Sue 144: trees: 0, cars: 4, perfumes: 8
Sue 145: goldfish: 7, cars: 5, trees: 1
Sue 146: perfumes: 7, cars: 7, goldfish: 0
Sue 147: trees: 2, goldfish: 7, vizslas: 5
Sue 148: samoyeds: 8, perfumes: 1, trees: 0
Sue 149: vizslas: 2, samoyeds: 5, trees: 0
Sue 150: akitas: 4, perfumes: 4, pomeranians: 2
Sue 151: trees: 2, cars: 0, goldfish: 10
Sue 152: goldfish: 7, vizslas: 0, trees: 0
Sue 153: children: 9, cats: 0, pomeranians: 10
Sue 154: cars: 6, goldfish: 10, akitas: 5
Sue 155: perfumes: 9, trees: 2, akitas: 3
Sue 156: pomeranians: 9, perfumes: 5, cars: 9
Sue 157: akitas: 0, trees: 2, cars: 7
Sue 158: goldfish: 10, trees: 8, akitas: 7
Sue 159: akitas: 5, trees: 10, cars: 10
Sue 160: akitas: 3, trees: 5, cars: 8
Sue 161: samoyeds: 2, cars: 7, perfumes: 4
Sue 162: cars: 6, vizslas: 10, pomeranians: 5
Sue 163: cars: 10, perfumes: 6, vizslas: 9
Sue 164: pomeranians: 7, cars: 4, vizslas: 2
Sue 165: goldfish: 9, vizslas: 3, trees: 1
Sue 166: goldfish: 1, samoyeds: 3, trees: 1
Sue 167: vizslas: 4, goldfish: 7, cats: 5
Sue 168: children: 1, cars: 5, samoyeds: 7
Sue 169: trees: 1, samoyeds: 3, goldfish: 6
Sue 170: goldfish: 2, cars: 3, perfumes: 9
Sue 171: cars: 4, goldfish: 0, trees: 6
Sue 172: cats: 8, perfumes: 6, trees: 1
Sue 173: akitas: 9, goldfish: 7, cars: 10
Sue 174: vizslas: 2, trees: 0, akitas: 1
Sue 175: perfumes: 3, vizslas: 8, akitas: 4
Sue 176: perfumes: 0, akitas: 6, goldfish: 3
Sue 177: perfumes: 6, children: 1, goldfish: 10
Sue 178: cars: 5, vizslas: 3, children: 10
Sue 179: perfumes: 3, trees: 8, cats: 9
Sue 180: perfumes: 8, vizslas: 4, trees: 7
Sue 181: perfumes: 7, vizslas: 9, samoyeds: 4
Sue 182: vizslas: 9, trees: 4, pomeranians: 4
Sue 183: trees: 9, cars: 3, goldfish: 5
Sue 184: perfumes: 2, cars: 4, vizslas: 3
Sue 185: children: 10, akitas: 10, cats: 9
Sue 186: cars: 5, samoyeds: 0, trees: 0
Sue 187: trees: 2, goldfish: 3, cars: 4
Sue 188: goldfish: 3, vizslas: 1, cats: 6
Sue 189: trees: 2, pomeranians: 10, cars: 7
Sue 190: perfumes: 10, akitas: 3, samoyeds: 0
Sue 191: cats: 5, vizslas: 6, akitas: 6
Sue 192: samoyeds: 5, trees: 1, perfumes: 8
Sue 193: pomeranians: 0, akitas: 9, cats: 0
Sue 194: trees: 1, goldfish: 0, perfumes: 10
Sue 195: perfumes: 2, akitas: 7, cars: 5
Sue 196: perfumes: 5, samoyeds: 8, cars: 1
Sue 197: vizslas: 2, pomeranians: 9, trees: 1
Sue 198: trees: 8, vizslas: 6, children: 8
Sue 199: pomeranians: 4, cars: 7, vizslas: 5
Sue 200: trees: 0, perfumes: 10, akitas: 10
Sue 201: cats: 9, akitas: 4, vizslas: 0
Sue 202: goldfish: 9, pomeranians: 9, cats: 6
Sue 203: cars: 5, perfumes: 5, trees: 2
Sue 204: pomeranians: 7, children: 2, akitas: 6
Sue 205: samoyeds: 7, pomeranians: 7, children: 6
Sue 206: trees: 1, cars: 1, pomeranians: 4
Sue 207: goldfish: 2, perfumes: 5, trees: 0
Sue 208: perfumes: 2, samoyeds: 4, trees: 1
Sue 209: cars: 8, perfumes: 6, goldfish: 9
Sue 210: perfumes: 4, cars: 8, samoyeds: 3
Sue 211: perfumes: 2, cars: 8, trees: 9
Sue 212: trees: 7, perfumes: 2, akitas: 5
Sue 213: children: 3, goldfish: 5, vizslas: 0
Sue 214: akitas: 6, goldfish: 0, children: 0
Sue 215: trees: 8, akitas: 3, goldfish: 1
Sue 216: goldfish: 6, perfumes: 8, akitas: 3
Sue 217: children: 7, trees: 2, vizslas: 6
Sue 218: goldfish: 8, samoyeds: 4, pomeranians: 6
Sue 219: goldfish: 8, samoyeds: 0, children: 9
Sue 220: perfumes: 1, cars: 8, vizslas: 6
Sue 221: perfumes: 9, cars: 10, children: 10
Sue 222: perfumes: 9, vizslas: 1, trees: 0
Sue 223: goldfish: 1, akitas: 2, vizslas: 8
Sue 224: samoyeds: 8, akitas: 7, vizslas: 4
Sue 225: goldfish: 1, cars: 4, perfumes: 10
Sue 226: goldfish: 9, trees: 4, perfumes: 5
Sue 227: vizslas: 5, trees: 4, goldfish: 7
Sue 228: cars: 1, cats: 10, perfumes: 4
Sue 229: vizslas: 8, cars: 10, akitas: 4
Sue 230: cats: 1, children: 8, vizslas: 3
Sue 231: perfumes: 7, cats: 6, samoyeds: 7
Sue 232: cars: 3, children: 9, perfumes: 7
Sue 233: vizslas: 1, samoyeds: 2, children: 2
Sue 234: trees: 1, samoyeds: 8, children: 2
Sue 235: trees: 6, akitas: 9, goldfish: 7
Sue 236: children: 10, trees: 0, samoyeds: 8
Sue 237: pomeranians: 4, trees: 1, goldfish: 2
Sue 238: vizslas: 4, akitas: 2, cars: 0
Sue 239: goldfish: 9, cars: 10, perfumes: 4
Sue 240: perfumes: 3, vizslas: 6, trees: 6
Sue 241: pomeranians: 6, akitas: 4, trees: 2
Sue 242: cars: 8, perfumes: 5, children: 7
Sue 243: trees: 4, perfumes: 7, cars: 3
Sue 244: perfumes: 6, akitas: 1, vizslas: 7
Sue 245: akitas: 3, perfumes: 9, samoyeds: 0
Sue 246: pomeranians: 3, vizslas: 9, samoyeds: 1
Sue 247: cars: 0, goldfish: 7, cats: 2
Sue 248: trees: 5, goldfish: 6, perfumes: 3
Sue 249: trees: 0, pomeranians: 7, perfumes: 9
Sue 250: cars: 9, trees: 1, goldfish: 10
Sue 251: perfumes: 3, cars: 8, trees: 7
Sue 252: cars: 5, akitas: 7, trees: 8
Sue 253: perfumes: 7, akitas: 3, trees: 8
Sue 254: goldfish: 8, samoyeds: 1, vizslas: 7
Sue 255: perfumes: 3, cars: 4, children: 6
Sue 256: perfumes: 9, trees: 8, children: 7
Sue 257: trees: 8, children: 6, cars: 4
Sue 258: vizslas: 1, trees: 10, goldfish: 9
Sue 259: vizslas: 5, trees: 6, goldfish: 9
Sue 260: trees: 0, goldfish: 6, cars: 7
Sue 261: cars: 1, perfumes: 4, goldfish: 9
Sue 262: cars: 7, goldfish: 9, cats: 9
Sue 263: cars: 0, children: 5, goldfish: 8
Sue 264: cars: 2, akitas: 8, trees: 0
Sue 265: perfumes: 9, children: 8, samoyeds: 7
Sue 266: cats: 1, children: 1, vizslas: 10
Sue 267: vizslas: 8, children: 2, trees: 6
Sue 268: akitas: 10, vizslas: 3, cats: 2
Sue 269: children: 4, goldfish: 1, cats: 6
Sue 270: vizslas: 5, cars: 9, akitas: 9
Sue 271: vizslas: 5, children: 4, akitas: 3
Sue 272: cars: 1, goldfish: 0, vizslas: 0
Sue 273: goldfish: 10, samoyeds: 1, akitas: 2
Sue 274: goldfish: 10, children: 2, pomeranians: 0
Sue 275: children: 0, vizslas: 1, samoyeds: 6
Sue 276: children: 1, vizslas: 3, samoyeds: 1
Sue 277: perfumes: 4, cats: 6, children: 10
Sue 278: pomeranians: 7, goldfish: 3, cars: 4
Sue 279: perfumes: 5, goldfish: 9, trees: 7
Sue 280: goldfish: 6, trees: 5, perfumes: 8
Sue 281: cars: 2, akitas: 1, vizslas: 7
Sue 282: vizslas: 4, akitas: 3, children: 8
Sue 283: pomeranians: 8, akitas: 9, vizslas: 4
Sue 284: samoyeds: 10, trees: 10, pomeranians: 2
Sue 285: akitas: 9, perfumes: 7, goldfish: 6
Sue 286: akitas: 2, vizslas: 7, goldfish: 10
Sue 287: pomeranians: 8, cars: 6, samoyeds: 5
Sue 288: pomeranians: 1, trees: 0, goldfish: 0
Sue 289: trees: 10, samoyeds: 1, children: 0
Sue 290: cats: 10, samoyeds: 6, trees: 0
Sue 291: vizslas: 9, trees: 6, goldfish: 5
Sue 292: cats: 4, perfumes: 8, cars: 3
Sue 293: goldfish: 10, perfumes: 10, cats: 0
Sue 294: cats: 7, trees: 6, akitas: 4
Sue 295: vizslas: 8, cars: 1, akitas: 6
Sue 296: vizslas: 5, akitas: 10, trees: 1
Sue 297: pomeranians: 8, samoyeds: 5, vizslas: 4
Sue 298: perfumes: 10, children: 5, vizslas: 2
Sue 299: cars: 10, akitas: 7, cats: 5
Sue 300: trees: 1, perfumes: 7, cars: 7
Sue 301: cars: 9, vizslas: 1, perfumes: 3
Sue 302: perfumes: 9, vizslas: 1, akitas: 5
Sue 303: akitas: 9, trees: 1, goldfish: 10
Sue 304: children: 10, vizslas: 6, pomeranians: 8
Sue 305: trees: 3, goldfish: 6, cats: 9
Sue 306: cars: 5, perfumes: 9, vizslas: 5
Sue 307: children: 0, goldfish: 7, trees: 2
Sue 308: trees: 9, samoyeds: 4, cars: 0
Sue 309: cats: 8, vizslas: 2, perfumes: 3
Sue 310: cars: 6, pomeranians: 6, vizslas: 6
Sue 311: vizslas: 6, akitas: 7, cats: 10
Sue 312: trees: 0, goldfish: 7, cars: 0
Sue 313: perfumes: 5, akitas: 5, cars: 2
Sue 314: akitas: 10, vizslas: 3, samoyeds: 8
Sue 315: cars: 3, perfumes: 1, goldfish: 8
Sue 316: pomeranians: 6, goldfish: 9, perfumes: 1
Sue 317: goldfish: 4, akitas: 6, cars: 2
Sue 318: perfumes: 8, vizslas: 8, akitas: 0
Sue 319: akitas: 10, cars: 5, vizslas: 6
Sue 320: vizslas: 4, akitas: 3, cats: 4
Sue 321: goldfish: 4, akitas: 8, cars: 8
Sue 322: pomeranians: 5, vizslas: 7, cats: 1
Sue 323: perfumes: 1, trees: 6, goldfish: 0
Sue 324: goldfish: 6, trees: 10, cars: 10
Sue 325: akitas: 2, samoyeds: 6, trees: 9
Sue 326: vizslas: 4, akitas: 7, cars: 9
Sue 327: children: 3, perfumes: 4, cars: 1
Sue 328: akitas: 9, perfumes: 6, cars: 10
Sue 329: perfumes: 2, goldfish: 0, trees: 1
Sue 330: vizslas: 10, pomeranians: 7, goldfish: 6
Sue 331: trees: 3, vizslas: 8, cars: 3
Sue 332: akitas: 2, cats: 1, goldfish: 8
Sue 333: cars: 6, trees: 2, vizslas: 0
Sue 334: samoyeds: 7, cars: 7, trees: 3
Sue 335: cats: 7, children: 1, perfumes: 8
Sue 336: akitas: 5, goldfish: 10, vizslas: 5
Sue 337: cats: 3, vizslas: 0, akitas: 10
Sue 338: perfumes: 8, cars: 1, trees: 8
Sue 339: cars: 4, samoyeds: 8, children: 2
Sue 340: goldfish: 9, pomeranians: 1, samoyeds: 1
Sue 341: akitas: 3, trees: 0, goldfish: 2
Sue 342: perfumes: 4, vizslas: 8, pomeranians: 9
Sue 343: akitas: 4, cars: 5, goldfish: 4
Sue 344: samoyeds: 5, cats: 4, trees: 0
Sue 345: samoyeds: 4, cars: 8, akitas: 2
Sue 346: akitas: 3, vizslas: 10, perfumes: 10
Sue 347: goldfish: 10, akitas: 4, cars: 1
Sue 348: perfumes: 10, cats: 4, vizslas: 5
Sue 349: akitas: 2, vizslas: 4, cars: 7
Sue 350: akitas: 5, vizslas: 5, cars: 6
Sue 351: vizslas: 8, perfumes: 6, cars: 3
Sue 352: cars: 10, vizslas: 0, goldfish: 10
Sue 353: cars: 10, perfumes: 5, children: 7
Sue 354: vizslas: 6, akitas: 3, samoyeds: 9
Sue 355: akitas: 2, perfumes: 7, cars: 10
Sue 356: cars: 10, perfumes: 7, children: 6
Sue 357: akitas: 4, cars: 8, trees: 1
Sue 358: trees: 2, cars: 1, goldfish: 2
Sue 359: vizslas: 5, cars: 9, trees: 4
Sue 360: perfumes: 4, akitas: 3, cars: 3
Sue 361: children: 3, akitas: 2, cats: 5
Sue 362: cars: 8, cats: 4, akitas: 10
Sue 363: cats: 2, trees: 1, vizslas: 4
Sue 364: vizslas: 2, pomeranians: 5, samoyeds: 9
Sue 365: samoyeds: 2, akitas: 7, goldfish: 9
Sue 366: goldfish: 8, trees: 7, cats: 2
Sue 367: perfumes: 2, vizslas: 6, trees: 5
Sue 368: cars: 5, samoyeds: 0, perfumes: 6
Sue 369: samoyeds: 10, trees: 10, vizslas: 1
Sue 370: trees: 2, vizslas: 3, cars: 4
Sue 371: akitas: 6, pomeranians: 2, cats: 4
Sue 372: trees: 2, perfumes: 3, goldfish: 9
Sue 373: vizslas: 5, children: 0, pomeranians: 6
Sue 374: trees: 1, vizslas: 8, perfumes: 10
Sue 375: cars: 0, akitas: 6, children: 0
Sue 376: akitas: 1, vizslas: 0, trees: 0
Sue 377: samoyeds: 10, cats: 5, pomeranians: 0
Sue 378: goldfish: 3, pomeranians: 7, cats: 7
Sue 379: perfumes: 0, cats: 0, trees: 8
Sue 380: perfumes: 4, samoyeds: 1, akitas: 7
Sue 381: akitas: 4, pomeranians: 2, children: 4
Sue 382: vizslas: 9, akitas: 4, trees: 10
Sue 383: trees: 1, vizslas: 10, akitas: 6
Sue 384: trees: 3, akitas: 8, goldfish: 3
Sue 385: goldfish: 6, perfumes: 2, children: 9
Sue 386: children: 10, akitas: 7, goldfish: 7
Sue 387: goldfish: 3, vizslas: 10, perfumes: 5
Sue 388: children: 4, trees: 0, cars: 2
Sue 389: trees: 0, cats: 3, goldfish: 10
Sue 390: samoyeds: 9, pomeranians: 0, cats: 6
Sue 391: samoyeds: 10, trees: 3, akitas: 4
Sue 392: akitas: 9, goldfish: 10, perfumes: 7
Sue 393: goldfish: 6, cars: 2, akitas: 9
Sue 394: trees: 4, goldfish: 9, vizslas: 7
Sue 395: vizslas: 4, samoyeds: 1, goldfish: 6
Sue 396: vizslas: 5, cats: 0, samoyeds: 1
Sue 397: goldfish: 7, cats: 0, trees: 7
Sue 398: cars: 10, akitas: 1, vizslas: 7
Sue 399: samoyeds: 10, cats: 6, goldfish: 6
Sue 400: cats: 6, samoyeds: 0, trees: 2
Sue 401: trees: 1, children: 4, goldfish: 2
Sue 402: cats: 8, vizslas: 4, children: 3
Sue 403: cars: 9, perfumes: 8, pomeranians: 2
Sue 404: goldfish: 8, trees: 2, cars: 5
Sue 405: perfumes: 1, pomeranians: 5, vizslas: 5
Sue 406: perfumes: 6, trees: 2, pomeranians: 6
Sue 407: trees: 0, goldfish: 6, cars: 6
Sue 408: trees: 0, samoyeds: 7, goldfish: 9
Sue 409: samoyeds: 10, goldfish: 6, pomeranians: 0
Sue 410: perfumes: 5, vizslas: 6, trees: 0
Sue 411: goldfish: 2, trees: 2, pomeranians: 0
Sue 412: pomeranians: 4, perfumes: 8, cats: 8
Sue 413: vizslas: 4, cars: 5, akitas: 1
Sue 414: perfumes: 2, trees: 8, goldfish: 7
Sue 415: akitas: 3, trees: 1, perfumes: 3
Sue 416: cars: 7, trees: 1, perfumes: 8
Sue 417: cars: 5, goldfish: 5, trees: 1
Sue 418: cars: 9, goldfish: 4, samoyeds: 2
Sue 419: pomeranians: 8, akitas: 1, goldfish: 6
Sue 420: cars: 0, cats: 0, children: 8
Sue 421: akitas: 10, goldfish: 1, vizslas: 8
Sue 422: children: 8, vizslas: 6, samoyeds: 10
Sue 423: samoyeds: 3, goldfish: 10, vizslas: 8
Sue 424: cars: 3, children: 7, goldfish: 4
Sue 425: cars: 9, perfumes: 9, goldfish: 8
Sue 426: akitas: 5, trees: 10, vizslas: 10
Sue 427: vizslas: 10, cars: 3, akitas: 7
Sue 428: cats: 6, perfumes: 5, goldfish: 10
Sue 429: goldfish: 7, trees: 5, vizslas: 10
Sue 430: perfumes: 3, trees: 7, cars: 3
Sue 431: cars: 2, vizslas: 1, akitas: 6
Sue 432: pomeranians: 8, perfumes: 5, cars: 3
Sue 433: children: 8, cars: 0, perfumes: 7
Sue 434: samoyeds: 0, vizslas: 9, akitas: 10
Sue 435: akitas: 3, vizslas: 8, cats: 4
Sue 436: goldfish: 5, trees: 8, samoyeds: 8
Sue 437: cars: 10, samoyeds: 9, goldfish: 7
Sue 438: samoyeds: 5, akitas: 7, perfumes: 9
Sue 439: goldfish: 10, perfumes: 5, cars: 0
Sue 440: pomeranians: 1, samoyeds: 9, children: 4
Sue 441: vizslas: 4, perfumes: 2, cats: 5
Sue 442: trees: 0, pomeranians: 3, cars: 7
Sue 443: akitas: 0, cars: 2, vizslas: 10
Sue 444: children: 1, akitas: 9, trees: 0
Sue 445: cars: 5, perfumes: 7, goldfish: 9
Sue 446: akitas: 0, perfumes: 1, vizslas: 2
Sue 447: vizslas: 7, perfumes: 0, cars: 5
Sue 448: vizslas: 6, goldfish: 10, trees: 0
Sue 449: cars: 7, vizslas: 7, trees: 3
Sue 450: pomeranians: 4, akitas: 4, vizslas: 8
Sue 451: cats: 4, perfumes: 8, children: 3
Sue 452: samoyeds: 8, akitas: 9, cars: 1
Sue 453: cars: 8, akitas: 5, vizslas: 2
Sue 454: vizslas: 9, perfumes: 4, akitas: 4
Sue 455: akitas: 3, goldfish: 2, vizslas: 6
Sue 456: cars: 4, perfumes: 5, goldfish: 10
Sue 457: trees: 9, pomeranians: 4, goldfish: 10
Sue 458: pomeranians: 1, perfumes: 9, children: 6
Sue 459: samoyeds: 0, goldfish: 8, vizslas: 6
Sue 460: cars: 10, goldfish: 8, samoyeds: 8
Sue 461: akitas: 8, goldfish: 9, vizslas: 2
Sue 462: cars: 1, vizslas: 2, akitas: 8
Sue 463: goldfish: 2, akitas: 4, samoyeds: 10
Sue 464: children: 5, perfumes: 5, cars: 5
Sue 465: perfumes: 9, trees: 0, samoyeds: 6
Sue 466: akitas: 5, goldfish: 3, cats: 6
Sue 467: perfumes: 3, goldfish: 0, trees: 4
Sue 468: goldfish: 2, children: 4, trees: 1
Sue 469: cars: 0, perfumes: 8, children: 7
Sue 470: vizslas: 8, cats: 5, samoyeds: 9
Sue 471: pomeranians: 7, trees: 2, goldfish: 3
Sue 472: goldfish: 8, akitas: 4, perfumes: 5
Sue 473: perfumes: 2, pomeranians: 3, cars: 8
Sue 474: samoyeds: 0, akitas: 7, pomeranians: 6
Sue 475: vizslas: 7, perfumes: 1, trees: 6
Sue 476: vizslas: 3, samoyeds: 1, perfumes: 10
Sue 477: cars: 6, perfumes: 5, vizslas: 2
Sue 478: pomeranians: 1, goldfish: 3, akitas: 7
Sue 479: goldfish: 10, trees: 0, cars: 3
Sue 480: cats: 3, akitas: 5, vizslas: 8
Sue 481: pomeranians: 5, vizslas: 2, trees: 3
Sue 482: cars: 8, samoyeds: 10, goldfish: 10
Sue 483: pomeranians: 3, vizslas: 6, goldfish: 5
Sue 484: perfumes: 7, vizslas: 4, akitas: 7
Sue 485: goldfish: 1, trees: 0, perfumes: 10
Sue 486: goldfish: 6, perfumes: 0, akitas: 10
Sue 487: cats: 2, akitas: 10, trees: 1
Sue 488: akitas: 1, goldfish: 3, cars: 7
Sue 489: goldfish: 3, akitas: 6, vizslas: 6
Sue 490: goldfish: 8, perfumes: 2, akitas: 2
Sue 491: trees: 4, vizslas: 8, perfumes: 6
Sue 492: cars: 9, perfumes: 3, cats: 0
Sue 493: trees: 3, vizslas: 6, goldfish: 7
Sue 494: trees: 8, samoyeds: 1, perfumes: 5
Sue 495: children: 9, akitas: 8, vizslas: 4
Sue 496: vizslas: 2, pomeranians: 1, perfumes: 7
Sue 497: trees: 2, akitas: 4, vizslas: 6
Sue 498: akitas: 8, pomeranians: 7, trees: 0
Sue 499: perfumes: 6, goldfish: 3, vizslas: 7
Sue 500: cars: 1, perfumes: 6, vizslas: 1'''
inp = '''children: 3
cats: 7
samoyeds: 2
pomeranians: 3
akitas: 0
vizslas: 0
goldfish: 5
trees: 3
cars: 2
perfumes: 1'''
detected = {}
for line in inp.split("\n"):
for k, v in re.findall(r'(\w+): (\d+)', line):
detected[k] = int(v)
aunts = {}
for line in remember.split("\n"):
for name, k1, v1, k2, v2, k3, v3 in re.findall(r'(.+): (\w+): (\d+), (\w+): (\d+), (\w+): (\d+)', line):
aunts[name] = {k1:int(v1), k2:int(v2), k3:int(v3)}
for aunt in aunts.keys():
temp = 0
for info in aunts[aunt]:
if info not in ['cats', 'trees', 'pomeranians', 'goldfish']:
if aunts[aunt][info] == detected[info]:
temp += 1
elif info in ['cats', 'trees']:
if aunts[aunt][info] >= detected[info]:
temp += 1
elif info in ['pomeranians', 'goldfish']:
if aunts[aunt][info] <= detected[info]:
temp += 1
if temp == 3:
print(aunt)
break
##################################################
# SUES = remember
# Sue = detected
import re
Sue = {}
for l in SUE.split('\n'):
k, v = re.search(r'(\w+): (\d+)', l).groups()
Sue[k] = int(v)
for ix, l in enumerate(SUES.split('\n')):
d = {}
for mo in re.finditer(r'(\w+): (\d+)', l):
d[mo.group(1)] = int(mo.group(2))
if set(d.items()).issubset(set(Sue.items())):
print('task 1', ix+1)
if d.pop('cats', 100) > Sue['cats'] and d.pop('trees', 100) > Sue['trees'] and d.pop('pomeranians', -1) < Sue['pomeranians'] and d.pop('goldfish', -1) < Sue['goldfish']:
if set(d.items()).issubset(set(Sue.items())):
print('task 2', ix + 1)
MX = 100
$map = {
'children' => 3..3,
'cats' => (7+1)..MX,
'samoyeds' => 2..2,
'pomeranians' => 0..(3-1),
'akitas' => 0..0,
'vizslas' => 0..0,
'goldfish' => 0..(5-1),
'trees' => (3+1)..MX,
'cars' => 2..2,
'perfumes' => 1..1,
}
p $stdin.readlines.select { |line|
!line.split()[2..-1].each_slice(2).any? { |k, v| !$map[k[0..-2]].include?(v.to_i) }
}
##################################################
sue = {
children: 3,
cats: 7,
samoyeds: 2,
pomeranians: 3,
akitas: 0,
vizslas: 0,
goldfish: 5,
trees: 3,
cars: 2,
perfumes: 1
}
$data = {}
File.readlines("16-1.data").each do |line|
name, items = line.chomp.split(": ", 2)
$data[name] = {}
items.split(", ").each do |item|
type, num = item.split(": ")
num = num.to_i
$data[name][type] = num
end
end
$data.each do |name, items|
her = true
items.each do |item, num|
sue_num = sue[item.to_sym]
if ['cats','trees'].include? item
her = false if sue_num >= num
elsif ['pomeranians','goldfish'].include? item
her = false if sue_num <= num
else
her = false if sue[item.to_sym] != num
end
end
puts name if her
end
import itertools
inp = '''33
14
18
20
45
35
16
35
1
13
18
13
50
44
48
6
24
41
30
42'''
containers = []
for line in inp.split("\n"):
containers.append(int(line))
solutions = []
def day16(bottles):
for i in range(len(bottles)):
for combination in itertools.combinations(bottles, i):
if sum(combination) == 150:
solutions.append(combination)
day16(containers)
print(len(solutions))
print(len([c for c in solutions if len(c) == \
len(min(solutions, key=lambda x: len(x)))]))
inp = "3
14
18
20
45
35
16
35
1
13
18
13
50
44
48
6
24
41
30
42"
cs = inp.split("\n").map(&:to_i)
solns = (1..cs.size).reduce([]) do |m, i|
m.concat(cs.combination(i).select {|x| x.inject(:+) == 150})
end
min = solns.map(&:size).min
p solns.count {|x| x.size == min}
import itertools
inp = '''####.#.##.###.#.#.##.#..###.#..#.#.#..##....#.###...##..###.##.#.#.#.##...##..#..#....#.#.##..#...##
.##...##.##.######.#.#.##...#.#.#.#.#...#.##.#..#.#.####...#....#....###.#.#.#####....#.#.##.#.#.##.
###.##..#..#####.......#.########...#.####.###....###.###...#...####.######.#..#####.#.###....####..
....#..#..#....###.##.#.....##...#.###.#.#.#..#.#..##...#....#.##.###.#...######......#..#.#..####.#
..###.####..#.#.#..##.#.#....#......#.##.##..##.#.....##.###.#..###...###.#.##..#.#..###....####.#.#
#.#...#......####.#..##.####.#.#.#...##..###.##.#...#..#..###....#.#....#..##..#....##.....##.#...#.
....##.#.#.#.##..##...##..##..#....#....###...####.###...##.#...#..#....##.....#..#.#####.###.###.##
#...##..#.#..#....#..########.##....##..##.###..#.#..#..#.##.##.#..##..######....####..#####.#.###..
.####...######.#..#.##.#.#..####...####.##.#.#......#...##....##..#...###..#.####......###......#.##
.####.###..#..#####.##...###......#...###..#..##..#.#....##.##.#.##.###..#..#..###.#..#.#....####.##
#..#..##.##.##.###.#.##.##.#.#.#....#....#.####.#.##...#####...###.#####.#.#.#....####..###..###..##
#.##....#...########..##...#.#.##.......#.#..##...####...#.####.####..##...##.#....###.#.####...#.##
#.#...##..#.##.##..##....#.....##.##.....#...###...#..#...####.##.####..#...##..##.##.##.##..##...##
.#..###...#.#.....#######..##.###....##..#.##.#......###.##....#......###...#.##....#.....##......##
..##....#.###...###..####.##..#..##.##......##.#.....#...#..#..##...###..#.####...#...#..##.#..##..#
...#.#.#...#.#..#.##....##..#...#.##..#......#.#.....#####.##.#...#######.#.#..#.####..###.....###.#
.#....#.#.##..####.#####..#.#######..#.##.###...##.##....##..###..#.##.###.......#....#..######.####
#..#.##.##..#..#..##.####.#.#.#.#..#.##...#..######....#.##.#..##.##.######.###.###.###...#.....#.#.
.#.......#...#.####.##...#####..##..#.#....##..#.#.#.####.#.##....#..##.##..#.###.....#.##.##.#.##.#
#..##..##...#....#.##.#...#.#....#......####...##..#...##.##.#..#########..#..#.##.##..#.#.#######..
#.......#####..###..######.#..##.#.#####..##...###...#.####.##...###..#.#.#####....#...#.##...#.#..#
.##..#...#####.##.##......#...#.#.#.###.#.#.#...##.#..#....###.....#..#.#.###......#####.###.#..##.#
.....###.#.#.#..##...#...###..#...#.#.##..###.##.#####.##..#.#.#.#.#####....#.#.#####...##.#..#.#.#.
###...##.#..#.####..##.#..##.#.#.#...#.#..#..##..##..#.#.#.#.##...##..#..#.....#....#####.#.#.####.#
....##....#.#.....#...###.#...##..##.##..#..###..##.###..#####..#...#####.##.#..#.#.#.###...####.###
##.##.##.#...#..#...........##.##.###.#...###.####.#..#..#...#..#..####.#.###########..#.###.###.#.#
##.##..##.####..###...##...#....###.###.#..##..#..#.###.#..####.#..##.#.#...#..#.#.##.##...#...#....
..##...#.#.##....##...#.#.#......##.##.#.#.####.####....####.#.###.##.#.#..####..#..######..#..#.#..
####.#.##.......##.###....##.#..####.#.#######..#...###..##.##..#...#...####........#.#..##...#....#
#..#.#.....#..#.###..#.#...###..##...#.#..#.#.##..#...##.##.##.#.#.#..#.####.########....########..#
#...#..##.##..#.#.#.##.##.##.#..#..#.##....#....###.#.###.#.#..#....#...##..#.....####...##.#..#...#
.###...##...####....###.##.#..####...##.#.##.#..##..##....#....##.#...#..#..##..##..##.#...#...###..
.#..##.#..##..####..#.#.##..###.#...#....##.###...#.###....#.#.#........#..#.#.#..##..#####..#..#.#.
.#.##.....#..#...#.##.....#.##..#..#....#..#..#....#.##..##...#.##.##..##..#.#.#.##..####.##..#.#..#
...###.#.....#...#.##.#.###.#...##..#.###..#..#..#.#..#...###.#.##.##.##.#.##.#####.#..#.#..#.#...##
#.#.#.#.##.#.....##..#.###......##.#.##..#...#.########.##.###..#..#..##..##.#..##..###.#.###...#.#.
..##...##...#...###.#..##..#..#..#.#.##..##......##..##.....##.....####..#.##......#..####...###..##
##.......#..##....###...###......#.##.##....######..###.##...##.#...#...#.....#.###.#.#..#.##..#..#.
#.#..#..#.#####.##.##.###..#...###.....#..##..####...#.#.###....#..#.#.###.####..#.#........##.#....
..###.#...##.#.####.#.##.##.....##...#.##.#.###.#.#..##.#..##..#..##.##....#.#####.##..#######.....#
###.###..##.#..##...#####..##.####....#.##......##......#.#....##.####.#.#.#.###...#..####..#.######
#..###...#.#.......#..####.####...#....###.###...#.##..##..#..##.##.......####.##...#.#.#.##.#.#..#.
..#...#..###.##..#.#.#.##..#..#.#.......###..###..#####.#.#.#.#.#..#.#.#.#..###....#.####..###...#..
...######.###....#..####.####......#...#.###.#....#...####.##........##...##.#..##.###.#..#..##..###
.#..###.####.###.#.#..#..#..#.##.#.#.###.##..####.#####..##....##.#.##...###.####.#.#######.#..#..#.
.#..##.#..##..#...##...#..#..##.#.#....##.##...###.#.#...##..##..#.###.#.#.#.#...#....#.#..#.#.###.#
.###..#.#..####.#########...####....####.#.##...##.##..#.##.#........#.....###.###.######.##.....###
..##.##..##..#.####.#..#####.#....##.##.#####.....#.#......##...#####..####....###..#.#...#..####..#
.#..##..##.##.##.##.#.###.###.#..#..#...###.#.##..##...##...###...##.###..#.#.#####.#.#.##....#.##..
...#.#....##.#.....###.##...#..##....#...###....#..#.###...##.#...###.#....#...##..###.#.....##....#
.#######..#...##.#.###.##.#.###...##......#.###.#...#.###.#.#.#..#..#####..#########...##..##...#..#
.#..#.##...#.#..#.##..#.#.#.##.....####.#..#.###..##.#.#.#...#....#.#..##.######...#.#..##.##...#..#
#.#######.#####..#####.##.##.#.#.##.###..#....####.#..##.##.######..###...#.#..#.####.##.##....####.
...##..#...##..#..#.....#.##...#.....##.#####.###.########.######..#...###..#.##.#.#.##..#.#.##..##.
#..#..#.#....###.#...##..####.#.##..#.####.###..##.#...#.###.#..#.##..#######.#...#..#.#..##.#....##
..#.##.#.####..##.###.###..#.##.#.####..##....##.###.#..##.#.###.###.##.##.#####..#.#...########....
.#.#.###..###...#...#..##.##......#..#...#.#.#.######.#.#...##..##........#....###..##...#..##.##...
##..#....##.###...##.#.##.##.##..#....#.#.#..#..####.##..#...#...#..#..#####.###...#..###..#...#.#..
##.#.#.##.###.....######.#.....#...#.##....###.#.##.#.#.##..##.######.#####....#.#####...##.#..###.#
######.#...####..###..##..#..##...#.#....##.#...##...#.....#...##....#.##..###..###...###..#..######
.....##.........#####.#.##..#..#.#.#.#.##...#....#.....###.########...#..####..#...#...##..#.##.##.#
#..###...#.##.##.#.#..####.#.....##..###....##..#...#.#...##.##..###..####...#.####..##..#..##..#...
#.####.#..##.#..#.....#..#.#..###...######.#.........####....###..#.#.#.##.#..#...#..####.....##..#.
..##....#.###.......##.#...#.####..##....##.#..#....#######...####.##..#####.#.#.#.#.##..##..#.#.#..
#.#.#.###..#..#.#..#.#.###....#...#####.###...........#.#....#####...#..####....#...###.#..#..####..
.......#.####.##...#..#.##..###..#..#.#.#.#.###....#....#.#.#..#.#..##.#####.#.....#.##.#.###.###.##
..###...#..#...####.#..##..##.#.#..#...#.#..#....###.#..####..######...####.#.##..#.#..###...##.####
..#.###..#.#...##...#.#....#..#...#.#..##.######.######.#.##.....#..##.#..###..#..#.##.###...#..#.##
####..##.####.....#...#.#.###..#...####.###.#.#.#.......##...#....#..#....#.#......###...#####.#.##.
#..##..#..#.####...#####.#.###.##.#.##.....#.#..#.##........######.#.#.###....##.##..##..########.##
#.#....###.##....#######.#...#.#.#.#..##.#.##...#.###...#.#.#..#.#..####.#.#..#..#.##.####....#..##.
####.##....#.......###..#..##.#.#.##..#...#...##.###....##..###.#.#...#..#.....##.###.##...###....##
..##.#..#....######..#.##.#.#...##..####.#####...##.#..###.##...#..####..###.##..##.##.#####.#..#.#.
.#.##..#..##.#.###.###....#.#..#....#...###.##.#.#.####.....#....#...#.....#....#.#.###.#..#.##..###
..###.#.#.##...##.##.##.#...#####.#..##.#....##..####...###..#....#.##...#........#####.#.###.#..#..
....#..##..##....#.#....#.#..##...##.#...##.###.#.#..###..##.##.##..#.#.#..#.#.##.......#.##.###..#.
.#..##.##.####.##....##.##.....###..##.#.##...#..###....###.###....#.#....#....#.##.#.##.#.##.....##
#.#..#.##.###.#.######.....###.#..#...#.#.....##.###.#...#.#..###.#.....##.###.#.###.####..#####.#..
#.#.##......#.##.#.#..##....#..###.#.###...##...###.#..#.##...#..#.##..##.#...######.##.....#####.##
#.#..#####....###.###...#.......#....###.##...#..#.##..#...#####..#..#.##......###...#...###..#.#..#
#.##..##.##.#..#.##.##..#.###.##.........###.#.#..#.#.....#.#...#.#.##.#.##.#...#...####.#.......##.
.#...####.##..#..##....####..######...#.#..##.##.....#####.#...#..#.####.#######...#.#####..#.###...
.#..######.#.##..##...##.....###.#..##..#...####..###...###.###..#..######.#....########..#####...#.
#..##.......#####...###..#.#.##.#..###.#...##.#..#.##.###...###...##.#..##..########..#.#..##..#.###
.#.#..#...#.#..#..##...#.#.##...###..#..#....###.#....#.##....###.###..##..#.#.####..####.#######.##
...##..##.##.###.##.###...##.#.#.....##.####..#..##.#..#.####...##..#..#.##...##...###.##.#.......##
.#.....#.##..#.#.....#.##.##..###..#....###...#.#....##########.##.###.#...#.####..####.#..#.#..###.
.##.#.#.##..#..###.###.##.#########.#.#.#.#.##.###..##..#.##.####......#####...#..####.#.##..#####.#
..#....###...##....#.###..##..#..####.##..####.#..####.###.#....####.....#.###..##...##..####...##.#
.###.....###.##.##..###.###.....##..#.######.#.#..##..#.##.#..#.#.#....#...#.#.#...#...##....#..##.#
..##....#..#####....#..####.#.#...##.#....##..##.###.###....###......#...#.#####.......#...#.....###
###.#..#.#.##..#..#...#.#....###.##.#.###.#...#.##.#..#.#.......#.#.#.###.####.###....#..##..#####..
.#..#######.#..###.#.##.#####.#####...##..#.####.#.#.##..###...#..##.##..#.#.###..#....#..#...###.#.
..#####..#.##.....###..##.#...#.#.#..#######.#..#...#.##.##.#.#....####...###..##...#....####.#..#.#
.####..#.#.##.###.#.##.....#..##.#.....###.....#..##...#....###.###..#......###.#.#.#.##.#.##..#...#
##.#..##.#..##...#.#....##..######..#.....#..#...#####....##......####.##..#...##..#.##.#.#######..#
##..####.#...##...#.#####.#.#..#....#.#..##.####.#..######.#..#..#.......#####..#..#..###.##...##.##
#.####......#.###...#..####.#..##.##..#.#...##.###.#...#####..####.#..#.#.....#.##...###...#.#....##
###.#.#.##.######......#.#.#.#.#........#..#..###.#.#.#..#.........#..#....#.#..#..#..###.##......##
##.#########...#...###..#.###.....#.#.##.........###....#.####.#...###.#..##..#.###..#..##......#.##'''
lights = dict()
for il, line in enumerate(inp.split("\n")):
for ic, char in enumerate(list(line)):
if char == '#':
lights[(il, ic)] = 1
elif char == '.':
lights[(il, ic)] = 0
neighbours = list(itertools.product([-1, 0, 1], [-1, 0, 1]))
neighbours.remove((0, 0))
def turn(el, origin):
state = 0
for neigh in neighbours:
try:
c = [sum(x) for x in zip(el, neigh)]
if origin[(c[0],c[1])] == 1:
state += 1
except KeyError:
continue
return state
def iteration(origin):
mask = {}
for ix in origin.keys():
state = turn(ix, origin)
if origin[ix] == 0 and state == 3:
mask[ix] = 1
elif origin[ix] == 1 and state not in [2, 3]:
mask[ix] = 0
else:
mask[ix] = origin[ix]
return mask
for i in range(100):
up = iteration(lights)
lights.update(up)
print(sum([1 for x in lights.values() if x == 1]))
corners = { (0, 0): 1, (0, 99): 1, (99, 0): 1, (99, 99): 1 }
lights_corners = dict()
for il, line in enumerate(inp.split("\n")):
for ic, char in enumerate(list(line)):
if char == '#':
lights_corners[(il, ic)] = 1
elif char == '.':
lights_corners[(il, ic)] = 0
lights_corners.update(corners)
for i in range(100):
up = iteration(lights_corners)
lights_corners.update(up)
lights_corners.update(corners)
print(sum([1 for x in lights_corners.values() if x == 1]))
##################################################
# Part 2 only but all it takes is removing the corners to get Part 1
corners = { (0,0), (0,99), (99,0), (99,99) }
lights = corners | {(x,y) for y, line in enumerate(inp.split("\n"))
for x, char in enumerate(line)
if char == '#'}
# Returns either True or False and counts all the True values.
neighbours = lambda x,y: sum((_x,_y) in lights for _x in (x-1,x,x+1)
for _y in (y-1,y,y+1) if (_x, _y) != (x, y))
for c in range(100):
lights = corners | {(x,y) for x in range(100) for y in range(100)
if (x,y) in lights and 2 <= neighbours(x,y) <= 3
or (x,y) not in lights and neighbours(x,y) == 3}
print(len(lights))
m = $stdin.readlines.map(&:strip)
m = inp.split("\n") # if repl or inp as multiline string
m[0][0] = '#'
m[m.size-1][0] = '#'
m[m.size-1][m[0].size - 1] = '#'
m[0][m[0].size - 1] = '#'
def g(mm, y, x)
return '#' if x == 0 and y == 0
return '#' if x == 0 and y == mm.size - 1
return '#' if x == mm[0].size - 1 and y == mm.size - 1
return '#' if x == mm[0].size - 1 and y == 0
sum = 0
(-1..1).each do |dy|
(-1..1).each do |dx|
yy,xx = y + dy, x + dx
next if dy == 0 and dx == 0
next if yy < 0 or xx < 0
next if yy >= mm.size or xx >= mm[0].size
sum += 1 if mm[yy][xx] == '#'
end
end
return (sum == 2 or sum == 3) ? '#' : '.' if mm[y][x] == '#'
return sum == 3 ? '#' : '.'
end
def f(m)
mm = []
m.size.times do |y|
line = ''
m[y].size.times do |x|
line += g(m, y, x)
end
mm << line
end
return mm
end
100.times {
m = f(m)
}
p m.flatten.join.count('#')
replacements = '''Al => ThF
Al => ThRnFAr
B => BCa
B => TiB
B => TiRnFAr
Ca => CaCa
Ca => PB
Ca => PRnFAr
Ca => SiRnFYFAr
Ca => SiRnMgAr
Ca => SiTh
F => CaF
F => PMg
F => SiAl
H => CRnAlAr
H => CRnFYFYFAr
H => CRnFYMgAr
H => CRnMgYFAr
H => HCa
H => NRnFYFAr
H => NRnMgAr
H => NTh
H => OB
H => ORnFAr
Mg => BF
Mg => TiMg
N => CRnFAr
N => HSi
O => CRnFYFAr
O => CRnMgAr
O => HP
O => NRnFAr
O => OTi
P => CaP
P => PTi
P => SiRnFAr
Si => CaSi
Th => ThCa
Ti => BP
Ti => TiTi
e => HF
e => NAl
e => OMg'''
inp = "CRnCaSiRnBSiRnFArTiBPTiTiBFArPBCaSiThSiRnTiBPBPMgArCaSiRnTiMgArCaSiThCaS"
"iRnFArRnSiRnFArTiTiBFArCaCaSiRnSiThCaCaSiRnMgArFYSiRnFYCaFArSiThCaSiThPB"
"PTiMgArCaPRnSiAlArPBCaCaSiRnFYSiThCaRnFArArCaCaSiRnPBSiRnFArMgYCaCaCaCaS"
"iThCaCaSiAlArCaCaSiRnPBSiAlArBCaCaCaCaSiThCaPBSiThPBPBCaSiRnFYFArSiThCaS"
"iRnFArBCaCaSiRnFYFArSiThCaPBSiThCaSiRnPMgArRnFArPTiBCaPRnFArCaCaCaCaSiRn"
"CaCaSiRnFYFArFArBCaSiThFArThSiThSiRnTiRnPMgArFArCaSiThCaPBCaSiRnBFArCaCa"
"PRnCaCaPMgArSiRnFYFArCaSiThRnPBPMgAr"
import re
import itertools
trans = dict()
for line in replacements.splitlines():
k, v = line.split(" => ")
if k in trans:
trans[k].append(v)
else:
trans[k] = [v]
def gen():
for a in trans:
for b in trans[a]:
yield (a, b)
posse = set()
for el in gen():
if el[0] in inp:
for match in re.finditer(el[0], inp):
new = match.string[:match.start()] + el[1] + match.string[match.end():]
posse.add(new)
molecule = inp[::-1]
reps = {m[1][::-1]: m[0][::-1] for m in re.findall(r'(\w+) => (\w+)', replacements)}
def rep(x):
return reps[x.group()]
count = 0
while molecule != 'e':
molecule = re.sub('|'.join(reps.keys()), rep, molecule, 1)
count += 1
print(count)
inp = "CRnCaSiRnBSiRnFArTiBPTiTiBFArPBCaSiThSiRnTiBPBPMgArCaSiRnTiMgArCaSiThCaSiRnFArRnSiRnFArTiTiBFArCaCaSiRnSiThCaCaSiRnMgArFYSiRnFYCaFArSiThCaSiThPBPTiMgArCaPRnSiAlArPBCaCaSiRnFYSiThCaRnFArArCaCaSiRnPBSiRnFArMgYCaCaCaCaSiThCaCaSiAlArCaCaSiRnPBSiAlArBCaCaCaCaSiThCaPBSiThPBPBCaSiRnFYFArSiThCaSiRnFArBCaCaSiRnFYFArSiThCaPBSiThCaSiRnPMgArRnFArPTiBCaPRnFArCaCaCaCaSiRnCaCaSiRnFYFArFArBCaSiThFArThSiThSiRnTiRnPMgArFArCaSiThCaPBCaSiRnBFArCaCaPRnCaCaPMgArSiRnFYFArCaSiThRnPBPMgAr"
replace = "Al => ThF
Al => ThRnFAr
B => BCa
B => TiB
B => TiRnFAr
Ca => CaCa
Ca => PB
Ca => PRnFAr
Ca => SiRnFYFAr
Ca => SiRnMgAr
Ca => SiTh
F => CaF
F => PMg
F => SiAl
H => CRnAlAr
H => CRnFYFYFAr
H => CRnFYMgAr
H => CRnMgYFAr
H => HCa
H => NRnFYFAr
H => NRnMgAr
H => NTh
H => OB
H => ORnFAr
Mg => BF
Mg => TiMg
N => CRnFAr
N => HSi
O => CRnFYFAr
O => CRnMgAr
O => HP
O => NRnFAr
O => OTi
P => CaP
P => PTi
P => SiRnFAr
Si => CaSi
Th => ThCa
Ti => BP
Ti => TiTi
e => HF
e => NAl
e => OMg"
reps = {}
replace.split("\n").each { |line|
line.scan(/(\w+) => (\w+)/) { |x,y|
reps[y.reverse] = x.reverse
}
}
molecule = inp.reverse
count = 0
until molecule == 'e' do
molecule = molecule.sub(/#{reps.keys.join('|')}/) { |match| reps[match] }
count += 1
end
p count
string = "<string with newlines>"
array = list.split("\n")
array.map! { |size|
size = size.split('x')
size.map! { |el|
el.to_i
}
}
# lenght - l / width - w / height - h
array.map! { |el|
[['l',el[0]],['w',el[1]],['h',el[2]]].to_h
}
paper = 0
# 2*l*w + 2*w*h + 2*h*l
array.map { |gift|
face1 = gift['l']*gift['w']
face2 = gift['w']*gift['h']
face3 = gift['h']*gift['l']
min = [face1,face2,face3].min
paper += 2*face1+2*face2+2*face3+min
}
puts paper
ribbon = 0
# A present with dimensions 2x3x4 requires 2+2+3+3 = 10 (smallest perimeter)
# feet of ribbon to wrap the present plus 2*3*4 = 24 feet (product)
# of ribbon for the bow, for a total of 34 feet.
array.map { |gift|
short = [gift['l'], gift['w'], gift['h']].min(2)
perim = short[0]*2+short[1]*2
bow = gift['l']*gift['w']*gift['h']
ribbon += perim+bow
}
'use strict'
// const input = 34000000
let input = parseInt(process.argv[2], 10)
const presents = []
const presents2 = []
for (let e = 1; e < input / 10; e++) {
let visits = 0
for (let i = e; i < input / 10; i = i + e) {
if (!presents[i]) presents[i] = 10
presents[i] = presents[i] + e * 10
if (visits < 50) {
if (!presents2[i]) presents2[i] = 11
presents2[i] = presents2[i] + e * 11
visits = visits + 1
}
}
}
const partOne = presents.reduce((min, current, index) => (min === 0 && current >= input) ? min = index : min, 0)
const partTwo = presents2.reduce(function(min, current, index) {
return (min === 0 && current >= input) ? min = index : min;
}, 0)
console.log(partOne)
console.log(partTwo)
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
# integer division
# equivalent to operator.ifloordiv(n,i)
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
N = 34000000
presents = {}
for i in range(1, N // 10+1):
for j in range(i, N // 10+1, i):
try:
presents[j] += i * 10
except KeyError:
presents[j] = 10
print(min([k for k, v in presents.items() if v >= N]))
presents2 = {}
for i in range(1, N // 10+1):
e = min(i * 50, N // 10+1)
for j in range(i, e, i):
try:
presents2[j] += i * 11
except KeyError:
presents2[j] = 11
print(min([k for k, v in presents2.items() if v >= N]))
'use strict';
function* genItems() {
let weapons = [[8, 4, 0], [10, 5, 0], [25, 6, 0], [40, 7, 0], [74, 8, 0]],
armor = [[13, 0, 1], [31, 0, 2], [53, 0, 3], [75, 0, 4], [102, 0, 5]],
rings = [[20, 0, 1], [25, 1, 0], [40, 0, 2], [50, 2, 0], [80, 0, 3], [100, 3, 0]],
arrSum = (a, b, c, d) => a.map((el, i) => el + b[i] + c[i] + d[i]);
rings.unshift([0, 0, 0]); // for sets with 1 ring
armor.unshift([0, 0, 0]); // for sets with no armor
for (let w of weapons) {
for (let ar of armor) {
yield arrSum(w, ar, [0, 0, 0], [0, 0, 0]); // for sets with 0 rings
for (let r1i = 0; r1i < rings.length - 1; r1i++) {
for (let r2i = r1i + 1; r2i < rings.length; r2i++) {
yield arrSum(w, ar, rings[r1i], rings[r2i]);
}
}
}
}
}
let dps = (dmg, armor) => Math.max(1, dmg - armor),
hits = (hp, armor, dmg) => Math.ceil(hp / dps(dmg, armor));
function simulate([bossHp, bossDmg, bossArmor], pHp, [, pDmg, pArmor]) {
return hits(bossHp, bossArmor, pDmg) <= hits(pHp, pArmor, bossDmg); // true if player wins
}
let boss = document.body.textContent.match(/\d+/g).map(s => +s),
[minCostToWin, maxCostToLose] = [Infinity, -Infinity];
for (let items of genItems()) {
if (simulate(boss, 100, items)) {
minCostToWin = Math.min(minCostToWin, items[0]);
} else {
maxCostToLose = Math.max(maxCostToLose, items[0]);
}
}
console.log(minCostToWin, maxCostToLose);
/* ################################################## */
'use strict'
const weapons = [
{ cost: 8, damage: 4, armor: 0, name: 'Dagger' },
{ cost: 10, damage: 5, armor: 0, name: 'Shortsword' },
{ cost: 25, damage: 6, armor: 0, name: 'Warhammer' },
{ cost: 40, damage: 7, armor: 0, name: 'Longsword' },
{ cost: 74, damage: 8, armor: 0, name: 'Greataxe' },
]
const armor = [
{ cost: 0, damage: 0, armor: 0, name: 'Nothing' },
{ cost: 13, damage: 0, armor: 1, name: 'Leather' },
{ cost: 31, damage: 0, armor: 2, name: 'Chainmail' },
{ cost: 53, damage: 0, armor: 3, name: 'Splintnmail' },
{ cost: 75, damage: 0, armor: 4, name: 'Bandedmail' },
{ cost: 102, damage: 0, armor: 5, name: 'Platemail' },
]
const rings = [
{ cost: 0, damage: 0, armor: 0, name: 'Damage +0' },
{ cost: 25, damage: 1, armor: 0, name: 'Damage +1' },
{ cost: 25, damage: 1, armor: 0, name: 'Damage +1' },
{ cost: 50, damage: 2, armor: 0, name: 'Damage +2' },
{ cost: 100, damage: 3, armor: 0, name: 'Damage +3' },
{ cost: 0, damage: 0, armor: 0, name: 'Defense +0' },
{ cost: 20, damage: 0, armor: 1, name: 'Defense +1' },
{ cost: 40, damage: 0, armor: 2, name: 'Defense +2' },
{ cost: 80, damage: 0, armor: 3, name: 'Defense +3' },
]
const simulate = (player) => {
const boss = { hp: 104, armor: 1, damage: 8 }
while (boss.hp > 0 && player.hp > 0) {
const playerDamage = Math.max(player.damage - boss.armor, 1)
const bossDamage = Math.max(boss.damage - player.armor, 1)
if (player.hp > 0) boss.hp = boss.hp - playerDamage
if (boss.hp > 0) player.hp = player.hp - bossDamage
}
return player.hp > 0
}
let min = 1000
let max = 0
for (let weapon of weapons) {
for (let mail of armor) {
for (let ring1 of rings) {
const otherRings = rings.filter(ring => ring.name !== ring1.name)
for (let ring2 of otherRings) {
const player = {
hp: 100,
equipment: [weapon, mail, ring1, ring2],
get cost() {
return this.equipment.reduce((a, b) => a + b.cost, 0)
},
get armor() {
return this.equipment.reduce((a, b) => a + b.armor, 0)
},
get damage() {
return this.equipment.reduce((a, b) => a + b.damage, 0)
},
}
if (simulate(player)) {
min = Math.min(player.cost, min)
} else {
max = Math.max(player.cost, max)
}
}
}
}
}
console.log(min, max)
import re
import itertools
shop = '''\
Weapons: Cost Damage Armor
Dagger 8 4 0
Shortsword 10 5 0
Warhammer 25 6 0
Longsword 40 7 0
Greataxe 74 8 0
Armor: Cost Damage Armor
Leather 13 0 1
Chainmail 31 0 2
Splintmail 53 0 3
Bandedmail 75 0 4
Platemail 102 0 5
Rings: Cost Damage Armor
Damage +1 25 1 0
Damage +2 50 2 0
Damage +3 100 3 0
Defense +1 20 0 1
Defense +2 40 0 2
Defense +3 80 0 3'''
boss_stats = '''\
Hit Points: 100
Damage: 8
Armor: 2'''
class Fighter(object):
def __init__(self, hp, dmg, arm):
self.hitpoints = int(hp)
self.damage = int(dmg)
self.armor = int(arm)
def fightw(fighter1, fighter2):
while fighter1.hitpoints > 0:
fighter2.hitpoints -= max(1, fighter1.damage - fighter2.armor)
if fighter2.hitpoints <= 0:
break
fighter1.hitpoints -= max(1, fighter2.damage - fighter1.armor)
if fighter1.hitpoints > fighter2.hitpoints:
return True
else:
return False
# unnecessary?
def fightl(fighter1, fighter2):
while True:
fighter2.hitpoints -= max(1, fighter1.damage - fighter2.armor)
if fighter2.hitpoints <= 0:
return False
fighter1.hitpoints -= max(1, fighter2.damage - fighter1.armor)
if fighter1.hitpoints <= 0:
return True
stats = {}
for line in boss_stats.split("\n"):
k, v = line.split(":")
stats[k] = v
boss = Fighter(stats['Hit Points'], stats['Damage'], stats['Armor'])
catalogue = {}
for itemtype in shop.split("\n\n"):
category = itemtype.split("\n")[0].split(": ")[0]
catalogue[category] = {}
for line in itemtype.split("\n")[1:]:
name, cost, damage, armor = re.split("\s{2,}", line)
catalogue[category][name] = [int(cost), int(damage), int(armor)]
catalogue['Armor']['Dummy'] = [0, 0, 0]
catalogue['Rings']['Dummy'] = [0, 0, 0]
equipment = [(a, b, c, d) for a, b, c, d in itertools.product(
catalogue['Weapons'], catalogue['Armor'],
catalogue['Rings'], catalogue['Rings']) if c != d ]
winning = []
for each in equipment:
w, a, r1, r2 = each
cost = catalogue['Weapons'][w][0] + catalogue['Armor'][a][0] + \
catalogue['Rings'][r1][0] + catalogue['Rings'][r2][0]
damage = catalogue['Weapons'][w][1] + catalogue['Armor'][a][1] + \
catalogue['Rings'][r1][1] + catalogue['Rings'][r2][1]
armor = catalogue['Weapons'][w][2] + catalogue['Armor'][a][2] + \
catalogue['Rings'][r1][2] + catalogue['Rings'][r2][2]
me = Fighter(100, damage, armor)
tboss = Fighter(boss.hitpoints, boss.damage, boss.armor)
if fightw(me, tboss):
winning.append([cost, each])
print('Part 1 = {}'.format(min(winning)))
losing = []
for each in equipment:
w, a, r1, r2 = each
cost = catalogue['Weapons'][w][0] + catalogue['Armor'][a][0] + \
catalogue['Rings'][r1][0] + catalogue['Rings'][r2][0]
damage = catalogue['Weapons'][w][1] + catalogue['Armor'][a][1] + \
catalogue['Rings'][r1][1] + catalogue['Rings'][r2][1]
armor = catalogue['Weapons'][w][2] + catalogue['Armor'][a][2] + \
catalogue['Rings'][r1][2] + catalogue['Rings'][r2][2]
me = Fighter(100, damage, armor)
tboss = Fighter(boss.hitpoints, boss.damage, boss.armor)
# works also with if not fightw
if fightl(me, tboss):
losing.append([cost, each])
print('Part 2 = {}'.format(max(losing)))
HERO_HIT_POINTS = 100.0
BOSS_HIT_POINTS = 100.0
BOSS_DAMAGE = 8
BOSS_ARMOR = 2
# 1 weapon
WEAPONS = [
{ cost: 8, damage: 4, armor: 0 },
{ cost: 10, damage: 5, armor: 0 },
{ cost: 25, damage: 6, armor: 0 },
{ cost: 40, damage: 7, armor: 0 },
{ cost: 74, damage: 8, armor: 0 },
]
# 0-1 armor
ARMORS = [
{ cost: 0, damage: 0, armor: 0 },
{ cost: 13, damage: 0, armor: 1 },
{ cost: 31, damage: 0, armor: 2 },
{ cost: 53, damage: 0, armor: 3 },
{ cost: 75, damage: 0, armor: 4 },
{ cost: 102, damage: 0, armor: 5 },
]
# 0-2 rings
RINGS = [
{ cost: 0, damage: 0, armor: 0 },
{ cost: 25, damage: 1, armor: 0 },
{ cost: 50, damage: 2, armor: 0 },
{ cost: 100, damage: 3, armor: 0 },
{ cost: 20, damage: 0, armor: 1 },
{ cost: 40, damage: 0, armor: 2 },
{ cost: 80, damage: 0, armor: 3 },
]
min_gold = Float::INFINITY
max_gold = 0
WEAPONS.each do |weapon|
ARMORS.each do |armor|
RINGS.combination(2).each do |ring_1, ring_2|
hero_damage = weapon[:damage] + ring_1[:damage] + ring_2[:damage]
hero_armor = armor[:armor] + ring_1[:armor] + ring_2[:armor]
hero_damages_dealt = [1, hero_damage - BOSS_ARMOR].max
boss_damages_dealt = [1, BOSS_DAMAGE - hero_armor].max
gold_spent = weapon[:cost] + armor[:cost] + ring_1[:cost] + ring_2[:cost]
if (BOSS_HIT_POINTS / hero_damages_dealt).ceil <= (HERO_HIT_POINTS / boss_damages_dealt).ceil
min_gold = gold_spent if gold_spent < min_gold
else
max_gold = gold_spent if gold_spent > max_gold
end
end
end
end
p min_gold, max_gold
def sim(actions, part):
boss_hp, boss_dmg = 58, 9
hp, mana, armor = 50, 500, 0
turn, turn_c = 0, 0
mana_spent = 0
poison_left, shield_left, recharge_left = 0, 0, 0
my_turn = 1
spell_cost = {'M': 53, 'D': 73, 'S': 113, 'P': 173, 'R': 229}
while True:
if len(actions)-1 < turn_c:
print('out of moves')
return 0
if poison_left:
poison_left = max(poison_left - 1, 0)
boss_hp -= 3
if shield_left:
shield_left = max(shield_left - 1, 0)
armor = 7
else:
armor = 0
if recharge_left:
recharge_left = max(recharge_left - 1, 0)
mana += 101
if my_turn == 1:
if part == 2:
hp -= 1
if hp <= 0:
return 0
action = actions[turn_c]
mana -= spell_cost[action]
mana_spent += spell_cost[action]
if action == 'M':
boss_hp -= 4
elif action == 'D':
boss_hp -= 2
hp += 2
elif action == 'S':
if shield_left:
return 0
shield_left = 6
elif action == 'P':
if poison_left:
return 0
poison_left = 6
elif action == 'R':
if recharge_left:
return 0
recharge_left = 5
if mana < 0:
return 0
if boss_hp <= 0:
return mana_spent
if my_turn == -1:
hp -= max(boss_dmg - armor, 1)
if hp <= 0:
return 0
if my_turn == 1:
turn_c += 1
my_turn = -my_turn
turn += 1
def iterate_actions(pos):
actions[pos] = 'DSPRM'['MDSPR'.index(actions[pos])]
if actions[pos] == 'M':
if pos+1 <= len(actions):
iterate_actions(pos+1)
for part in (1, 2):
actions = ['M'] * 20
min_spent = 1000000
for i in range(1000000):
result = sim(actions, part)
if result:
min_spent = min(result, min_spent)
iterate_actions(0)
print(min_spent)
var day23 = (input, a = 0) => {
let i = 0,
reg = {a: a, b: 0},
program = input.map(s => s.match(/([^, ]+)/g)), // maybe split instead of match?
ops = {
hlf: x => reg[x] >>= 1,
tpl: x => reg[x] *= 3,
inc: x => reg[x]++,
jmp: x => i += +x - 1,
jie: (x, y) => i += reg[x] % 2 === 0 ? +y - 1 : 0,
jio: (x, y) => i += reg[x] === 1 ? +y - 1 : 0
}
do {
let [o, x, y] = program[i]
ops[o](x, y)
} while (++i < program.length)
return reg.b
}
inp = `jio a, +19
inc a
tpl a
inc a
tpl a
inc a
tpl a
tpl a
inc a
inc a
tpl a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
jmp +23
tpl a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
inc a
tpl a
inc a
tpl a
inc a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
tpl a
inc a
jio a, +8
inc b
jie a, +4
tpl a
inc a
jmp +2
hlf a
jmp -7`
input = inp.split("\n")
console.log(day23(input))
console.log(day23(input, a = 1))
import re
inp = '''\
jio a, +19
inc a
tpl a
inc a
tpl a
inc a
tpl a
tpl a
inc a
inc a
tpl a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
jmp +23
tpl a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
inc a
tpl a
inc a
tpl a
inc a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
tpl a
inc a
jio a, +8
inc b
jie a, +4
tpl a
inc a
jmp +2
hlf a
jmp -7'''.split("\n")
registry = { 'a': 0, 'b': 0 }
class Machine(object):
"""
hlf r sets register r to half its current value, then continues with the next instruction.
tpl r sets register r to triple its current value, then continues with the next instruction.
inc r increments register r, adding 1 to it, then continues with the next instruction.
jmp offset is a jump; it continues with the instruction offset away relative to itself.
jie r, offset is like jmp, but only jumps if register r is even ("jump if even").
jio r, offset is like jmp, but only jumps if register r is 1 ("jump if one", not odd).
"""
# TODO: for another day when you actually have time
def hlf(reg):
reg //= 2
return reg
def tpl(reg):
reg *= 3
return reg
def inc(reg):
reg += 1
return reg
def jmp(cline, offset):
cline += offset
return cline
def jie(reg, cline, offset):
if not reg % 2:
cline += offset
return cline
else:
cline += 1
return cline
def jio(reg, cline, offset):
if reg == 1:
cline += offset
return cline
else:
cline += 1
return cline
def parse(line):
matches = list(filter(None, re.split(r'[, ]', line)))
return matches
methods = {
'hlf': hlf,
'tpl': tpl,
'inc': inc,
'jmp': jmp,
'jie': jie,
'jio': jio
}
inp_lines = list(enumerate(inp))
line = inp_lines[0]
while True:
try:
parsed = parse(line[1])
if parsed[0] in ['jio', 'jie']:
op, reg, offset = parsed
newline = methods.get(op)(registry[reg], line[0], int(offset))
line = inp_lines[newline]
elif parsed[0] in ['hlf', 'tpl', 'inc']:
op, reg = parsed
registry[reg] = methods.get(op)(registry[reg])
line = inp_lines[line[0] + 1]
elif parsed[0] == 'jmp':
op, offset = parsed
newline = methods.get(op)(line[0], int(offset))
line = inp_lines[newline]
except IndexError:
print('Program Ended')
break
print(registry)
registry = { 'a': 1, 'b': 0 }
line = inp_lines[0]
while True:
try:
parsed = parse(line[1])
if parsed[0] in ['jio', 'jie']:
op, reg, offset = parsed
newline = methods.get(op)(registry[reg], line[0], int(offset))
line = inp_lines[newline]
elif parsed[0] in ['hlf', 'tpl', 'inc']:
op, reg = parsed
registry[reg] = methods.get(op)(registry[reg])
line = inp_lines[line[0] + 1]
elif parsed[0] == 'jmp':
op, offset = parsed
newline = methods.get(op)(line[0], int(offset))
line = inp_lines[newline]
except IndexError:
print('Program Ended')
break
print(registry)
import itertools
import operator
import functools
weights = list(map(lambda x: int(x), '''\
1
3
5
11
13
17
19
23
29
31
37
41
43
47
53
59
67
71
73
79
83
89
97
101
103
107
109
113'''.split("\n")))
parts = 3 # parts = 4
tot = sum(weights)/parts
def hasSum(lst, sub):
for y in range(1,len(lst)):
for x in itertools.combinations(lst, y):
if sum(x) == tot:
if sub == 2:
return True
elif sub < parts:
return hasSum(list(set(lst) - set(x)), sub - 1)
elif hasSum(list(set(lst) - set(x)), sub - 1) :
return functools.reduce(operator.mul, x, 1)
print(hasSum(weights, parts))
'''To continue, please consult the code grid in the manual. Enter the code at row 2978, column 3083.'''
def next_code(cur_code):
return (cur_code * 252533) % 33554393
def get_code_count(row, column):
# for previous columns is?
# lenght of diagonal is equal to column number for last column
return sum(range(row + column - 1)) + column
first_code = 20151125
code_coords = (2978, 3083)
code_count = get_code_count(*code_coords)
cur_code = first_code
for i in range(code_count - 1):
cur_code = next_code(cur_code)
print(cur_code)
string = "<long <^v> string>"
start = [0, 0]
walk = []
walk.push(start)
string.each_char { |i|
case i
when "^"
new = [walk[-1][0]+1,walk[-1][1]]
walk.push(new)
when "v"
new = [walk[-1][0]-1,walk[-1][1]]
walk.push(new)
when "<"
new = [walk[-1][0],walk[-1][1]-1]
walk.push(new)
when ">"
new = [walk[-1][0],walk[-1][1]+1]
walk.push(new)
end
}
puts walk.uniq.count
vect = { '^' => ->(pos) { pos[1] += 1 },
'>' => ->(pos) { pos[0] += 1 },
'v' => ->(pos) { pos[1] -= 1 },
'<' => ->(pos) { pos[0] -= 1 } }
vis = {}
map = [[0, 0], [0, 0]]
string.each_char.with_index do |c, i|
vect[c].call(map[i%2])
vis[[map[i%2][0],map[i%2][1]]] = true
end
p vis.keys.size
###################################################################
# from https://gist.github.com/damoonrashidi/60c1253de720465cdb7f #
###################################################################
class Santa
def initialize x, y
@x = x
@y = y
end
def position
"#{@x}:#{@y}"
end
def move dir
case dir
when 'v'
@y -= 1
when '^'
@y += 1
when '<'
@x -= 1
when '>'
@x += 1
end
end
end
map = {"0:0" => 2}
santa = Santa.new 0,0
robot = Santa.new 0,0
File.read('input.txt').split('').each_slice(2) do |set|
santa.move set[0]
robot.move set[1]
map[santa.position] = true
map[robot.position] = true
end
puts map.length
###################################################################
vectors = {
?^ => [ 0, -1],
?> => [ 1, 0],
?v => [ 0, 1],
?< => [-1, 0]
}
# xs[0],ys[0] is the position of the first santa
# xs[1],ys[1] is the position of the second santa
xs, ys = [0, 0], [0, 0]
visited = {}
gets.chomp.each_char.with_index do |c, i|
visited[[
xs[i % 2] += vectors[c][0],
ys[i % 2] += vectors[c][1]
]] = true # or 1
end
p visited.count # .keys.size
###################################################################
# only the first part
s = [[0, 0]]
x = 0
y = 0
vect = { '^' => -> { y += 1 },
'>' => -> { x += 1 },
'v' => -> { y -= 1 },
'<' => -> { x -= 1 } }
s.each_char do |c|
vect[c].call
s << [x, y]
end
p s.uniq.size # .count
require 'digest'
secret = '<secret>'
n5 = 1
5hash = ''
until 5hash[0...5] == '00000'
n5 += 1
5hash = Digest::MD5::hexdigest(secret+n.to_s)
end
puts n5
n6 = 1
6hash = ''
until 6hash[0...6] == '000000'
n5 += 1
6hash = Digest::MD5::hexdigest(secret+n.to_s)
end
puts n6
// get from browser console
var strs=document.body.textContent.split('\n').filter(function(l){return l.length>0});
//part1
function part1(str){
var vowels=str.match(/[aeiou]/g);
var badCouplet=str.match(/ab|cd|pq|xy/);
var doubles=str.match(/(.)\1/);
return (vowels!=undefined && vowels.length>2) &&
(badCouplet==undefined || badCouplet.length==0) &&
(doubles!=undefined && doubles.length>0)
}
strs.filter(part1).length
//part2
function part2(str) {
var repeat=str.match(/(..).*\1/);
var zxz=str.match(/(.).\1/);
return (repeat!=undefined && repeat.length>0) &&
(zxz!=undefined && zxz.length>0)
}
strs.filter(part2).length
string = "<long multiline string of strings>"
part1 = string.split("\n")
part2 = string.split("\n")
part1.keep_if do |x|
x.scan(/[aeiou]/).length >= 3 &&
/(.)\1/.match(x) &&
! /ab|cd|pq|xy/.match(x)
end
puts part1.uniq.count
part2.keep_if do |x|
/(.).\1/.match(x) && /(..).*\1/.match(x)
end
puts part2.uniq.count
inst = "turn on 0,0 through 999,999
toggle 0,0 through 999,0
turn off 499,499 through 500,500" # string similar to these
arr = inst.split("\n").map do |l|
l =~ /(toggle|turn on|turn off).(\d+),(\d+).through.(\d+),(\d+)/;
[$1, $2.to_i, $3.to_i, $4.to_i, $5.to_i]
end
turned = {}
act = {
'turn on' => ->(hash, str) { hash[str] = 1 },
'turn off' => ->(hash, str) { hash[str] = 0 },
'toggle' => ->(hash, str) {
if hash[str] == 1 then
hash[str] = 0
else
hash[str] = 1
end
},
}
arr.each do |op, x1, y1, x2, y2|
xs, ys = [*x1..x2], [*y1..y2]
(xs).product(ys).each { |a, b|
act[op].call(turned, [a, b])
}
end
p turned.map{ |k,v| v == 1 ? k : nil }.compact.count
bright = {}
bact = {
'turn on' => ->(hash, arr, val) { hash[arr] = val.to_i + 1 },
'turn off' => ->(hash, arr, val) {
unless val.to_i == 0 then
hash[arr] = val.to_i - 1
end
},
'toggle' => ->(hash, arr, val) { hash[arr] = val.to_i + 2 },
}
arr.each do |op, x1, y1, x2, y2|
xs, ys = [*x1..x2], [*y1..y2]
xs.product(ys).each { |a, b|
bact[op].call(bright, [a, b], bright[[a, b]])
}
end
p bright.inject(0) { |total, (k, v)| total + v }
instructions = 'long list of a AND b -> operations'
calc = dict()
results = dict()
for command in commands:
(ops, res) = command.split('->')
calc[res.strip()] = ops.strip().split(' ')
def calculate(name):
try:
return int(name)
except ValueError:
pass
if name not in results:
ops = calc[name]
if len(ops) == 1:
res = calculate(ops[0])
else:
op = ops[-2]
if op == 'AND':
res = calculate(ops[0]) & calculate(ops[2])
elif op == 'OR':
res = calculate(ops[0]) | calculate(ops[2])
elif op == 'NOT':
res = ~calculate(ops[1]) & 0xffff
elif op == 'RSHIFT':
res = calculate(ops[0]) >> calculate(ops[2])
elif op == 'LSHIFT':
res = calculate(ops[0]) << calculate(ops[2])
results[name] = res
return results[name]
print "a: %d" % calculate('a')
##################################################
def evaluate(gate, commands, values):
try:
val = int(gate)
values[gate] = val
return
except ValueError:
pass
command = commands[gate]
if len(command) == 1:
try:
values[gate] = int(command[0])
except ValueError:
evaluate(command[0], commands, values)
values[gate] = values[command[0]]
elif len(command) == 2:
if command[0] == "NOT":
lhs = command[1]
if values.get(lhs) is None:
evaluate(lhs, commands, values)
values[gate] = 0xffff - values[lhs]
elif len(command) == 3:
lhs = command[0]
rhs = command[2]
op = command[1]
if values.get(lhs) is None:
evaluate(lhs, commands, values)
if values.get(rhs) is None:
evaluate(rhs, commands, values)
if op == "AND":
values[gate] = values[lhs] & values[rhs]
elif op == "OR":
values[gate] = values[lhs] | values[rhs]
elif op == "RSHIFT":
values[gate] = 0xffff & (values[lhs] >> int(rhs))
elif op == "LSHIFT":
values[gate] = 0xffff & (values[lhs] << int(rhs))
def solve(instructions):
commands = {tokens[-1] : tokens[:-2]
for tokens in map(str.split, instructions.split('\n')) }
values = {}
evaluate('a', commands, values)
print(values['a'])
##################################################
def day7(text, initialVariables=None):
stmts = text.split("\n")
variables = {} if initialVariables is None else initialVariables
while len(stmts) > 0:
stmts = [s for s in stmts if not evalStmt(s, variables)]
return { k.lower(): v for k,v in variables.items() } # EDIT: fixed
def evalStmt(stmt, variables):
expr, var = stmt.upper().split(' -> ') # EDIT: fixed
expr = expr.replace('RSHIFT', '>>').replace('LSHIFT', '<<').replace('AND','&').replace('OR','|').replace('NOT','0xffff ^ ')
try:
exec('%s = (%s) & 0xffff' % (var, expr), {}, variables)
return True
except NameError:
return False
class Circuit
TRANSFORMS = {
"LSHIFT" => "<<",
"RSHIFT" => ">>",
"NOT" => "~",
"AND" => "&",
"OR" => "|",
/\b(if|do|in)\b/ => "\\1_",
}
def add(line)
TRANSFORMS.each do |from, to|
line.gsub!(from, to)
end
expr, name = line.strip.split(" -> ")
method = "def #{name}; @#{name} ||= #{expr}; end"
puts method
instance_eval method
end
end
circuit = Circuit.new
open("input.txt").each_line { |line| circuit.add(line) }
# circuit.add("46065 -> b")
p circuit.a
##################################################
instructions = 'long list of a AND b -> operations'
trans = {
'AND' => '&',
'OR' => '|',
'NOT' => '~',
'LSHIFT' => '<<',
'RSHIFT' => '>>'
}
res = inst.gsub(Regexp.union(trans.keys), trans).
gsub(/(.+?) -> (\w+)/) { "%2s = #{$1}" % $2 }.
upcase.
split("\n").
sort.
rotate.
join(?;)
a = eval res
p eval res
res.gsub(/B = \d+;(.+)/, "B = #{a};#{$1}")
p eval res
##################################################
data = File.readlines("input.txt")
$machine = {}
$output = {}
data.each do |c|
x,y = c.chomp.split('->')
y = y.lstrip
$machine[y] = x.split
end
def foo(gate)
if gate.match(/^\d+$/)
return gate.to_i
end
if ! $output.has_key?(gate)
operate = $machine[gate]
if operate.length == 1
value = foo(operate[0])
else
z = operate[-2]
if z == 'RSHIFT'
value = foo(operate[0]) >> foo(operate[2])
elsif z == 'LSHIFT'
value = foo(operate[0]) << foo(operate[2])
elsif z == 'AND'
value = foo(operate[0]) & foo(operate[2])
elsif z == 'OR'
value = foo(operate[0]) | foo(operate[2])
elsif z == 'NOT'
value = ~foo(operate[1])
end
end
$output[gate] = value
end
return $output[gate]
end
p foo('a')
import json, ast
string = r'''
multiline raw string
"aaa\"aaa"
"\x27"''' # can contain quotes and hexadecimal characters
arr = string.split("\n")
mem_repr = 0
for line in arr: # 1371
total += len(line) - len(ast.literal_eval(line))
enc_repr = 0
for line in arr:
total2 += len(json.dumps(line)) - len(line)
print("{}, {}".format(mem_repr, enc_repr))
##################################################
from ast import literal_eval
def day8(text):
rawLen = sum(len(s) for s in text.split("\n"))
evalLen = sum(len(literal_eval(s)) for s in text.split("\n") if len(s.strip()) > 0)
return rawLen - evalLen
def day8_part2(text):
rawLen = sum(len(s) for s in text.split("\n"))
quotedLen = sum(len('"' + s.replace("\\", "\\\\").replace('"', '\\"') + '"')
for s in text.split("\n") if len(s) > 0)
return quotedLen - rawLen
string = 'raw string with literals'
arr = string.split("\n")
p arr.inject(0) { |sum, el| sum + (el.length - eval(el).length) }
p arr.inject(0) { |sum, el| sum + (el.inspect.length - el.length) }
##################################################
s = 'raw string with literals'
t = s.delete("\r\n").size
p t - s.split.map { |s| eval(s).size }.reduce(:+)
p s.split.map(&:inspect).map(&:size).reduce(:+) - t
travel = '''AlphaCentauri to Snowdin = 66
AlphaCentauri to Tambi = 28
AlphaCentauri to Faerun = 60
AlphaCentauri to Norrath = 34
AlphaCentauri to Straylight = 34
AlphaCentauri to Tristram = 3
AlphaCentauri to Arbre = 108
Snowdin to Tambi = 22
Snowdin to Faerun = 12
Snowdin to Norrath = 91
Snowdin to Straylight = 121
Snowdin to Tristram = 111
Snowdin to Arbre = 71
Tambi to Faerun = 39
Tambi to Norrath = 113
Tambi to Straylight = 130
Tambi to Tristram = 35
Tambi to Arbre = 40
Faerun to Norrath = 63
Faerun to Straylight = 21
Faerun to Tristram = 57
Faerun to Arbre = 83
Norrath to Straylight = 9
Norrath to Tristram = 50
Norrath to Arbre = 60
Straylight to Tristram = 27
Straylight to Arbre = 81
Tristram to Arbre = 90'''
import sys
from itertools import permutations
places = set()
distances = dict()
for line in travel.split("\n"):
(source, _, dest, _, distance) = line.split()
places.add(source)
places.add(dest)
distances.setdefault(source, dict())[dest] = int(distance)
distances.setdefault(dest, dict())[source] = int(distance)
shortest = sys.maxsize
longest = 0
for items in permutations(places):
dist = sum(map(lambda x, y: distances[x][y], items[:-1], items[1:]))
shortest = min(shortest, dist)
longest = max(longest, dist)
print("shortest: {:d}".format(shortest))
print("longest: {:d}".format(longest))
travel = "AlphaCentauri to Snowdin = 66
AlphaCentauri to Tambi = 28
AlphaCentauri to Faerun = 60
AlphaCentauri to Norrath = 34
AlphaCentauri to Straylight = 34
AlphaCentauri to Tristram = 3
AlphaCentauri to Arbre = 108
Snowdin to Tambi = 22
Snowdin to Faerun = 12
Snowdin to Norrath = 91
Snowdin to Straylight = 121
Snowdin to Tristram = 111
Snowdin to Arbre = 71
Tambi to Faerun = 39
Tambi to Norrath = 113
Tambi to Straylight = 130
Tambi to Tristram = 35
Tambi to Arbre = 40
Faerun to Norrath = 63
Faerun to Straylight = 21
Faerun to Tristram = 57
Faerun to Arbre = 83
Norrath to Straylight = 9
Norrath to Tristram = 50
Norrath to Arbre = 60
Straylight to Tristram = 27
Straylight to Arbre = 81
Tristram to Arbre = 90"
travel.split("\n") do |line|
/(\w+) to (\w+) = (\d+)/.match(line)
distances[$1][$2] = distances[$2][$1] = $3.to_i
end
distances = Hash.new { |h,k| h[k] = {} }
distances = distances.keys.permutation.map do |path|
path.each_cons(2).reduce(0) do |distance, (current_town, next_town)|
distance + distances[current_town][next_town]
end
end
p "shortest: #{distances.sort[0]}"
p "longest: #{distances.sort[-1]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment