If you havent already done so, doing it in the form of binary search, the code completes in the blink of an eye (though on a high end cpu 11th Gen Intel® Core™ i7-11800H @ 2.30GHz). posted the code below
If you havent already done so, doing it in the form of binary search, the code completes in the blink of an eye (though on a high end cpu 11th Gen Intel® Core™ i7-11800H @ 2.30GHz). posted the code below
I feel like I need a Rosetta stone to read this code
It is a binary search
def parse_input(path):
with path.open("r") as fp:
lines = fp.read().splitlines()
roots = [int(line.split(':')[0]) for line in lines]
node_lists = [[int(x) for x in line.split(':')[1][1:].split(' ')] for line in lines]
return roots, node_lists
def construct_tree(root, nodes, include_concat):
levels = [[] for _ in range(len(nodes)+1)]
levels[0] = [(str(root), "")]
# level nodes are tuples of the form (val, operation) where both are str
# val can be numerical or empty string
# operation can be *, +, || or empty string
for indl, level in enumerate(levels[1:], start=1):
node = nodes[indl-1]
for elem in levels[indl-1]:
if elem[0]=='':
continue
if elem[0][-len(str(node)):] == str(node) and include_concat:
levels[indl].append((elem[0][:-len(str(node))], "||"))
if (a:=int(elem[0]))%(b:=int(node))==0:
levels[indl].append((str(int(a/b)), '*'))
if (a:=int(elem[0])) - (b:=int(node))>0:
levels[indl].append((str(a - b), "+"))
return levels[-1]
def solve_problem(file_name, include_concat):
roots, node_lists = parse_input(Path(cwd, file_name))
valid_roots = []
for root, nodes in zip(roots, node_lists):
top = construct_tree(root, nodes[::-1], include_concat)
if any((x[0]=='1' and x[1]=='*') or (x[0]=='0' and x[1]=='+') or
(x[0]=='' and x[1]=='||') for x in top):
valid_roots.append(root)
return sum(valid_roots)
I did a similar approach (place obstacles on guards path). Takes about 80s 10-15s in 11th Gen Intel® Core™ i7-11800H.
Motivated by the code above, I also restricted the search to start right before the obstacle rather than the whole path which took it down from 80s to 10-15s
Well also because he was likely just a pawn. at the root of all this are the shareholders who are billionaires and who likely make the calls regarding company policies. this guy was likely just their lapdog. so even though a rule of no more than 500mil would not deal with this guy, it would definitely have prevented the existence of a parasite company of this scale. I would still say though 50 mil should be sufficient. It will allow you almost all the reasonable luxuries you can imagine if that is your thing.
nice one thanks
sort using a compare function
from math import floor
from pathlib import Path
from functools import cmp_to_key
cwd = Path(__file__).parent
def parse_protocol(path):
with path.open("r") as fp:
data = fp.read().splitlines()
rules = data[:data.index('')]
page_to_rule = {r.split('|')[0]:[] for r in rules}
[page_to_rule[r.split('|')[0]].append(r.split('|')[1]) for r in rules]
updates = list(map(lambda x: x.split(','), data[data.index('')+1:]))
return page_to_rule, updates
def sort_pages(pages, page_to_rule):
compare_pages = lambda page1, page2:\
0 if page1 not in page_to_rule or page2 not in page_to_rule[page1] else -1
return sorted(pages, key = cmp_to_key(compare_pages))
def solve_problem(file_name, fix):
page_to_rule, updates = parse_protocol(Path(cwd, file_name))
to_print = [temp_p[int(floor(len(pages)/2))] for pages in updates
if (not fix and (temp_p:=pages) == sort_pages(pages, page_to_rule))
or (fix and (temp_p:=sort_pages(pages, page_to_rule)) != pages)]
return sum(map(int,to_print))
the perfect transportation does not e-
install doom on me
did he gorge on Caesar’s entrails
I feel like I shouldn’t have had to read half the article to get to this information. All they had to do was put the word “dead” in front of oak somewhere in the beginning. Fucking click baiters.
Eh imagine your loved one dying because some fuckwad billionaire, who dismissed modern medicine in favour of carrot juices, fucked him self up and then paid tons of money to get a liver which would only extend his life by a year.
Same story as the submarine guy, these people trust their own ideas so blindly they sometimes cant see the obvious. That is why they will easily blast the whole surface of earth flat if they think it is justified for some reason.
unfortunately it is an age of bullshit. they basically use bullshitting skills as the first level filter for job applications. the way people advertise their positions you would think you are applying for a job at google or sth.
no the correct answer is fuck off
wow for a solid ten seconds did not realize this was onion. I guess this will become more and more frequent over the next four years.
could? probably already is
thanks that indeed is a Rosetta stone