Skip to content

Instantly share code, notes, and snippets.

View d3banjan's full-sized avatar

Debanjan d3banjan

View GitHub Profile
@d3banjan
d3banjan / yaml_OrderedDict.py
Created October 22, 2018 11:02 — forked from oglops/yaml_OrderedDict.py
write to and load from yaml file with OrderedDict
#!/usr/bin/env python
try:
# for python newer than 2.7
from collections import OrderedDict
except ImportError:
# use backport from pypi
from ordereddict import OrderedDict
import yaml
curl -L "https://raw.githubusercontent.com/noSenseOfDangerous/PythonDesignPattern/master/factoryPattern_01/data/donut.json" -o donut.json
# % Total % Received % Xferd Average Speed Time Time Time Current
# Dload Upload Total Spent Left Speed
# 100 2895 100 2895 0 0 14532 0 --:--:-- --:--:-- --:--:-- 14547
ls -lh .
# total 4,0K
# -rw-r--r-- 1 debanjan debanjan 2,9K 12. Mär 15:02 donut.json
wc -l *
# 129 donut.json
jq '.' donut.json
@d3banjan
d3banjan / main.py
Created October 9, 2023 13:40
skyscraper puzzle
# Import required modules
from itertools import permutations, product, accumulate
from collections import defaultdict
import pprint
# Function to calculate the visibility score using differences between adjacent maximum heights
def visibility_score_with_diff(perm):
max_heights = list(accumulate(perm, func=max))
differences = [b - a for a, b in zip(max_heights[:-1], max_heights[1:])]
score = sum(diff != 0 for diff in differences) + 1