Skip to content

Instantly share code, notes, and snippets.

@PamelaM
PamelaM / forms.py
Created May 24, 2022 15:02 — forked from eerien/forms.py
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'
@PamelaM
PamelaM / aoc_2017_day15.py
Created December 15, 2017 14:23
Advent of Code 2017, Day 15
import time
def generator(input, factor, criteria):
value = input
ignored = 0
while True:
value = (value * factor) % 2147483647
if (value % criteria) == 0:
yield value, ignored
else:
@PamelaM
PamelaM / aoc_2017_day14.py
Last active December 14, 2017 19:02
Advent of Code 2017, Day 14
def _replace(data, position, chunk):
#print position, chunk
for idx, v in enumerate(chunk):
data[position+idx] = v
def hash_list(lengths, data, position=0, skip_size=0):
#print position, skip_size, data
base_len = len(data)
for length in lengths:
@PamelaM
PamelaM / aoc_2017_day13.py
Created December 14, 2017 15:41
Advent of Code 2017, Day 13
INPUT = """0: 3
1: 2
2: 4
4: 6
6: 5
8: 8
10: 6
12: 4
14: 8
16: 6
@PamelaM
PamelaM / aoc_2017_day12.py
Created December 13, 2017 16:21
Advent of Code 2017, Day 12
INPUT = """0 <-> 454, 528, 621, 1023, 1199
1 <-> 1335, 1563, 1627, 1679
2 <-> 353, 689
3 <-> 3, 1171
4 <-> 1247
5 <-> 758, 928, 1260
6 <-> 1010
7 <-> 570
8 <-> 710, 1610
9 <-> 9
@PamelaM
PamelaM / aoc_2017_day11.py
Created December 13, 2017 15:47
Advent of Code 2017, Day 11
INPUT = """ne,n,ne,s,nw,s,s,sw,sw,sw,sw,sw,nw,nw,sw,nw,nw,n,nw,nw,nw,nw,nw,s,n,nw,s,n,n,nw,n,n,se,n,n,n,s,n,n,n,n,sw,se,n,n,ne,s,ne,ne,nw,ne,n,ne,ne,ne,ne,ne,s,ne,ne,s,se,ne,ne,ne,ne,ne,nw,ne,se,ne,ne,n,ne,ne,se,ne,ne,se,se,se,se,se,n,se,ne,se,se,ne,ne,se,sw,sw,se,se,s,sw,se,se,se,s,n,se,se,s,se,s,se,se,se,se,se,se,n,s,s,nw,se,s,s,nw,s,se,se,s,s,s,sw,s,s,se,n,ne,s,s,s,s,s,s,nw,s,n,s,n,se,s,s,sw,s,ne,s,s,s,s,s,nw,ne,s,s,sw,s,s,s,s,se,n,nw,s,s,s,s,s,sw,s,n,sw,s,s,sw,sw,s,sw,sw,ne,sw,sw,s,ne,s,sw,sw,sw,sw,s,sw,se,sw,sw,s,sw,se,s,sw,sw,sw,se,sw,sw,sw,sw,s,sw,s,sw,s,sw,sw,ne,sw,sw,ne,sw,sw,s,sw,sw,sw,ne,sw,sw,sw,sw,se,se,sw,nw,sw,sw,nw,sw,nw,nw,sw,sw,sw,sw,nw,sw,nw,sw,sw,nw,sw,n,sw,nw,sw,s,s,se,nw,s,nw,sw,nw,nw,sw,nw,s,nw,se,s,sw,se,nw,nw,n,sw,sw,nw,sw,nw,nw,nw,ne,sw,ne,se,sw,sw,ne,nw,sw,nw,nw,nw,ne,nw,nw,sw,nw,sw,nw,sw,nw,nw,nw,nw,nw,ne,nw,nw,nw,nw,nw,nw,nw,ne,nw,nw,nw,nw,nw,nw,nw,ne,ne,nw,s,sw,nw,nw,nw,se,nw,se,se,nw,nw,nw,n,nw,nw,ne,nw,nw,nw,ne,nw,n,sw,nw,ne,nw,sw,nw,n,nw,s,nw,n,nw,nw,nw,nw,nw,n,n,sw,nw,nw,n,nw
@PamelaM
PamelaM / aoc_2017_day10.py
Created December 10, 2017 06:24
Advent of Code 2017, Day 10
INPUT = """165,1,255,31,87,52,24,113,0,91,148,254,158,2,73,153"""
import asciitree
from collections import OrderedDict, defaultdict
def _replace(data, position, chunk):
#print position, chunk
for idx, v in enumerate(chunk):
data[position+idx] = v
@PamelaM
PamelaM / aoc_2017_day9.py
Created December 9, 2017 20:10
Advent of Code 2017, Day 9
TESTSCORES = [
("{}", 1),
("{{{}}}", 6),
("{{},{}}", 5),
("{{{},{},{{}}}}", 16),
("{<a>,<a>,<a>,<a>}", 1),
("{{<ab>},{<ab>},{<ab>},{<ab>}}", 9),
("{{<!!>},{<!!>},{<!!>},{<!!>}}", 9),
("{{<a!>},{<a!>},{<a!>},{<ab>}}", 3),
]
@PamelaM
PamelaM / aoc_2017_day8.py
Created December 8, 2017 17:07
Advent of Code 2017, Day 8
TEST = """pb inc 5 if a > 1
a inc 1 if b < 5
c dec -10 if a >= 1
c inc -20 if c == 10"""
INPUT = """uz inc 134 if hx > -10
qin dec -300 if h <= 1
ubi inc 720 if qin <= 306
si inc -108 if he <= 1
hx inc 278 if hx <= -10
@PamelaM
PamelaM / aoc_2017_day7.py
Created December 7, 2017 22:08
Advent of Code 2017, day 7
TEST = """pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
qoyq (66)
padx (45) -> pbga, havc, qoyq
tknk (41) -> ugml, padx, fwft
jptl (61)