blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
2bd770434ad0736854c1dc0d812de658a885a2e8 | pm-twice/procon | /AtCoder/ABC/126/B.py | 303 | 3.640625 | 4 | #-*- coding:utf-8 -*-
S = input()
s1 = S[:2]
s2 = S[2:]
i1 = int(s1)
i2 = int(s2)
YYMM = False
MMYY = False
if 1 <= i1 <= 12:
MMYY = True
if 1 <= i2 <= 12:
YYMM = True
if YYMM and MMYY:
print("AMBIGUOUS")
elif YYMM:
print("YYMM")
elif MMYY:
print("MMYY")
else:
print("NA")
|
ffb4c6e1c6663d862e94ff9a13b1609174839552 | pm-twice/procon | /AtCoder/ABC/122/D.py | 2,153 | 3.578125 | 4 | # -*- coding: utf-8 -*-
N = int(input())
# 4^100 ≒1.61*10^60
# 全探索はまず不可能。N=3の場合から漸化式?いまいち規則性が分からん
# N文字の場合、ATCGの4通りで4**N通りの文字列
# 1. この時、"AGC"を含まない
# 2. 隣接2文字の入れ替えで"AGC"にならない
# つまり、"GAC", "ACG"を含むのもアウト
# "AxGC", "AGxC"もアウト
# N-1における上記を満たす文字数をf(N-1)とすると
# 先頭がGC, AC, CGの場合にA,G,Aを置くのがアウト
# また、先頭がxGCの場合(TGC, GGC)もAを置... |
5f5eeaecbe8f3e25a975039289917108585b2862 | pm-twice/procon | /AtCoder/ABC/122/A.py | 173 | 3.71875 | 4 | # -*- coding: utf-8 -*-
b = input()
ret = ""
if b == "A":
ret = "T"
elif b == "T":
ret = "A"
elif b == "C":
ret = "G"
elif b == "G":
ret = "C"
print(ret)
|
feb1ad544c5aeb23bc1b4262b4117de9a95e75fc | mheen/io_beaching | /plot_tools/plot_cycler.py | 1,677 | 3.546875 | 4 | import matplotlib.pyplot as plt
from matplotlib.widgets import Button
from matplotlib.figure import Figure
from typing import Callable, TypeVar, List
T = TypeVar("T")
def example():
def plot(fig: Figure, a: int):
formule = lambda x: a*x
ax = fig.gca()
ax.set_title("a =" + str(a))
... |
341fba26b9fc34aff5da08ac112a8e8ac17072a6 | GordonYuanyc/4428 | /risk_project.py | 3,182 | 4.21875 | 4 | import math
import random
# a function that can generate a series of time in poisson process... I hope so...
def nextTime(rateParameter):
return -math.log(1.0 - random.random()) / rateParameter
def calculate_remaining_customer(cust_num,rate,time):
return int(cust_num * (1 - math.exp(-rate*time)))
def check_b... |
eca5f085e999092ef22f2924804b3776ceb9d928 | AFAIKRitwik/Evolutionary-Algorithms | /Knapsack.py | 5,836 | 4.21875 | 4 | # Evolutionary approach to solve the 0/1 knapsack problem
'''
AIM OF EA: EVOLVE EACH CANDIDATE TO BECOME A VALID SOLUTION
Each object is represented as a list of 3 values. [item_no, weight, value,True]
objlist = list of objects
the knapsack is considered as the chromosome
knapsack = actual final knapsack. represented ... |
13932432f00caf9a14c5999e04fae77e4dacff24 | nycynik/advent2020 | /day12/solve.py | 4,975 | 3.65625 | 4 | from math import cos, sin, pi, radians, degrees
def get_data():
data = []
data_file = open("data.txt")
for val in data_file:
data.append(val.strip())
data_file.close()
print(f"read {len(data)} lines\n")
return data
def check_data(data):
# n=0/360, w=270, e=90, s=180
# ar... |
c4c12819874eb2e4950b2d94d694e210ce8ea684 | k-harada/AtCoder | /ABC/ABC201-250/ABC212/A.py | 425 | 3.6875 | 4 | def solve(a, b):
if a == 0:
return "Silver"
elif b == 0:
return "Gold"
else:
return "Alloy"
def main():
a, b = map(int, input().split())
res = solve(a, b)
print(res)
def test():
assert solve(50, 50) == "Alloy"
assert solve(100, 0) == "Gold"
assert solve(0,... |
932234249b0a86ee662f793a964c58a837928378 | k-harada/AtCoder | /ABC/ABC251-300/ABC280/A.py | 419 | 3.5625 | 4 | def solve(h, w, s):
res = 0
for row in s:
res += row.count("#")
return res
def main():
h, w = map(int, input().split())
s = [input() for _ in range(h)]
res = solve(h, w, s)
print(res)
def test():
assert solve(3, 5, [
"#....",
".....",
".##.."
]) ==... |
94b987ec4b339a01bd50305e770e33625a279936 | k-harada/AtCoder | /ABC/ABC201-250/ABC216/B.py | 653 | 3.5 | 4 | def solve(n, st_list):
name_list = [s + "-" + t for s, t in st_list]
if len(set(name_list)) < n:
return "Yes"
else:
return "No"
def main():
n = int(input())
st_list = [tuple(input().split()) for _ in range(n)]
res = solve(n, st_list)
print(res)
def test():
assert solv... |
b93d08b18f5ceb5aa79a42a8b1feab147b1531c3 | k-harada/AtCoder | /ABC/ABC101-150/ABC114/A.py | 279 | 3.671875 | 4 | def solve(x):
if x in [3, 5, 7]:
return "YES"
else:
return "NO"
def main():
x = int(input())
res = solve(x)
print(res)
def test():
assert solve(5) == "YES"
assert solve(6) == "NO"
if __name__ == "__main__":
test()
main()
|
c29dea5b3c0c71a1923c736793806112bc3caa16 | k-harada/AtCoder | /ABC/ABC151-200/ABC171/E.py | 485 | 3.53125 | 4 | def solve(n, a_list):
s = 0
for i in range(n):
a = a_list[i]
s = s ^ a
res_list = []
for i in range(n):
a = a_list[i]
res_list.append(str(s ^ a))
# print(res_list)
return " ".join(res_list)
def main():
n = int(input())
a_list = list(map(int, input().spli... |
5b17b87bda9b1239ad3e75e84b6e186382f0de15 | k-harada/AtCoder | /ABC/ABC151-200/ABC155/A.py | 1,083 | 3.546875 | 4 | import sys
TEST_INPUT = [
"""
5 7 5
""",
"""
4 4 4
""",
"""
4 9 6
""",
"""
3 3 4
"""
]
ANSWER = [
"Yes",
"No",
"No",
"Yes"
]
class InputHandler:
def __init__(self, text_lines="", is_test=False):
self.data = list(text_lines.split("\n"))
... |
c9670b03bbfc41417cef889aa2b2cb558b40dc26 | k-harada/AtCoder | /ABC/ABC201-250/ABC218/A.py | 324 | 3.671875 | 4 | def solve(n, s):
if s[n - 1] == "o":
return "Yes"
else:
return "No"
def main():
n = int(input())
s = input()
res = solve(n, s)
print(res)
def test():
assert solve(4, "oooxoox") == "No"
assert solve(7, "ooooooo") == "Yes"
if __name__ == "__main__":
test()
mai... |
6be7cbfeddea99ca4e104612246ca5791607a2bd | k-harada/AtCoder | /other_contests/PAST202004/C.py | 1,082 | 3.5 | 4 | def solve(n, s_list):
res_list = [[] for _ in range(n)]
res_list[n - 1] = list(s_list[-1])
for i in range(n - 2, -1, -1):
res_list[i].append(".")
for j in range(1, 2 * n - 2):
if s_list[i][j] == "#":
if res_list[i + 1][j - 1] == "X" or res_list[i + 1][j] == "X" or... |
77b1f4f06866e50e053200f4cd7e39c290ee7535 | k-harada/AtCoder | /ABC/ABC151-200/ABC161/F.py | 1,180 | 3.53125 | 4 | import math
def solve(n):
if n == 2:
return 1
res = 0
# divisor of n - 1
m = int(math.sqrt(n - 1))
for i in range(2, m + 1):
if (n - 1) % i == 0:
res += 2
if m * m == n - 1:
res -= 1
res += 1
# divisor of n
# n itself
res += 1
divisors ... |
5aa3cd9afe2ac833f8d146a39266e8a296445878 | k-harada/AtCoder | /ABC/ABC251-300/ABC289/B.py | 651 | 3.671875 | 4 | def solve(n, m, a_list):
res = []
temp = []
for p in range(1, n + 1):
if p in a_list:
temp.append(p)
else:
res.append(p)
while len(temp):
res.append(temp.pop())
return " ".join([str(i) for i in res])
def main():
n, m = map(int, in... |
9d7840fddc9d465b70a1f16a3374ed2fb1ada8b3 | k-harada/AtCoder | /ABC/ABC151-200/ABC187/C.py | 710 | 3.625 | 4 | def solve(n, s_list):
s_list_0 = [s for s in s_list if s[0] != "!"]
s_list_1 = [s[1:] for s in s_list if s[0] == "!"]
set_0 = set(s_list_0)
set_1 = set(s_list_1)
list_intersect = list(set_0.intersection(set_1))
if len(list_intersect) == 0:
return "satisfiable"
else:
return li... |
aa136de51141496d9c9a6da37f0cdbb6299592f1 | k-harada/AtCoder | /marathon/genocon2021/A.py | 679 | 3.59375 | 4 | DUAL_DICT = {"A": "T", "T": "A", "C": "G", "G": "C"}
def solve(m, s_list):
res_list = []
for s in s_list:
t = "".join([DUAL_DICT[c] for c in reversed(s)])
res_list.append(t)
return res_list
def main():
m = int(input())
s_list = [input() for _ in range(m)]
res_list = solve(m, ... |
93c001bb8063a18367053fd1db997d59f0ac0bbc | k-harada/AtCoder | /marathon/HTTF2021/unit_test.py | 1,098 | 3.84375 | 4 | import numpy as np
def min_path(board, x, y):
"""
:param board: np.array
:param x: 開始地点
:param y: 開始地点
:return: 追加すべき点のlist
"""
r, c = board.shape
d_min = r + c
i_min = 0
j_min = 0
for i in range(r):
for j in range(c):
if board[i, j] == 0:
... |
22929386efe5d1ea5fb2b0a7b07e494858d54975 | k-harada/AtCoder | /ABC/ABC151-200/ABC171/A.py | 272 | 3.671875 | 4 | def solve(s):
if s.upper() == s:
return "A"
else:
return "a"
def main():
s = input()
res = solve(s)
print(res)
def test():
assert solve("B") == "A"
assert solve("a") == "a"
if __name__ == "__main__":
test()
main()
|
3ec13da625459464ee2ae47e833d7604a1867c0e | k-harada/AtCoder | /ABC/ABC201-250/ABC240/A.py | 372 | 3.734375 | 4 | def solve(a, b):
if a + 1 == b:
return "Yes"
elif a == 1 and b == 10:
return "Yes"
return "No"
def main():
a, b = map(int, input().split())
res = solve(a, b)
print(res)
def test():
assert solve(4, 5) == "Yes"
assert solve(3, 5) == "No"
assert solve(1, 10) == "Yes"... |
15c536d0414922b65d71a5266cc887d954c38f94 | k-harada/AtCoder | /ABC/ABC201-250/ABC208/A.py | 346 | 3.640625 | 4 | def solve(a, b):
if a <= b <= 6 * a:
return "Yes"
else:
return "No"
def main():
a, b = map(int, input().split())
res = solve(a, b)
print(res)
def test():
assert solve(2, 11) == "Yes"
assert solve(2, 13) == "No"
assert solve(100, 600) == "Yes"
if __name__ == "__main_... |
1a418b7d3423ae0fc46d8035e34bf3a9e3e2c7ac | k-harada/AtCoder | /ABC/ABC201-250/ABC216/A.py | 410 | 3.65625 | 4 | def solve(xy):
x, y = map(int, xy.split("."))
if 0 <= y <= 2:
return str(x) + "-"
elif 3 <= y <= 6:
return str(x)
else:
return str(x) + "+"
def main():
xy = input()
res = solve(xy)
print(res)
def test():
assert solve("15.8") == "15+"
assert solve("1.0") ==... |
768e47b31703504334d0bdedede2234af09528a8 | k-harada/AtCoder | /ABC/ABC151-200/ABC195/A.py | 309 | 3.625 | 4 | def solve(m, h):
if h % m == 0:
return "Yes"
else:
return "No"
def main():
m, h = map(int, input().split())
res = solve(m, h)
print(res)
def test():
assert solve(10, 120) == "Yes"
assert solve(10, 125) == "No"
if __name__ == "__main__":
test()
main()
|
c8febcb8b836cdfd3e3d748aa2d7a350b615f3f0 | k-harada/AtCoder | /ABC/ABC201-250/ABC217/E.py | 953 | 3.546875 | 4 | from heapq import heappush, heappop
from collections import deque
def solve(q, query_list):
h = []
queue = deque()
res_list = []
for query in query_list:
if query[0] == 1:
queue.append(query[1])
elif query[0] == 2:
if len(h):
res_list.append(heap... |
4967a6bab9c618002dab8e34ac442c1dc07faf33 | k-harada/AtCoder | /ABC/ABC306/A.py | 338 | 3.796875 | 4 | def solve(n, s):
res = ""
for i in range(n):
res += s[i] * 2
return res
def main():
n = int(input())
s = input()
res = solve(n, s)
print(res)
def test():
assert solve(8, "beginner") == "bbeeggiinnnneerr"
assert solve(3, "aaa") == "aaaaaa"
if __name__ == "__main__":
... |
0ab51960a274efbfdac3841470582bc444b88b38 | k-harada/AtCoder | /other_contests/PAST2019/C.py | 373 | 3.5 | 4 | def solve(abc6):
abc6_s = list(sorted(abc6))
return abc6_s[3]
def main():
abc6 = list(map(int, input().split()))
res = solve(abc6)
print(res)
def test():
assert solve([4, 18, 25, 20, 9, 13]) == 18
assert solve([95, 96, 97, 98, 99, 100]) == 98
assert solve([19, 92, 3, 35, 78, 1]) == 3... |
43efb1d6fdd231f75f76220eb88cf56c13e83cff | k-harada/AtCoder | /ABC/ABC151-200/ABC162/A.py | 319 | 3.671875 | 4 | def solve(n):
if "7" in list(str(n)):
return "Yes"
else:
return "No"
def main():
n = int(input())
res = solve(n)
print(res)
def test():
assert solve(117) == "Yes"
assert solve(123) == "No"
assert solve(777) == "Yes"
if __name__ == "__main__":
test()
main()
|
dbb47589e39645a2dd66662480e2b3bd8f582cb3 | k-harada/AtCoder | /ABC/ABC201-250/ABC211/A.py | 308 | 3.546875 | 4 | def solve(a, b):
return (a - b) / 3 + b
def main():
a, b = map(int, input().split())
res = solve(a, b)
print(res)
def test():
assert solve(130, 100) == 110
assert solve(300, 50) == 133.3333333
assert solve(123, 123) == 123
if __name__ == "__main__":
# test()
main()
|
9f5952879d0b5b8f6b4a4293fe783b625eb4602d | k-harada/AtCoder | /other_contests/PAST202004/B.py | 460 | 3.65625 | 4 | def solve(s):
a = s.count("a")
b = s.count("b")
c = s.count("c")
m = max(a, b, c)
if a == m:
return "a"
elif b == m:
return "b"
else:
return "c"
def main():
s = input()
res = solve(s)
print(res)
def test():
assert solve("abbc") == "b"
assert so... |
d0bf919ae4878def8b136ba40ca1b6f70ce9ec7a | k-harada/AtCoder | /ABC/ABC151-200/ABC162/C.py | 421 | 3.515625 | 4 | import math
def solve(k):
res = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
d = math.gcd(a, b)
for c in range(1, k + 1):
res += math.gcd(c, d)
return res
def main():
k = int(input())
res = solve(k)
print(res)
def test():
assert ... |
249c0e105a1d822dded29eb06e2920ca658936dd | k-harada/AtCoder | /ABC/ABC151-200/ABC176/B.py | 459 | 3.828125 | 4 | def solve(ns):
d = 0
for s in ns:
d += int(s)
d %= 9
if d == 0:
return 'Yes'
else:
return 'No'
def main():
ns = input()
res = solve(ns)
print(res)
def test():
assert solve("123456789") == 'Yes'
assert solve("0") == 'Yes'
assert solve("314159265... |
25371c077a7c601f0d7e0098aa3c010c472f0599 | DivijeshVarma/ChoiceGame | /ChoiceGame.py | 2,087 | 4 | 4 | # python Game
print("Welcome to Game")
name = input("What is your Name? ")
age = int(input("What is your Age? "))
points = 20
if age >= 18:
# weapon = input("To play the game choose weapon (axe/hammer): ")
print("You entered Game with 20 points")
choice = input("make a choice left or right (left/right):... |
581d5b2737d09f0fc13fb9f4fe9d635fcb76651e | tpurnachander/hello-world | /prime_num_list.py | 410 | 4.21875 | 4 | prime_list = [2]
limit = int(input("Enter a limit : "))
for num in range(3,limit):
#print(" Iterating number is %s"%num)
if num <= limit:
for i in range(2,num):
if (num % i) == 0:
print("%s is not a prime number"%num)
break
elif num-i == 1 and (num % i) != 0:
print(" %s is pr... |
5d5516d102d0c59527b00d00570821516956844c | HarshitaVP/Machine-Learning-Internship | /INFIDATA MACHINE LEARNING - colab notebooks/INFIDATA MACHINE LEARNING/prodlist.py | 776 | 3.90625 | 4 | class product():
def __init__(self,name,manufacturer,price):
self.name = name
self.manufacturer = manufacturer
self.price = price
def info(self):
print("Name ",self.name," manufacturer ".self.manufacturer,
" price ",self.price)
prodlist = []
total = 0
... |
60f1f49a03137547d866a1052a058b620985a05d | technofreak98/HeartDiseasePrediction | /prediction.py | 2,016 | 3.59375 | 4 | # Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('data.csv')
X = dataset.iloc[:, 0:9].values
y = dataset.iloc[:, 9].values
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values = 'NaN', strategy = 'mean',... |
76c8226d506bac1df18a78db04b6a59715ed0e75 | cmgospod/Computer-Architecture | /ls8/cpu.py | 4,347 | 3.71875 | 4 | """CPU functionality."""
import sys
class CPU:
"""Main CPU class."""
def __init__(self, filename):
"""Construct a new CPU."""
self.reg = [0] * 256
self.ram = [0] * 128
self.filename = filename
self.stack_pointer = 0xF4
self.flags = [0] * 8
def load(self):
... |
7c1bc9e4ad25ada066ef51b936c3a72333bf2f9f | mldmort/TF | /MNIST/mnist_train.py | 2,646 | 3.671875 | 4 | from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
def main():
# import data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
# ======================================
# looking into the data
#print (mnist.train.images[0])
#print (mnist.train.labels[0])
... |
b0f0c2a908680e81fdcd0740f99696e5f9d194b2 | bhatnagaranshika02/Regex | /Prog1.py | 121 | 4.21875 | 4 | import re
word = input("Enter a string: ")
found = re.search(r'e',word)
if found:
print('yes')
else:
print('No')
|
d918e2597f1c5dd70c2b49adf7b02de42df1e75b | chasecolford/Leetcode | /problems/298.py | 1,448 | 3.921875 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def longestConsecutive(self, root: TreeNode) -> int:
"""
we can dfs, and always return the l... |
2c187430158966ee2783416b5c1e8e8fb732e9cf | chasecolford/Leetcode | /problems/100.py | 860 | 3.8125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
# if both nodes are null at the sam... |
75f3a4d02877160ad961ceaed6c07af27d8878c3 | chasecolford/Leetcode | /problems/101.py | 838 | 4.375 | 4 | """
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left ... |
d62be56ef086e9e99f5f15c4365833e0853bb7b8 | chasecolford/Leetcode | /problems/350.py | 567 | 3.734375 | 4 | """
Given two arrays, write a function to compute their intersection.
"""
# class Solution:
# def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
# # bruteforce
# res = []
# for i in nums1:
# if i in nums2:
# nums2.remove(i)
# res... |
8e7dde52257ab9fcabb552a02628222e63520b34 | chasecolford/Leetcode | /problems/300.py | 4,324 | 4.46875 | 4 | """
faster version: based on the following but with the addition of binary search
Approach 2: Intelligently Build a Subsequence
Intuition
As stated in the previous approach, the difficult part of this problem is deciding if an
element is worth using or not. Consider the example nums = [8, 1, 6, 2, 3, 10]. Let's try ... |
c0015ba1ced68a51c965257724ddfcabaec81c0a | chasecolford/Leetcode | /problems/746.py | 902 | 4.25 | 4 | """
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
Once you pay the cost, you can either climb one or two steps.
You need to find minimum cost to reach the top of the floor,
and you can either start from the step with index 0, or the step with index 1.
"""
#NOTE: we can star... |
8922d015e107fe3e3f452a5c38768bc2678a717c | chasecolford/Leetcode | /problems/1880.py | 255 | 3.53125 | 4 | class Solution:
def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:
value = lambda word : int(''.join([str(ord(char) - 97) for char in word]))
return value(firstWord) + value(secondWord) == value(targetWord) |
d32b1c4a1d08a06b430c15ec74a7efc1c0a074c9 | chasecolford/Leetcode | /problems/5.py | 1,669 | 3.59375 | 4 | class Solution:
def longestPalindrome(self, s: str) -> str:
# 2D dp that acts as a truth table representing if dp[i][j] in s is palindromic.
# i.e., if dp[5][7] == 1, this means that s[5:7] is palindromic (actaully s[5 : 7 + 1] since upper bound is exclusve).
dp = [[0] * len(s) for ... |
ff342218775b4373369f66ca2f2f614eacea2de8 | chasecolford/Leetcode | /problems/1299.py | 772 | 3.75 | 4 | """
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.
After doing so, return the array.
Example 1:
Input: arr = [17,18,5,4,6,1]
Output: [18,6,6,6,1,-1]
Constraints:
1 <= arr.length <= 10^4
1 <= arr[... |
9c222a565c8c66c9fde6e134b18434e2652afc72 | chasecolford/Leetcode | /problems/904.py | 2,182 | 3.90625 | 4 | class Solution:
def totalFruit(self, f: List[int]) -> int:
"""sliding window
1. as long as we have only two types of fruit in our window,
we will keep taking them
2. when we find a new third fruit, we need to know how long ago
we saw each of the fruits. We will always... |
3f7bdc86609ad0a024f0949d6837a0d247d0a980 | chasecolford/Leetcode | /problems/144.py | 1,562 | 3.859375 | 4 | """
Given the root of a binary tree, return the preorder traversal of its nodes' values.
"""
from typing import List
from collections import deque
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
... |
bd83846e565390d79da82a00ee598bef52b81aaf | chasecolford/Leetcode | /problems/1160.py | 1,259 | 3.953125 | 4 | """
You are given an array of strings words and a string chars.
A string is good if it can be formed by characters from chars (each character can only be used once).
Return the sum of lengths of all good strings in words.
Example 1:
Input: words = ["cat","bt","hat","tree"], chars = "atach"
Output: 6
Explanation:... |
001165f242fdb986fecec06d0a830c95b6935da8 | chasecolford/Leetcode | /problems/61.py | 2,090 | 3.9375 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def rotateRight(self, head: ListNode, k: int) -> ListNode:
""" Main idea:
First, calculate the mod of k % len(list) if k >= len(list)... |
125dc18f00a8951c25367d469dc24ed00cd6df8d | chasecolford/Leetcode | /problems/1700.py | 1,112 | 3.84375 | 4 | from collections import deque
from typing import Deque
"""
1 <= students.length, sandwiches.length <= 100
students.length == sandwiches.length
sandwiches[i] is 0 or 1.
students[i] is 0 or 1.
"""
#NOTE:
def countStudents(students, sandwiches):
s, q = sandwiches, Deque(students)
taken = True
... |
fd18e0153a8b6a709f15e012c98c353fe5ae83c3 | chasecolford/Leetcode | /problems/1137.py | 340 | 3.625 | 4 | class Solution:
def tribonacci(self, n: int) -> int:
t0, t1, t2 = 0, 1, 1
if n == 0:
return 0
elif n == 1:
return 1
elif n == 2:
return 1
for i in range(n-2):
t = t0+t1+t2
t0 = t1
t1 = t2
t2 =... |
37f4fd23a2bde90fd6627b3a502d4268b8dc685d | flk91/LabPython | /LabPython/01-base/04-dec2bin.py | 527 | 3.96875 | 4 | # preso in input un numero, compreso tra 1 e 7,
# fornire la sua rappresentazione in sistema binario.
num = input("Digita un numero compreso tra 0 e 7\n")
num = int(num)
if num>=0 and num<=7 :
d = num
r1 = d % 2
d = d // 2 # l'operatore // è la divisione intera
r2 = d % 2
d = d // 2
r3 = d%2
... |
59a8aec02cb3d2502585f3b0ce3f6b1be9005a10 | flk91/LabPython | /LabPython/03-funzioni/amicabili.py | 723 | 3.875 | 4 | import math
###########################
# FUNZIONE sdiv(n)
#
# Preso in input un numero n,
# restituisce la somma dei suoi divisori propri
# (i divisori del numero compreso 1, escluso n
###########################
def sdiv(n):
sd=0
for i in range(1, n):
if n%i==0:
sd=sd+i
return sd
#... |
4f0d18d04a13b2f0b8180bef3b514d7e1f394694 | nicholaslz/Prate | /main 1.0.2.py | 4,532 | 3.5 | 4 | import json
def doNothing():
while True:
pass
def makeOffline(username):
with open('userinfo.json', 'r+') as f:
users = json.load(f)
users[username]['Online'] = "false"
json.dump(users, f)
def main():
while True:
user_input = input('... |
2aa009453bf62a097db6e738dda8cbf1a0671543 | eleander/Space-Invaders-Pygame | /Models/Bullet.py | 421 | 3.640625 | 4 | import pygame
class Bullet(object):
# "ready" You can't see the bullet on the screen
# "fire" The bullet is moving
def __init__(self, x, y, x_change):
self.x = x
self.y = y
self.x_change = x_change
self.y_change = -15
self.state = "ready"
def fire(self, bullet_i... |
8535a00eecd727d0efa7d0405d5ed154a57b9d98 | nakul3112/8-Puzzle-Solver | /eight_puzzle_bfs.py | 7,829 | 3.734375 | 4 |
import numpy as np
import time
m = int(input("Enter number of Rows: "))
n = int(input("Enter number of columns: "))
Mat = []
for i in range(0, n):
Mat.append([])
for i in range(0, m):
for j in range(0,n):
Mat[i].append(j)
Mat[i][j] = 0
for i in range(0, m):
for j in range(0, ... |
6f38ad96ae7b72e43726cf09f11581ebe95008d3 | wictoriadrefelt/assignment3 | /models/bank.py | 2,436 | 3.890625 | 4 | import datetime
import pytz
class Bank:
def __init__(self, name: str):
self.name = name
self.accounts = []
#self.account_holder = first
#self.account_number = account_number
def create_account(self):
new_account = Bank(self.name)
x = [new_account for ac in self... |
bdcbc4f9812887c2f701509b0410eeeb1b96e330 | parthag835/MY-Python_Projects | /Pattan.py | 398 | 3.75 | 4 | import turtle
ter=turtle.Turtle()
ter.speed(0)
def drow(size,angle):
for j in range(4):
ter.fd(size)
ter.right(angle)
print('lets start')
for i in range(36):
drow(100,90)
ter.right(11)
ter.color("Blue")
for i in range(36):
drow(100,90)
ter.right(11)
ter.color("Green")... |
ce919bd30927298fa44492fceac41314bf43bd3d | Subhadeep-Chaki/My-Game | /Rock-Paper-Scissors_Game.py | 2,347 | 4.1875 | 4 | '''
from random import randint
ty = ["Rock","Paper","Scissor"]
bot = ty[randint(0,2)]
user = False
while user ==False:
user = input("Rock,Paper,Scissor? -->")
if user == bot:
print("Tie!")
elif user == "Rock":
if bot =="Paper":
print("You Lose! Computer sel... |
c274089e97f4a820c527065a530d859e17e09296 | Scurry200/OpenCVPythonLearning | /chapter1.py | 12,181 | 3.515625 | 4 | import cv2
import numpy as np
print("package imported")
#reads image
# img = cv2.imread("Resources/shapes.png")
# #displays image
# cv2.imshow("Output", img)
# #infinite delay so image appears until you close it and doesn't close out on its own
# cv2.waitKey(0)
# #collects video
# cap = cv2.VideoCapture("Resources/v... |
7ef8a53dfda09b8282f113a2bc7b9772962df34b | ankithmjain/algorithms | /bsttut.py | 317 | 3.8125 | 4 | graph = {
'1': ['2', '3', '4'],
'2': ['5', '6'],
'5': ['9', '10'],
'4': ['7', '8'],
'7': ['11', '12']
}
def breadth_search(graph, a, b):
path = [a]
queue = [path]
while queue:
current_path = queue.pop(0)
node = current_path[-1] |
3d50000d49f4874047d0fde1ad5c9e3be2155de1 | ankithmjain/algorithms | /inheritance.py | 666 | 3.609375 | 4 | class Node(object):
def __init__(self,sName):
self._lChildren = []
self.sName = sName
def __repr__(self):
return "<Node '{}'>".format(self.sName)
def append(self,*args,**kwargs):
self._lChildren.append(*args,**kwargs)
def print_all_1(self):
print(self)
... |
b15d3c51708d19d0af3764bf2f9095b3ea2f5f39 | inghgalvanIA/pywombat | /1Tipo_De_Objetos.py | 263 | 3.921875 | 4 | #Imprime en consola el tipo de objeto de cada uno de los elemento que contiene la lista.
lista = ['Hola Mundo', 234, [4, 3, 2, 1], ('H', 'o', 'l', 'a'), 25.02, {1: 'M', 2: 'u', 3: 'n', 4: 'd', 5: 'o'}]
for i in lista:
print(f"el valor {i} es de tipo {type(i)}") |
a9d8ba6e2d7701ab2167a918f8184ee4548fae67 | mattiasl/aoc2020 | /src/day23/solver.py | 1,794 | 3.640625 | 4 | class Cup:
def __init__(self, label):
self.label = label
self.next_cup = None
def pick_n_cups(cup, n=3):
start_cup, values = cup.next_cup, []
cur = start_cup
for i in range(n - 1):
values.append(cur.label)
cur = cur.next_cup
values.append(cur.label)
cup.next_cu... |
0ad94b787990644aad4d8d4fd115fe1f13197c29 | casssie-zhang/LeetcodeNotes | /sort/148.SortList.py | 1,348 | 4.0625 | 4 | # Definition for singly-linked list.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def sortList(self, head):
l1 = ListNode(5)
l2 = None
res = self.mergeTwoLists(l1, l2)
print(res.val)
# fast and low ... |
25b381e4afb4706534d9c159c162606101f53726 | casssie-zhang/LeetcodeNotes | /trees/117.PopulatingNextRightPointersInEachNode2.py | 1,931 | 4 | 4 | """
# Definition for a Node.
class Node:
def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):
self.val = val
self.left = left
self.right = right
self.next = next
"""
class Solution:
def connect(self, node: 'Node') -> 'Node':
... |
adf5f06e774a49d3d5d8acd2dbbd4e8fa021bcc7 | casssie-zhang/LeetcodeNotes | /53.MaximumSubarray.py | 810 | 3.78125 | 4 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/4/5 18:02
# @Author : 10029
# @Email: zhangkexin@zhoupudata.com
def maxSubarray(nums):
# max sum = itself = (1) value at index itself (2) previndex to currindex
max_curr = nums[0]
max_gbl = nums[0]
i=1
while(i<len(nums)):
max_curr... |
72cce43bdaf0be117d8dd96813c64f4e9a0ef4a1 | rahmad239/teach_yourself | /dice_game.py | 746 | 4.375 | 4 | import random
# importing allows us access to the library within python. Additional options can be
#accessed and downloaded.
Roll=== int (random.randint(1,6)) #this sets the variable Rolls value to a random integer between 1 & 6
if Roll ===1:
print ("The number on the die is", Roll)
elif Roll ===2:
print ("Th... |
90f8f132f5bba37a3be8a6ccc8c2ada5e1a3c0e8 | thatguysilver/py3oop | /ch5/color.py | 701 | 3.953125 | 4 | #Used to illustrate why we don't need to use get/set methods in py.
class Color:
def __init__(self, rgb_value, name):
self.rgb_value = rgb_value
self._name = name
def _set_name(self, name):
if not name:
raise Exception('invalid name')
self._name = name
def _get... |
63a3505e56d2e1fcdf0f8a238be956f961038816 | thatguysilver/py3oop | /ch4/simple_exception.py | 527 | 4 | 4 | #Basic demo of exception raising.
class EvenOnly(list):
def append(self, integer):
if not isinstance(integer, int):
raise TypeError('Only integers can be added!')
if integer % 2:
raise ValueError('Only even numbers can be added.')
super().append(integer)
def funny_d... |
e093f4657c13b4006a3e23529e6fa6692b0c4577 | jessicarush/python-notes | /structured_file_formats.py | 13,046 | 3.828125 | 4 | '''Structured Text Files'''
# In simple text files, the only level of organization is the line. Sometimes,
# you need more structure than that. You might want to save data for your
# program to use later, or send data to another program. There are many
# formats. Each of these can be read and written by at least one ... |
65d9e42befb8e76ba3c495aeb217211cecec7365 | jessicarush/python-notes | /debugging.py | 5,198 | 4.21875 | 4 | '''Debugging'''
# General Tips
# -----------------------------------------------------------------------------
# Though not very advanced, dropping print() statements and other reflection
# related functions can tell you a lot about what's going on. Beyond that:
# print the values of your local arguments with:
prin... |
82926e24b04a451a26dd24c74a662c3109e1aa4f | jessicarush/python-notes | /concurrency.py | 20,072 | 3.96875 | 4 | '''Concurrency and Networks'''
# Normally we run programs in one place (on a single machine) and one line at
# a time (sequential). Concurrency is running more than one thing at a time.
# Distributed computing or Networking is running in more than one place.
# Concurrency: https://docs.python.org/3/library/concurren... |
901ad77d178758439eb9b68d53e3c9d5d375f1d3 | jessicarush/python-notes | /exceptions.py | 18,050 | 4.03125 | 4 | '''Exceptions'''
# An exception is a Python object that represents an error.
# There's two types of errors we can get: syntax errors and exceptions.
# Technically a syntax error is a type of exception but let's just say while
# syntax errors are self explanatory, 'Exceptions' are a result of flaws in a
# programs lo... |
e9a1dd9f7f6612ae34c90bdc97eccd0773fc3727 | jessicarush/python-notes | /helper_functions.py | 2,169 | 4.03125 | 4 | '''Demo: Helper functions can be more readable than complex expressions.'''
# Consider we're receiving some rgba values from a query string of a url.
# The output we want is an integer for each r, g, b, and a. Let's say if the
# values are missing, we want them to be 0.
# Let's first see what type of data we get:
f... |
723fb25ed9c431ace1f59270393d4f1f7c543f73 | jessicarush/python-notes | /regular_expressions.py | 10,009 | 4.3125 | 4 | '''Regular Expressions using the standard module re'''
import re
# https://docs.python.org/3/library/re.html
# match()
# -----------------------------------------------------------------------------
# Define a pattern string, and a source string to compare against.
# match() checks whether the source begins with t... |
f3eec4bd0caad34fe01f0b80786abca1cdfa7377 | jessicarush/python-notes | /rounding_example.py | 5,004 | 3.921875 | 4 | '''Rounding Issue with Floats and Solutions'''
# Floating point numbers are subject to rounding errors as they convert between
# binary and decimal. One solution is to use the decimal module that comes with
# python. The decimal module provides support for fast correctly-rounded
# decimal floating point arithmetic. I... |
a971dc92b4f231c388804796b041abc7cc575a2f | jessicarush/python-notes | /timezones_example.py | 2,407 | 4.53125 | 5 | '''Timezones Example'''
# A program that allows a user to choose one time zones from a list.
# The program will then display the time in that timezone,
# as well as local time & UTC time.
import datetime
import pytz
# References
# -----------------------------------------------------------------------------
# prin... |
9d8a35fe63cc515ead0ea933c876ad20f5df361e | jessicarush/python-notes | /shelve_module.py | 7,611 | 4.15625 | 4 | '''Shelve Module'''
# The shelve module can be used as a simple persistent storage option for
# Python objects when a relational database is overkill. The shelf is accessed
# by keys, just as with a dictionary. The values are pickled and written to a
# database file.
# When using modules like pickle, the downside is... |
028d97550694f94f8d66cd051364410995cb9dc6 | jessicarush/python-notes | /matplotlib_intro.py | 6,144 | 4.4375 | 4 | '''Matplotlib - Mathematical Plotting Library'''
# $ pip install matplotlib
# http://matplotlib.org
# https://matplotlib.org/examples/index.html
# https://matplotlib.org/users/pyplot_tutorial.html
# plt.plot()
# -----------------------------------------------------------------------------
import matplotlib.pyplot ... |
a353cdd5c69f9715f30307286ed83bb963f3857b | down-dive/Python_DS_practice | /Homework_1.py | 1,845 | 4.46875 | 4 | Exercise 1
print("Learning Python for Data Science")
Exercise 2
first_name = "Yevgeniya" # Exercise 2 - Python code
last_name = "Terlyuk"
print(first_name)
print(last_name)
2b
class_name = "Python for Data Science"
which_day = "Saturdays"
Num_days = "eight"
Class_timings = "9 am to noon"
sentence = "{} is on {} {} {... |
276dfeaaaa29ecc4bb0d31436b451c85034223a7 | yulishuta/algorithms-python | /BalanceSTree.py | 6,949 | 3.796875 | 4 | class Node:
def __init__(self,key, color='BLACK'):
self.key = key
self.left = None
self.right = None
self.color = color
def inOrder(tree):
if (tree == None): return
inOrder(tree.left)
print self.key
inOrder(tree.right)
def rotateLeft(node):
rightNode = node.ri... |
5f40834e43fd2b91650ca5850fcf9f1111b9e8e3 | notVonNeumann/python-coding-challenges | /fib_bottom_up.py | 354 | 3.671875 | 4 | def fib_bottom_up(n):
if n == 1 or n == 2:
return 1
arr = [None] * (n + 1)
arr[1] = arr[2] = 1
for i in range(3, n + 1):
arr[i] = arr[i - 1] + arr[i - 2]
return arr[n]
print(fib_bottom_up(10))
print(fib_bottom_up(100))
print(fib_bottom_up(1000))
print(fib_bottom_up(10000... |
88feeac24816d98ca7de2cae137b56e867d4da7a | ninjelli/assignment-1-AngelaHoch | /resize/interpolation.py | 1,885 | 3.734375 | 4 | #class interpolation:
import numpy
def linear_interpolation(image, pt1, pt2, unknown):
"""Computes the linear interpolation for the unknown values using pt1 and pt2
take as input
pt1: known point pt1 and f(pt1) or intensity value
pt2: known point pt2 and f(pt2) or intensity value
unknown: take and ... |
8dd790bdab3e6a6851c62e891cc3163dd819ebf0 | dpflug/Project-Euler | /python/dpflug-0004.py | 270 | 3.5625 | 4 | #!/usr/bin/env python
import pfleulerlib
three_digits = range(999,99,-1)
largest_palin = 0
for x in three_digits:
for y in three_digits:
if pfleulerlib.is_palin(str(x * y)) and x * y > largest_palin:
largest_palin = x * y
print(largest_palin)
|
a5bb6ee088fbb2d6718aee06696e952e22b46857 | dpflug/Project-Euler | /python/dpflug-0014.py | 1,099 | 3.5625 | 4 | def memoize(f):
class memodict(dict):
__slots__ = ()
def __missing_(self, key):
self[key] = ret = f(key)
return ret
return memodict().__getitem__
class countcalls(object):
"Decorator that keeps track of the number of times a function is called."
__instances = {... |
b7de72c6aa3d57955d560c62b4aefb7cfc8bb7ec | JissuPark/Algorithm | /BOJ/2579.py | 452 | 3.90625 | 4 | from sys import stdin
input = stdin.readline
def stair_climbing(s, n):
if len(s) < 3:
return sum(s)
DP = [[s[0], s[0]], [s[0] + s[1], s[1]]]
for i in range(2, n):
DP.append([DP[i - 1][1] + s[i], max(DP[i - 2][0], DP[i - 2][1]) + s[i]])
print(DP)
return max(DP[n - 1])
if __name__... |
6f193f20b2e94aaaca9b8b3753228b3d1d0bef93 | JissuPark/Algorithm | /BOJ/2920.py | 355 | 3.6875 | 4 | from sys import stdin
input = stdin.readline
def musical_scale(m):
if music == sorted(music):
return 'ascending'
elif music == sorted(music, reverse=True):
return 'descending'
else:
return 'mixed'
if __name__ == "__main__":
music = list(map(int, input().split()))
res = m... |
479ed0edd559e9089a3bdcf59020e94d7d2f19d1 | JissuPark/Algorithm | /BOJ/4949.py | 685 | 3.609375 | 4 | from sys import stdin
input = stdin.readline
def balanced_world(s):
stack = []
for arg in s:
if arg == '(' or arg == '[':
stack.append(arg)
elif arg == ')':
if stack and stack[-1] == '(':
stack.pop()
else:
return 'no'
... |
51cd122823574d3d79c7a53d92885e091ee80f52 | JissuPark/Algorithm | /BOJ/11655.py | 353 | 3.625 | 4 | import sys
#input
S = sys.stdin.readline()
#solution
def rot13(str):
answer = ""
for s in str:
if ord(s)>64 and ord(s)<91:
answer += chr(65+(ord(s)-65+13)%26)
elif ord(s)>96 and ord(s)<123:
answer += chr(97+(ord(s)-97+13)%26)
else:
answer += s
retu... |
7eeed9689a420313cbb7c566c1c2455103f47f1c | JissuPark/Algorithm | /BOJ/14425.py | 974 | 3.765625 | 4 | # 트리는 시간초과
class Node(object):
def __init__(self, apb):
self.apb = apb
self.children = {}
class Trie:
def __init__(self):
self.head = Node(None)
def insert(self, string):
cur = self.head
for ch in string:
if ch not in cur.children:
cur.chi... |
a9ed9891d1910887a7c2e13c6e4fe363f95e0ec2 | learntocodeGCSE/quick_code | /SnakeGame.py | 4,561 | 3.890625 | 4 | #imports needed
import pygame
import time
import random
#Make the window
pygame.init()
dis_Width = 300
dis_Height = 300
dis = pygame.display.set_mode((dis_Width,dis_Height))
pygame.display.set_caption('SNAKE!')
#Colours
white = (255, 255, 255)
black = (0 , 0 , 0)
yellow = (255,255,102)
blue = (50, 150, 210)
green = (... |
36577f80fae9a8235d5f610cfbbc7d79cf33761a | kelhwu/main | /IA_6.py | 858 | 3.75 | 4 | def merge(X, p, q, r):
left = []
right = []
# A = [None]*(r+1)
n1 = int(q - p + 1)
n2 = int(r - q)
for i in range(n1):
left.append(X[p+i])
for i in range(n2):
right.append(X[q+i+1])
left.append(float('inf'))
right.append(float('inf'))
print(left)
... |
37c5999ee1e6c620696734294c1f6b658f1edd1e | wiryawan46/Deep-Food | /TumFoodCam/Segmentation/Rectangle.py | 351 | 3.71875 | 4 | class Rectangle(object):
""" Rectangle wrapper.
"""
def __init__(self, upperLeftPoint, size):
self.width, self.height = size
self.upperLeft = upperLeftPoint
self.lowerRight = (upperLeftPoint[0] + self.width, upperLeftPoint[1] + self.height)
def contains(self, other):
... |
a180d4f5950a179cb75d2d7466b7eecd00dc559b | VictorYovev/ai | /av6/rooks_problem_without_lambda.py | 600 | 3.65625 | 4 | from constraint import *
def rooks_attacking_constraint(rook1, rook2):
if rook1[0] != rook2[0] and rook1[1] != rook2[1]:
return True
return False
if __name__ == '__main__':
problem = Problem(RecursiveBacktrackingSolver())
domain = [(i, j) for i in range(0, 8) for j in range(0, 8)]
rook... |
09c37165e63e0fa0ff44bcd235ed9cc6f7cf2627 | raindrift/leadreader | /leadreader/analyses/base.py | 606 | 3.78125 | 4 | """
base.py
Base class for all analysis.
"""
from abc import ABCMeta, abstractmethod
class BaseAnalysis(metaclass=ABCMeta):
""" Base class for all analysis to run on a composition."""
def __init__(self, composition):
self.composition = composition
@abstractmethod
def name(self):
""" ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.