Adventní kalendář

kutr

Adventní kalendář
« kdy: 16. 12. 2017, 00:12:08 »
Ve fóru o programování se tady objevují solidní nesmysly o najímání lidí, znalostech programátorů apod., tak bych to chtěl aspoň na vánoce oživit pozitivně a poslat to zase zpátky k podstatě věci. Otvíráte adventní kalendář http://adventofcode.com/2017? Pokud ano, které úlohy vás nejvíc zabavili a co bylo těžké, pochopit nebo implementovat? Zkoušeli jste to v jazyku co neznáte nebo jste vsadili na jistotu?

Za sebe můžu říct, že mám všechno a zkusil jsem to v rustu. Zatím nejtěžší byla určitě úloha 7, druhá část, hlavně pochopit, co vlastně mám odevzdat. Nejvíc mě bavila úloha 10 druhá část. Takhle vymakaně by měli vypadat všechny programátorské soutěže.

Poslední, nejspíš zbytečný dotaz: Zvládnul to někdo z vás do první stovky v hodnocení?


pepa489

Re:Adventní kalendář
« Odpověď #1 kdy: 16. 12. 2017, 16:51:41 »
Ano, taky řeším v rustu a souhlasím, 7 úloha, 2 část byla asi nejtěžší. Nikdy jsem se dostat leaderboardu nesnažil

gll

Re:Adventní kalendář
« Odpověď #2 kdy: 16. 12. 2017, 17:27:27 »
Podle názvu vlákna není poznat, že se týká programování. Určitě to zkusím.

#

Re:Adventní kalendář
« Odpověď #3 kdy: 16. 12. 2017, 20:29:43 »
Kalendar otevrima kazdej den, zatim me nic neprekvapilo :) - https://www.masterofmalt.com/rum/drinks-by-the-dram/rum-advent-calendar/

gll

Re:Adventní kalendář
« Odpověď #4 kdy: 16. 12. 2017, 20:35:04 »
7 neni tezka, jen ma trochu matouci zadani obsahujici nadbytecne informace (vaha).

moje reseni

Kód: [Vybrat]
def a_7(input):
    all_children = []
    parents = []
    for line in input:
res = re.match(r'([a-z]+).*-> ([a-z\s,]+)',
                       line.strip())
        if res:
            name, children = res.groups()
            children = re.split(r', ', children)
            all_children += children
            parents.append(name)
    root = set(parents) - set(all_children)
    return list(root)[0]


gll

Re:Adventní kalendář
« Odpověď #5 kdy: 23. 12. 2017, 12:46:02 »
mělo to 2 části.

Kód: [Vybrat]
def parse_line(line):
    reg1 = r'([a-z]+) \(([0-9]+)\)'
    reg2 = r' -> ([a-z\s,]+)'
    res = re.match(reg1 + reg2, line)
    if res:
        children = re.split(r', ', res.group(3))
    else:
        res = re.match(reg1, line)
        children = []
    return res.group(1), int(res.group(2)), children


def root(parents, children):
    return list(set(parents) - set(children))[0]


def process_input(input):
    return zip(*list(map(parse_line, input)))


def a_7_part1(input):
    names, _, children = process_input(input)
    return root(names, sum(children, []))


def catch_e(exception, func, *args):
    try:
        func(*args)
    except exception as e:
        return e.args[0]


def a_7_part2(input):
    names, weights, children = process_input(input)
    weights = dict(zip(names, weights))
    tree = dict(zip(names, children))

    def walk(node):
        children = tree[node]
        sums = list(map(walk, children))
        counts = Counter(sums)
        if len(counts) > 1:
            (w1, _), (w2, _) = counts.most_common(2)
            wrong_w = weights[children[sums.index(w2)]]
            raise ValueError(wrong_w + w1 - w2)
        return weights[node] + sum(sums)

    return catch_e(ValueError, walk, root(names, sum(children, [])))

chtěl bych vidět vaše řešení.

jenda

Re:Adventní kalendář
« Odpověď #6 kdy: 23. 12. 2017, 23:23:26 »
Kód: [Vybrat]
inLines = input1.splitlines()
inp = dict()
for l in inLines:
  rep = l.replace(',','').split()
  inp.update({rep[0]:rep[1:]})
# if the len value > 2 => has links
# shall be enough to go through all links and find the one not present
res=set(inp.keys())
for t in inp:
  x=inp[t]
  if len(x)>2:
    for q in x[2:]:
      if q in res: res.remove(q)
print(res)