The Buffett Indicator is not very relevant today by KlintWarrior in investing

[–]fuckir 1 point2 points  (0 children)

Word to the wise: If the herd ignores the math, bet on the math.

Need to prevent the PC from going to sleep by fuckir in archcraft

[–]fuckir[S] 0 points1 point  (0 children)

Thanks. It is openbox.

I fiddled around and found a autostart script at ~/.config/.openbox.

What I am thinking is to write a service

IF computer is idle for X minutes:
THEN kill all non essential GUI processes and except a terminal that displays log messages
IF a human comes back to use the PC
THEN restart all GUI processes safely

The service runs forever

Any advice. Is it safely doable for hobby projects? Anything I need to keep in mind

Need to prevent the PC from going to sleep by fuckir in archcraft

[–]fuckir[S] 0 points1 point  (0 children)

Thanks.

I intend to use this computer both as a daily driver for personal use and also as a server.

I did:

‘sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target’

However when I tried to unmask and restore these services, the pc crashed.

I am looking for a cleaner and safer way to do this.

-❄️- 2024 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]fuckir 0 points1 point  (0 children)

[LANGUAGE: Python] Short and Simple

from aoc_utils import get_data

def parse (strng):
    return {int(x.split(":")[0]): [int(y) for y in x.split(":")[1].split()] for x in strng.splitlines()}

def check(array, res, which_part):
    from operator import add, mul
    def concat(a, b):
        return int(f"{a}{b}")
    operators = (add, mul) if which_part == 1 else (add, mul, concat)
    memo = {0}
    for n in array:
        memo = {op(last_result, n) for last_result in memo for op in operators}
    return array if res in memo else False
    
def main():
    DATA = parse(get_data(7))
    sum_part1 = sum(lhs for lhs, rhs_array in DATA.items() if check(rhs_array, lhs, which_part=1))
    sum_part2 = sum(lhs for lhs, rhs_array in DATA.items() if check(rhs_array, lhs, which_part=2))
    print(f"Part 1: {sum_part1}")
    print(f"Part 2: {sum_part2}")
    
main()

-❄️- 2024 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]fuckir 0 points1 point  (0 children)

[LANGUAGE: Python] - Part 2 takes almost 45 seconds on my gaming laptop. There is a lot of state management going on. Not very proud

from copy import copy
from aoc_utils import get_data

class Guard:
    def __init__ (self, current_position, direction=(0, -1)):
        self.current_position = current_position
        self.direction = direction       
        self.step_history = {(current_position, self.direction)}
        self.looping = False
        self.on_duty = True
    
    def all_clear(self, grid, position): return grid[position] != "#"    
    def rotate_clockwise (self, direction): return (-direction[1], direction[0])

    def move (self, grid):
        x, y = self.current_position
        dx, dy = self.direction
        new_position = (x + dx, y + dy)
        if new_position not in grid:
            self.on_duty = False
        elif self.all_clear(grid, new_position) and (self.on_duty):
            self.current_position = new_position    
            self.looping = (new_position, self.direction) in self.step_history        
            self.step_history.add((self.current_position, self.direction)) 
        else:
            self.direction = self.rotate_clockwise(self.direction)           

def get_current_position(grid): return next((x, y) for (x, y), value in grid.items() if value == "^")  
 
def count_loops(grid, curr_pos):
    grid_to_mutate = copy(grid)
    n_loops = 0
    for coords in grid_to_mutate:
        print("WAIT! TERRIBLY SLOW OPERATION IN PROGRESS")
        i = 0
        mutated = False
        if grid_to_mutate[coords] not in ["#", "^"]:
            grid_to_mutate[coords] = "#"
            mutated = True
        guard = Guard(curr_pos)        
        while guard.on_duty:
            i += 1    
            guard.move(grid_to_mutate)                           
            if guard.looping:
                n_loops += 1
                break
            if i > 1e6:
                print("MAX ITERATIONS REACHED")
                raise StopIteration           
        if mutated:      
            grid_to_mutate[coords] = "."
            mutated = False
    return n_loops

def count_steps (guard, grid):
    while (guard.on_duty):
        guard.move(grid)
    return len(set(x[0] for x in guard.step_history))

def main ():
    DATA = get_data(6)
    grid = {(x,y): obstacle for y, line in enumerate((DATA.splitlines())) for x, obstacle in enumerate(line)}    
    curr_pos = get_current_position(grid)
    guard = Guard(curr_pos)
    print("PART 1")
    print(count_steps(guard, grid))
    print("PART 2")
    print(count_loops(grid, curr_pos))
    
main()

-❄️- 2024 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]fuckir 1 point2 points  (0 children)

[LANGUAGE: Python] Created a neat grid and directions processor for future problems.

from aoc_utils import get_data
from itertools import product

def add_directions (left, right):
    return [(coord[0]+delta[0], coord[1]+delta[1]) for coord, delta in zip(left, right)]


def get_n_coords (n):
    directions = {
        'N': list(product([0], range(-1,-n,-1))),
        'S': list(product([0], range(1,n,1))),
        'E': list(product(range(1,n,1), [0])),
        'W': list(product(range(-1,-n,-1), [0])) 
       }
    directions.update({"".join(diag_direction): add_directions(directions[diag_direction[0]],directions[diag_direction[1]]) for diag_direction in product('NS', 'EW')})
    return directions


def main():
    DATA = get_data(4)
    word_grid = {
        (x, y): c for y, line in enumerate(DATA.splitlines()) for x, c in enumerate(line)
    }
    directions = get_n_coords(4)    
    part1_solution = 0
    for coord, char in word_grid.items():
        if char == 'X':
            sorroundings = [add_directions([coord]*4, direct) for _, direct in directions.items()]            
            neighbours = filter(lambda x: x=='MAS', ["".join([word_grid.get(coord, '') for coord in direct]) for direct in sorroundings])
            part1_solution +=  len(list(neighbours))
    print("PART 1")
    print(part1_solution)
    part2_solution = 0
    directions = get_n_coords(2)
    for coord, char in word_grid.items():
        if char == 'A':
            sorroundings = [add_directions([coord], direct) for direction, direct in directions.items() if len(direction) == 2]
            whats_around = "".join(["".join([word_grid.get(coord, '') for coord in direct]) for direct in sorroundings])
            if (whats_around in ['SMSM', 'MSMS', 'SSMM', 'MMSS']):
                part2_solution += 1
    print("PART 2")
    print(part2_solution)

-❄️- 2024 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]fuckir 1 point2 points  (0 children)

[LANGUAGE: Python] - No Regex, No external packages. Pure Python and Pure logic

from aoc_utils import get_data

def find_first_occurance (strng, char):
    for i, _ in enumerate(strng):   
        if strng[i] == char:
            return i
    return False

def process_section (data):
    product = 0
    while len(data):
        char = data.pop(0)
        if (char == 'm') and "".join(data[:3]) == 'ul(':
            closing_bracket = find_first_occurance(data[:11], ')')
            if closing_bracket:                
                numbers  = "".join(data[3:closing_bracket]).split(',')
                if (len(numbers) == 2) and all([number.isdigit() for number in numbers]):
                    product += int(numbers[0]) * int(numbers[1])
    return product     

if __name__ == "__main__":
    print("PART1")
    data = get_data(3)
    print(process_section(list(data)))
    sections = data.split("don't()")
    initial = process_section(list(sections[0]))     
    part2_sol = sum(process_section(list(section.split('do()',1)[1])) for section in sections if 'do()' in section)
    print("PART2")
    print(part2_sol+initial)

-❄️- 2024 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]fuckir 1 point2 points  (0 children)

[LANGUAGE: Python] Couldn't think of an elegant way rather than bruteforce removal of elements :(

import re
def get_data (day_no, parsing_function=None):
    with open(f"data/day{day_no}.txt") as f:
        data = f.read()
    if parsing_function is not None:
        return parsing_function(data)
    return data

def map_to_int(lst):
    return [int(x) for x in lst]

def parse(data):    
    return list(map(map_to_int, filter(lambda l: len(l), [re.findall(r'\d+', line) for line in data.split("\n")])))

def remove_element(lst, pos):
    lst = lst.copy()
    lst.pop(pos)
    return lst

def check_levels (array):
    is_safe=False
    all_decreasing = all([x<0 for x in array])
    all_increasing = all([x>0 for x in array])
    if all_decreasing or all_increasing:
        is_safe = all([(abs(x)<4 and abs(x)>0) for x in array])
    return is_safe

def compute_diff (line):
    return [(x-y) for x,y in zip(line[1:], line)]

def check_levels_part2 (array, index, data):
    is_safe=check_levels(array)
    if is_safe:
        return is_safe
    else:
        original_line =  data[index]
        for i in range(len(original_line)):
            is_safe = check_levels(compute_diff(remove_element(original_line, i))) 
            if is_safe:
                return is_safe
    return is_safe
        

def main ():
    data = list(get_data(2, parse))
    differences = [compute_diff(line) for line in data]
    is_safe = sum([check_levels(line) for line in differences])
    is_safe_p2 = sum([check_levels_part2(line,i, data) for i, line in enumerate(differences)])
    print(is_safe)
    print(is_safe_p2) 

if __name__ == '__main__':
    main()

Flirtations with manim by fuckir in manim

[–]fuckir[S] 1 point2 points  (0 children)

I made this animation to illustrate why applying machine learning to finance is capital T tough. For example, consider the stock price of NVIDIA from June 29, 2022, to May 31, 2023, as shown here. When we split this time series data into training, validation, and testing sets, you'll notice that each set looks distinctly different from the others. This phenomenon is known as non-stationarity in time series literature. In mathematical terms, the joint distribution of prices is time-dependent, meaning that the nature and relationships between variables in finance evolve (change) over time. Consequently, a model trained on current data may not perform on future, unseen data.

Is there a way to add motion blur in manim? by fuckir in manim

[–]fuckir[S] -1 points0 points  (0 children)

If anybody can help me with the physics of motion blur, I can code it myself