This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer