Skip to content

Instantly share code, notes, and snippets.

View luqmansen's full-sized avatar
🎯
Focusing

Luqman luqmansen

🎯
Focusing
View GitHub Profile
@luqmansen
luqmansen / aoc_2023_day_5_part_1.py
Created December 10, 2023 18:19
Advent of Code Day 5 part 1
from dataclasses import dataclass
from typing import List
@dataclass
class Mapping:
destination_range_start: int
source_range_start: int
range_length: int
def is_input_in_range(self, input_num) -> bool:
@luqmansen
luqmansen / aoc_2023_day_4_part_2.py
Last active December 10, 2023 17:08
advent of code day 4 part 2
from collections import defaultdict
from dataclasses import dataclass
from typing import List, Set
@dataclass
class Deck:
id: int
winning: Set[int]
mine: Set[int]
@dataclass
class Deck:
id: int
winning: Set[int]
mine: Set[int]
def count_point(self) -> int:
mine_winning = self.winning.intersection(self.mine)
num_of_match = len(mine_winning)
if num_of_match <= 1:
@luqmansen
luqmansen / aoc_2023_day_3_part_2.py
Created December 5, 2023 16:40
Advent of code day 3 part 2
@dataclass
class PartNumber:
id: int
value: int
def __hash__(self):
return self.id
_part_number_id = 1
from dataclasses import dataclass
from typing import Dict, Set
@dataclass
class PartNumber:
id: int
value: int
def __hash__(self):
@luqmansen
luqmansen / aoc_2023_day_2.py
Created December 4, 2023 13:31
advent of code 2023 day 2
@dataclass
class GameSet:
red: int = 0
green: int = 0
blue: int = 0
def match_rule(self, rule: 'GameSet'):
if any([
self.blue > rule.blue,
@luqmansen
luqmansen / aoc_2023_day_1.py
Last active December 5, 2023 16:11
Advent of code 2023
# https://adventofcode.com/2023/day/1
# get full input at https://adventofcode.com/2023/day/1/input
if __name__ == '__main__':
per_line = _input.split('\n')
total = 0
for line in per_line:
print(f'line: {line}')
@luqmansen
luqmansen / mission_1.py
Last active December 11, 2023 09:13
mission_1
def collect_cases(stack, test_case_num):
if test_case_num <= 0:
return
num_of_inputs = input()
actual_input = input()
stack.append((num_of_inputs, actual_input))
collect_cases(stack, test_case_num - 1)
@luqmansen
luqmansen / dependency_graph.py
Last active September 1, 2023 06:19
Generate Django Application Dependency Graph
import ast
import os
from random import randrange
from graphviz import Digraph
def random_color():
r = randrange(255)
g = randrange(start=0, stop=10)
@luqmansen
luqmansen / bench_test.go
Created July 21, 2022 03:39
Testing some concurrent map locking mechanism
package caskdb
import (
"github.com/cornelk/hashmap"
"math"
"sync"
"testing"
)
type m struct {