blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
a3456f8a183741fc49af6142933fc3531b53a0e8
bfishbaum/euler
/fraction.py
1,258
3.703125
4
def contFraction(values): frac = (values.pop(),1) def addToFrac(fract,add): return (fract[0]+add*fract[1],fract[1]) while(values != []): frac = addToFrac(frac[::-1],values.pop()) return frac def sqrContFraction(n,accuracy): def nextIter(num): a = int(num[0]**0.5 + num[1]) // num[2] # a is the integer ...
5cc8dcca7e46e299fb8628ed12b52b12e260e4ff
bfishbaum/euler
/prob074.py
525
3.671875
4
#Solved def factorial(x): product = 1 while(x > 1): product *= x x -= 1 return product facts = [factorial(x) for x in range(10)] def digitFact(x): sum = 0 while(x != 0): sum += facts[x%10] x //= 10 return sum def chainLength(x): total = 1 previous = set() previous.add(x) while(True): x = digitFact...
9b26316b1a7e3f6597669050e9d1946018ad1f8d
bfishbaum/euler
/.BU/prob20
195
3.71875
4
#Solved def sumDigits(n): return n%10 + sumDigits(n//10) if n != 0 else 0 def factorial(x): product = 1 for z in range(2,x+1): product *= z return product print(sumDigits(factorial(100)))
524815de1376f982844cdc7ef8348aa2f13566ea
bfishbaum/euler
/.BU/prob21
480
3.578125
4
#Solved def getSumDivisors(n): if(n <= 3): return 1 divisors = [] for x in range(1,int(n**0.5)+1): if(n%x == 0): divisors += [x] if(x*x == n): divisors = divisors[0:-1] sum = 0 for div in divisors: sum += div sum += n/div return (sum - n) def amicableNo(x): y = getSumDivisors(x) z = getSumDi...
530439d2277c1fa97240581ae028f8501e72754d
onlyahran/Algorithm
/2-1.py
420
3.671875
4
#!/usr/bin/env python # coding: utf-8 # In[12]: # stack t = int(input()) for _ in range(t): n = int(input()) # 명령어 개수 stack = [] for i in range(n): q = int(input()) if q == -1: if len(stack) != 0: print(stack[len(stack)-1]) stack.pop() ...
2934d4388941701bd3d01b1b5d2a3815b96685e8
onlyahran/Algorithm
/2-3.py
480
3.65625
4
#!/usr/bin/env python # coding: utf-8 # In[12]: # priority queue import heapq t = int(input()) for _ in range(t): n = int(input()) # 명령어 개수 hq = [] # 빈 큐 선언 for _ in range(n): q = int(input()) if q == -1: if len(hq) != 0: min_num = min(hq) min_...
bdbb2890f71f21eb76593876b893340e5379e445
PacktPublishing/Practical-Convolutional-Neural-Networks
/Chapter01/code files/Keras_basics_3.py
2,828
3.6875
4
# Import Numpy, keras and MNIST data import numpy as np import matplotlib.pyplot as plt from keras.datasets import mnist from keras.models import Sequential from keras.layers.core import Dense, Dropout, Activation from keras.utils import np_utils # Retrieve the training and test data (X_train, y_train), (X_test, y_te...
9f856248e4b08b29cb0c23b763ef799bdc1b5396
akshaynit/data-structures
/heap_.py
1,394
3.75
4
# -*- coding: utf-8 -*- """ Created on Wed Nov 27 11:16:22 2019 @author: AK389016 """ heapsize = 0 def parent_index(pos): return int((pos - 1) / 2) def lchild_index(pos): return int(2 * pos) + 1 def rchild_index(pos): return 2 * pos + 2 def insert_heap(heap, x): heap.append(x) ...
0e52b904243347426e8af4ba256efb70009d606e
mbomark/DV-kurser
/v3 global var.py
2,209
3.796875
4
användare = {'a':'1', 'b':'2', 'c':'3'} saker = {'a':["fanta", "pepsi"],'b': [],'c': [] } def inlogg(): #function för inlogg global login login = str(input("användarnamn: ")) #print(login) if login == användare: #finns ...
1d39630f00c73bd5c678360e2bc0fd433242258f
KacperMitkowski/Technical_exercise
/main.py
1,404
4.125
4
def main(): """ :param - :return: - main function for displaying sum of expressions it handles errors exception as well """ try: outcome = add_expressions(1, 1, 2)(2, 4) result = '' for key, value in outcome.items(): result += f'{value}X**{key} + ' ...
dfa8979647d347122e7687448d4e29e5a5417dd9
priyankaparikh/dictionaries-word_count-
/wordcount.py
595
3.75
4
import sys from string import punctuation def get_word_count(filename): word_count = {} with open(filename) as paragraph: for line in paragraph: line = line.strip() words = line.split() for word in words: word = word.lower().strip(punctuation) ...
252fa34f5fc87f2b042fe1428175abff27185251
SixByNine/gwdetect
/src/detect_GWB_FreqAVG.py
1,250
3.5
4
#!/usr/bin/env python from sys import argv from numpy import * from matplotlib.pyplot import * avg=list() W=list() avgE2=list() freqs=list() first=True n=0 A=float(argv[1]) for a in argv[2:]: print a f=open(a) i=0 for line in f: elems=line.split() a=float(elems[0]) v=float(ele...
2fea25fbbdab6a4df00c4f8d65cc066c0f8e096f
shivaligulati/pwt-color-wheel
/colorwheel.py
604
3.921875
4
from turtle import * t1 = Turtle() #imports turtle + window for graphics colors = ["red", "orange", "yellow", "green", "blue", "purple"] #color list import random #necessary to import to make sure the same color isn't being draw t1.up() t1.goto(-200,0) t1.down() t1.width(5) t1.hideturtle() t1.speed(0) #draws th...
763482a8657be10538ee02b9f5595a587409178c
Babnik21/Euler
/Euler 37.py
1,595
3.578125
4
#opazimo, da soda števila ne morejo biti praštevila (razen 2, poseben primer, ki ga prištejemo kasneje) #ker mora biti število praštevilo v vseh rotacijah, ne sme imeti sode števke cifre = '123579' def prastevilo(n): if n <= 1: return False i = n**0.5 if i == i//1: return False i = i ...
509857b30b352b639e707d5e3959a534e889f2aa
seanjones2848/python_basics
/ex03.py
311
3.640625
4
import sys if len(sys.argv) < 2: print ("Give me a number") else: n = sys.argv[1] if n < 0: sign = -1 n = n * -1 else: sign = 1 nums = [0] i = 0 while i < n: print i if i % 3 == 0 or i % 5 == 0: print i nums.append(i) i += 1 if i == n: break print("all done") print (str(sum(nums) * sign))
f15d372f3bb0d3bd73b9fcbb3c2babba05d6a5e0
atemate/case-dataset-loader
/dataset_loader/utils.py
2,323
3.953125
4
from typing import Iterator, Optional, Sequence, Tuple, Union def zip_closest( main: Sequence[int], secondary: Sequence[int], *, linearize: bool = False, step: Optional[int] = 1, ) -> Iterator[Tuple[int, int]]: """ Iterates over 'main' sequence while taking the closest element from 'se...
81309f236e523a326b1866b281868fe8dd1b0be6
luiramirezm/barbie
/Python lu/1.py
314
3.8125
4
"""1. Elabore un algoritmo que almacene una lista de 10 elementos, imprima la lista Lista = [46,78,23,1,0,5,67,33,29] """ try: lista = [] for i in range(10): num = int(input("Digite un número: ")) lista.append(num) print("La lista es: ", lista) except ValueError: Print("Error")
b8a1c4fbe8f8eb3d64b8d6dec489fe87c0b41bcd
ehivan24/data_analysis_python
/data_analysis/employment_data_analysis/data_analysis_4_pandas_and_numpy.py
2,386
3.515625
4
import unicodecsv as csv from datetime import datetime as dt from collections import defaultdict import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from Data_Analysis_Utils import Data_Analysis_Util as utils """ Here we load the file. """ df_weather = pd.read_csv('nyc_su...
2eec291ff40aa05e277ab9a317296600397916e9
Jackyzzk/Algorithms
/树-递归-08-0572. 另一个树的子树.py
2,427
4
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): """ 给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。 s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。 给定的树 s: 3 / \ 4 5 / ...
96477d3379ba056eb206e649c35461046c022f8f
Jackyzzk/Algorithms
/搜索-Backtracking-12-0090. 子集 II.py
967
3.703125
4
class Solution(object): """ 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。 说明:解集不能包含重复的子集。 输入: [1,2,2] 输出: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] 链接:https://leetcode-cn.com/problems/subsets-ii """ def subsetsWithDup(self, nums): """ :type nums: List[int] :rtype: List[List[int]...
d573001da5d38886fefd80b3c1a6fa937b56d4de
Jackyzzk/Algorithms
/栈和队列-04-0020. 有效的括号-2.py
1,107
4.03125
4
class Solution(object): """ 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 注意空字符串可被认为是有效字符串。 输入: "()" 输出: true 输入: "()[]{}" 输出: true 输入: "(]" 输出: false 输入: "([)]" 输出: false 输入: "{[]}" 输出: true 链接:https://leetcode-cn.com/problems/valid-parentheses ...
783b868934843905d4bb01454f9050946cf16bf9
Jackyzzk/Algorithms
/数学-素数分解-01-0204. 计数质数-2.py
765
3.765625
4
class Solution(object): """ 统计所有小于非负整数 n 的质数的数量。 输入: 10 输出: 4 解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。 链接:https://leetcode-cn.com/problems/count-primes/ """ def countPrimes(self, n): """ :type n: int :rtype: int """ if n < 2: return 0 x = [1 for i in...
8a3d0206b9e2fdb4d532777cb10f0266f9c8c45d
Jackyzzk/Algorithms
/哈希表-02-0217. 存在重复元素.py
934
3.78125
4
class Solution(object): """ 给定一个整数数组,判断是否存在重复元素。 如果任何值在数组中出现至少两次,函数返回 true。如果数组中每个元素都不相同,则返回 false。 输入: [1,2,3,1] 输出: true 输入: [1,2,3,4] 输出: false 输入: [1,1,1,3,3,4,3,2,4,2] 输出: true 链接:https://leetcode-cn.com/problems/contains-duplicate/ """ def containsDuplicate(self, nums): """ :type nums:...
3cd31e6abf7549b38701549dccfe9784a509c2b0
Jackyzzk/Algorithms
/树-BST-01-0669. 修剪二叉搜索树.py
2,556
3.96875
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): """ 给定一个二叉搜索树,同时给定最小边界L 和最大边界 R。 通过修剪二叉搜索树,使得所有节点的值在[L, R]中 (R>=L) 。 你可能需要改变树的根节点,所以结果应当返回修剪好的二叉搜索树的新的根节点。 二叉排序树,若它的左子树不空,则左子树上所有结...
db8312d916feb0b62529d7fcc0efcbb25211d077
Jackyzzk/Algorithms
/图-拓扑排序-02-0210. 课程表 II.py
2,550
3.625
4
class Solution(object): """ 现在你总共有 n 门课需要选,记为 0 到 n-1。 在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 , 你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总量以及它们的先决条件,返回你为了学完所有课程所安排的学习顺序。 可能会有多个正确的顺序,你只要返回一种就可以了。如果不可能完成所有课程,返回一个空数组。 输入: 2, [[1,0]] 输出: [0,1] 解释: 总共有 2 门课程。要学习课程 1,你需要先完成课程 0。因此,正确的课程顺序为 [0,1] 。 输入: 4, [[1,0],[2,0],[3,1],[3,2]] 输出:...
eb954c6e2157c1ccc5cbc23e7619c0b9796d29d6
Jackyzzk/Algorithms
/哈希表-04-0128. 最长连续序列-3-Jacky.py
1,014
3.609375
4
class Solution(object): """ 给定一个未排序的整数数组,找出最长连续序列的长度。 要求算法的时间复杂度为 O(n)。 输入: [100, 4, 200, 1, 3, 2] 输出: 4 解释: 最长连续序列是 [1, 2, 3, 4]。它的长度为 4。 链接:https://leetcode-cn.com/problems/longest-consecutive-sequence/ """ def longestConsecutive(self, nums): """ :type nums: List[int] :rtype: int ...
9051da063bc2326716901270daee85cbea768379
Jackyzzk/Algorithms
/树-BST-05-0236. 二叉树的最近公共祖先.py
2,914
3.9375
4
# Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): """ 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q, 最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大 (一个节点也可以是它自己的祖先)。” ...
e0d58aca04b28a51e1d0d2495158bc3a981494b0
Jackyzzk/Algorithms
/动态规划-0-1 背包-06-0139. 单词拆分.py
1,593
3.625
4
class Solution(object): """ 给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict, 判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 拆分时可以重复使用字典中的单词。你可以假设字典中没有重复的单词。 输入: s = "leetcode", wordDict = ["leet", "code"] 输出: true 解释: 返回 true 因为 "leetcode" 可以被拆分成 "leet code"。 输入: s = "applepenapple", wordDict = ["apple", "pen"] 输出: true 解释: 返回 true 因为 "applep...
47a7325eb5da1a2c3ab9aebdf01f7658e8c5b6bd
Jackyzzk/Algorithms
/数组与矩阵-06-0448. 找到所有数组中消失的数字.py
1,101
3.5625
4
class Solution(object): """ 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。 找到所有在 [1, n] 范围之间没有出现在数组中的数字。 您能在不使用额外空间且时间复杂度为O(n)的情况下完成这个任务吗? 你可以假定返回的数组不算在额外空间内。 输入: [4,3,2,7,8,2,3,1] 输出: [5,6] 链接:https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array """ def findDisappear...
754836370ff927b7ebd528b0fd12f53fc479b665
Jackyzzk/Algorithms
/数学-其他-04-0628. 三个数的最大乘积.py
941
3.96875
4
class Solution(object): """ 给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积。 输入: [1,2,3] 输出: 6 输入: [1,2,3,4] 输出: 24 注意: 给定的整型数组长度范围是[3,104],数组中所有的元素范围是[-1000, 1000]。 输入的数组中任意三个数的乘积不会超出32位有符号整数的范围。 链接:https://leetcode-cn.com/problems/maximum-product-of-three-numbers/ """ def maximumProduct(self, nums): ...
c8358f96ca97b2b320ebf6ba1e569e89a972fb2c
Jackyzzk/Algorithms
/二分查找-03-0540-有序数组中的单一元素.py
1,254
3.53125
4
class Solution(object): """ 给定一个只包含整数的有序数组,每个元素都会出现两次,唯有一个数只会出现一次,找出这个数。 输入: [1,1,2,3,3,4,4,8,8] 输出: 2 输入: [3,3,7,7,10,11,11] 输出: 10 注意: 您的方案应该在 O(log n)时间复杂度和 O(1)空间复杂度中运行。 链接:https://leetcode-cn.com/problems/single-element-in-a-sorted-array/ """ def singleNonDuplicate(self, nums): """ :typ...
2f49e9c514fcd4ec43c9226d27abd1468ed82570
Jackyzzk/Algorithms
/数组与矩阵-04-0240. 搜索二维矩阵 II.py
1,443
3.859375
4
class Solution(object): """ 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性: 每行的元素从左到右升序排列。 每列的元素从上到下升序排列。 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30] ] 给定 target = 5,返回 true。 给定 target = 20,返回 false。 链接:https://leetc...
99c0fc48a9ec23d868c660b9d93690207294291b
Jackyzzk/Algorithms
/栈和队列-03-0155. 最小栈.py
1,403
4.28125
4
class MinStack(object): """ 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。 push(x) -- 将元素 x 推入栈中。 pop() -- 删除栈顶的元素。 top() -- 获取栈顶元素。 getMin() -- 检索栈中的最小元素。 示例: MinStack minStack = new MinStack(); minStack.push(-2); minStack.push(0); minStack.push(-3); minStack.getMin(); --> 返回 -3. minStack.pop(); minStack.top(); ...
853945bbb696365c6cfc27021580430a8e8b6606
Jackyzzk/Algorithms
/双指针-04-0680. 验证回文字符串 Ⅱ-2.py
1,015
3.78125
4
class Solution(object): """ 给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。 输入: "aba" 输出: True 输入: "abca" 输出: True 解释: 你可以删除c字符。 字符串只包含从 a-z 的小写字母。字符串的最大长度是50000。 链接:https://leetcode-cn.com/problems/valid-palindrome-ii/ """ def validPalindrome(self, s): """ :type s: str :rtype: bool """ ...
af360abc6fdeac81fc584961fa3047ee2a217fea
Jackyzzk/Algorithms
/搜索-Backtracking-06-0047. 全排列 II.py
1,446
3.59375
4
class Solution(object): """ 给定一个可包含重复数字的序列,返回所有不重复的全排列。 输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ] 链接:https://leetcode-cn.com/problems/permutations-ii/ """ visit = 0 def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ def...
bd5e28e0bf06b2deb843a3456d7e945195ccdc56
Jackyzzk/Algorithms
/动态规划-0-1 背包-02-0494. 目标和-常规dp优化2.py
1,710
3.5625
4
class Solution(object): """ 给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在你有两个符号 + 和 -。 对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面。 返回可以使最终数组和为目标数 S 的所有添加符号的方法数。 输入: nums: [1, 1, 1, 1, 1], S: 3 输出: 5 解释: -1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 +1+1+1+1-1 = 3 一共有5种方法让最终目标和为3。 数组非空,且长度不会超过20。 初始的数组的和不会超过1000。 ...
17b9a02df2076861842abc841261725fb893fabf
Jackyzzk/Algorithms
/搜索-Backtracking-05-0046. 全排列-3位掩码.py
1,329
3.640625
4
class Solution(object): """ 给定一个 没有重复 数字的序列,返回其所有可能的全排列。 示例: 输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] 链接:https://leetcode-cn.com/problems/permutations/ """ def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] ...
39453dd00c0fdc736109a84d009f5724005dd0f5
Jackyzzk/Algorithms
/位运算-09-0693. 交替位二进制数.py
939
3.8125
4
class Solution(object): """ 给定一个正整数,检查他是否为交替位二进制数:换句话说,就是他的二进制数相邻的两个位数永不相等。 输入: 5 输出: True 解释: 5的二进制数是: 101 输入: 7 输出: False 解释: 7的二进制数是: 111 输入: 11 输出: False 解释: 11的二进制数是: 1011 输入: 10 输出: True 解释: 10的二进制数是: 1010 链接:https://leetcode-cn.com/problems/binary-number-with-alternating-bits """ def hasAlternatingBi...
db483fb95801279127d2e984cac3bc66cad0bd21
Jackyzzk/Algorithms
/字符串-05-0409. 最长回文串.py
959
3.8125
4
class Solution(object): """ 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。 在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。 假设字符串的长度不会超过 1010。 输入: "abccccdd" 输出: 7 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。 链接:https://leetcode-cn.com/problems/longest-palindrome """ def longestPalindrome(self, s): """ :type s: str ...
0b2fffef7f4ea66e25ca54501b0b107003133c86
Jackyzzk/Algorithms
/动态规划-字符串编辑-02-0072. 编辑距离-优化dp.py
1,649
3.859375
4
class Solution(object): """ 给定两个单词 word1 和 word2,计算出将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行如下三种操作: 插入一个字符 删除一个字符 替换一个字符 输入: word1 = "horse", word2 = "ros" 输出: 3 解释: horse -> rorse (将 'h' 替换为 'r') rorse -> rose (删除 'r') rose -> ros (删除 'e') 输入: word1 = "intention", word2 = "execution" 输出: 5 解释: intention -> inentio...
0778fbf16e667863f63e346623fa1f7a253f9a14
Jackyzzk/Algorithms
/树-递归-14-0671. 二叉树中第二小的节点-heap.py
2,284
3.75
4
# Definition for a binary tree node. import heapq class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): """ 给定一个非空特殊的二叉树,每个节点都是正数,并且每个节点的子节点数量只能为 2 或 0。 如果一个节点有两个子节点的话,那么这个节点的值不大于它的子节点的值。  给出这样的一个二叉树,你需要输出所有节点中的第二小的值。如果...
22310fd77460385a308e5da0264509e8cb189e6e
wubw555/cp
/multi_loop/multi_loop.py
2,871
3.671875
4
import sys def build_statement(loop_list, current_num, spaces): ''' recursive function for build for statement. Args: loop_list (list): list of basic for statement currnt_num (int): current position of processing spaces (int): spaces for indentation Returns: for_stateme...
b3c50f0e348a4da2176d5585e89786e75aba2a27
harry-sunhao/Python
/Topic5_Question.py
1,580
3.78125
4
def Q5_11(): student_num=int(input("Enter the number of students ")) First_Scores=int(input("Enter Num1 student's score: ")) Sencond_Scores=First_Scores for i in range(1,student_num): scores=int(input("Enter Num"+str(i+1)+" student's score: ")) if(scores>First_Scores): Sencond_Scores=First_Scores...
2b75b179ef238fbba80f7a50b6fc7ce32035525e
computingForSocialScience/cfss-homework-dianahou
/Assignment5/fetchAlbums.py
1,482
3.875
4
import requests from datetime import datetime def fetchAlbumIds(artist_id): """Using the Spotify API, take an artist ID and returns a list of album IDs in a list """ url = "https://api.spotify.com/v1/artists/" + artist_id + "/albums?market=US&album_type=album" req = requests.get(url) album_dat...
3f69a86216b5ec08c7135fdd889bd5136b1a5760
manojach87/ludo
/src/game.py
3,044
3.65625
4
colors = {0: "red", 1: "green", 2: "yellow", 3: "blue"} ## This class is for the gatti class gatti: loc = -1 MAXMOVES = 56 inSafeZone = True SAFEZONES = [-1, 0, 8, 13, 21, 26, 34, 39, 47] HOMEZONES = [51, 52, 53, 54, 55, 56] def __init__ (self,color): self.color = color self.loc...
59b7f02ae28b7a37b7b2bac726f483b5040b223e
NikolasHofmann/visual_output
/visualize_fib_squares.py
1,188
3.65625
4
import pygame from fibonacci_squares import make_rect, make_rects_random from random import randint from time import sleep pygame.init() window = (1600,1600) screen = pygame.display.set_mode(window) background = pygame.Surface(window) background.fill ((255,90,0)) """ for i in range(1, 40): rectangle = make_rect...
593f055fd888630c55986a5b08816e6cc01866d9
mddzzuhust/PythonDynamic
/chapter01/hnt.py
1,357
4.0625
4
#1. 大傻: 只搬动一号盘 #2. 1. 叫谁来做,: 1. 从哪个柱子搬动到哪个柱子,中间柱子 #2. 2. 搬动自己负责的柱子 3. 从哪个柱子搬动到哪个柱子,中间柱子 def move(index, start, mid, end): if index == 1: print("{}-->{}".format(start,end)) return else: move(index-1, start, end, mid) print("{}-->{}".format(start, end)) move(index-1, mid,...
a02952c2fe50ca536bbbf6e7e4f1864e95f3b1af
Shyngyskhan/BFDjango
/Week 1/informatics/functions/B.py
146
3.84375
4
def double_power(nubmer, power): return number ** power number = float(input()) power = int(input()) print (double_power(number, power))
37c8299281370444f16d46d9ef079f44db0b9164
joechip504/EightBlockPuzzle
/board.py
2,337
3.84375
4
import logging import math import sys class Board(object): ''' Represents the current board state. self.grid : 2D list storing the tiles at their respective locations. self.goal : dictionary maps tiles to 2-tuples representing goal locations. = { 0 : (0,0) , 1 : (1,0) , ....
4cfe379136a8a0e1d67e4742b0e7f5385dd26c5c
reyyansarikaya/Codewars
/7kyu/highest_and_lowest.py
450
3.984375
4
""" Author: Fatma Reyyan SARIKAYA """ """ In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number. Example: high_and_low("1 2 3 4 5") # return "5 1" high_and_low("1 2 -3 4 5") # return "5 -3" high_and_low("1 9 3 4 -5") # return "9 -5" """ def hi...
5f1dddf598953f481071feca220157a4ba6577b6
wobblefish/python-examples
/snake/Snake.py
2,784
3.96875
4
import random import curses # init the screen s = curses.initscr() # hide the cursor so it doesn't show curses.curs_set(0) # get the width and height sh, sw = s.getmaxyx() # create a new window using height, width # start at top w = curses.newwin(sh, sw, 0, 0) # have the window accept keypad input w.keypad(1) # refre...
cd994c41c4723151b04c7abc9f8cdc0595c1bf8a
GongFuXiong/leetcode
/topic13_tree/T94_inorderTraversal/interview.py
1,058
3.84375
4
''' 94. 二叉树的中序遍历 给定一个二叉树,返回它的中序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] ''' import sys sys.path.append("..") # 这句是为了导入_config from T_tree.Tree import Tree import math class Solution: def inorderTraversal(self, root): res = [] def dfs(root): ...
93ef6dfb96137c06a898c8b33966fa86bc13406d
GongFuXiong/leetcode
/topic12_backtrack/T1028_recoverFromPreorder/interview.py
1,907
3.515625
4
''' 1028. 从先序遍历还原二叉树 我们从二叉树的根节点 root 开始进行深度优先搜索。 在遍历中的每个节点处,我们输出 D 条短划线(其中 D 是该节点的深度),然后输出该节点的值。(如果节点的深度为 D,则其直接子节点的深度为 D + 1。根节点的深度为 0)。 如果节点只有一个子节点,那么保证该子节点为左子节点。 给出遍历输出 S,还原树并返回其根节点 root。 示例 1: 输入:"1-2--3--4-5--6--7" 输出:[1,2,5,3,4,6,7] 示例 2: 输入:"1-2--3---4-5--6---7" ...
5b52c4153f231b0efb645d96d5aee78fa6c47785
GongFuXiong/leetcode
/topic23_math/T31_nextPermutation/interview.py
2,561
3.640625
4
''' 31. 下一个排列 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列。 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列)。 必须原地修改,只允许使用额外常数空间。 以下是一些例子,输入位于左侧列,其相应输出位于右侧列。 1,2,3 → 1,3,2 3,2,1 → 1,2,3 1,1,5 → 1,5,1 ''' class Solution: def nextPermutation(self, nums: List[int]): ''' 方法一...
46c2131853e2c3540fda9439cc33db1d21d4cf32
GongFuXiong/leetcode
/topic16_speed_pointer/T287_findDuplicate/interview.py
2,487
3.6875
4
''' 287. 寻找重复数 给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),可知至少存在一个重复的整数。假设只有一个重复的整数,找出这个重复的数。 示例 1: 输入: [1,3,4,2,2] 输出: 2 示例 2: 输入: [3,1,3,4,2] 输出: 3 说明: 不能更改原数组(假设数组是只读的)。 只能使用额外的 O(1) 的空间。 时间复杂度小于 O(n2) 。 数组中只有一个重复的数字,但它可能不止重复出现一次。 ''' class Solution: ...
47e84986523cc8d34a78206472ba493b0d6348cf
GongFuXiong/leetcode
/topic9_hash_table/T350_intersect/interview.py
1,561
4.0625
4
''' 350. 两个数组的交集 II 给定两个数组,编写一个函数来计算它们的交集。 示例 1: 输入:nums1 = [1,2,2,1], nums2 = [2,2] 输出:[2,2] 示例 2: 输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4] 输出:[4,9] ''' class Solution: # 哈希表 def intersect(self, nums1, nums2): ''' 问题分析: 这道题 与 两个数组的交集 I 的 区别...
c663db23170f3a5e07599ea9b3db8fc4c7b667b4
GongFuXiong/leetcode
/topic5_string/T214_shortestPalindrome/interview.py
916
3.984375
4
''' 214. 最短回文串 给定一个字符串 s,你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。 示例 1: 输入: "aacecaaa" 输出: "aaacecaaa" 示例 2: 输入: "abcd" 输出: "dcbabcd" ''' class Solution: # 方法一:对称 def shortestPalindrome(self, s): ''' 思路:找到 反向的第一个重合点 ''' r = s[::-1...
a7259b21164eacfc8605afca4c7b8eff1552a736
GongFuXiong/leetcode
/old/t20190803_MinStack/MinStack.py
1,980
4.09375
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @file: MinStack.py @time: 2019/8/03 @rel: https://leetcode-cn.com/problems/min-stack/ @url: @desc: 155. 最小栈 设计一个支持 push,pop,t...
82babc37588e87d6d7f94c2e89158e65a986e2e6
GongFuXiong/leetcode
/topic11_heap/T_HeapSort/Heap.py
4,013
3.5625
4
''' 堆排序 ''' import math class MaxHeap: def deapsort(self,nums): nums_len = len(nums) # 1.构建大顶堆 for i in range(math.floor(nums_len/2),-1,-1): # 从第一个非叶子结点从下至上,从右至左调整结构 self.adjustHeap(nums,i,nums_len) # 2.调整堆结构+交换堆顶元素与末尾元素 for i in range(nums_len-1,0...
5f371670dcf687e653c1bbd2fd6396e2a077f845
GongFuXiong/leetcode
/old/t20190909_deleteDuplicates/deleteDuplicates.py
2,032
3.6875
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/9/09 @url:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/ @desc: 82. 删除排序链表中的重复元素 II ...
891daa87059a9ae88d58e15b8bce428452623887
GongFuXiong/leetcode
/topic13_tree/T111_minDepth/interview.py
1,317
3.78125
4
''' # 111. 二叉树的最小深度 ## 题目 ### 介绍 给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明: 叶子节点是指没有子节点的节点。 ### 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回它的最小深度 2. ''' import sys sys.path.append("..") # 这句是为了导入_config from T_tree.Tree import Tree class Solution: ...
d73a0fcf42906d9903851fd422939acb7164ff3c
GongFuXiong/leetcode
/simulation_study/191117_isHappy/demo.py
1,204
3.59375
4
''' 202. 快乐数 ''' import math class Solution: # 循环法,阙值出现问题 def isHappy1(self, n): count = 0 level =1000 while count < level: curr_num = math.pow(n%10,2) while int(n/10) != 0: curr_num = curr_num +math.pow(n/10,2) n = int(n/10) ...
c650a6ba2203464a75aebd88ce1bbc75d843bdc0
GongFuXiong/leetcode
/topic10_queue/T239_maxSlidingWindow/interview.py
2,322
3.78125
4
''' 239. 滑动窗口最大值 给定一个数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。 返回滑动窗口中的最大值。 进阶: 你能在线性时间复杂度内解决此题吗? 示例: 输入: nums = [1,3,-1,-3,5,3,6,7], 和 k = 3 输出: [3,3,5,5,6,7] 解释: 滑动窗口的位置 最大值 --------------- ----- [1 ...
7f95f0b3757191c0573087ad9adc856829728499
GongFuXiong/leetcode
/topic6_stack/T84_ilargestRectangleArea/interview.py
1,558
3.828125
4
''' 84. 柱状图中最大的矩形 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 求在该柱状图中,能够勾勒出来的矩形的最大面积。 以上是柱状图的示例,其中每个柱子的宽度为 1,给定的高度为 [2,1,5,6,2,3]。 图中阴影部分为所能勾勒出的最大矩形面积,其面积为 10 个单位。 示例: 输入: [2,1,5,6,2,3] 输出: 10 ''' class Solution: def largestRectangleArea(self, heights): n = len(heigh...
44149205fcb45b0e5cf213dd208c87af3a308c51
GongFuXiong/leetcode
/topic2_arr/T_select_max_min/demo.py
818
4.09375
4
''' 在一个未排序的整型数组中,如何找到最大和最小的数字? ''' class Solution: def select_max_min(self, nums): max_val = nums[0] min_val = nums[0] for num in nums: if max_val < num: max_val = num elif min_val > num: min_val = num return [max_val,min_v...
9c901069b6795631815f32e06bd99870410041df
GongFuXiong/leetcode
/old/t20190902_threeSumClosest/threeSumClosest.py
1,854
3.71875
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/8/31 @url:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/ @desc: 16. 最接近的三数之和 给定一个包括...
c4e8682133110ede6b728ea536832892395e05f0
GongFuXiong/leetcode
/topic8_binary_search/T69_mySqrt/interview.py
1,288
3.890625
4
''' 69. x 的平方根 实现 int sqrt(int x) 函数。 计算并返回 x 的平方根,其中 x 是非负整数。 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。 示例 1: 输入: 4 输出: 2 示例 2: 输入: 8 输出: 2 说明: 8 的平方根是 2.82842...,   由于返回类型是整数,小数部分将被舍去。 ''' class Solution: #def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:...
200f39591fbf6f59631a4e092900d7b77e7cb002
GongFuXiong/leetcode
/topic16_speed_pointer/T109_sortedListToBST/interview.py
1,807
3.921875
4
''' 109. 有序链表转换二叉搜索树 给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。 示例: 给定的有序链表: [-10, -3, 0, 5, 9], 一个可能的答案是:[0, -3, 9, -10, null, 5], 它可以表示下面这个高度平衡二叉搜索树: 0 / \ -3 9 / / -10 5 ''' # Definition for singly-linked list. # class ListN...
57ce2715e667249a4d530416d79b37f16a50dcfc
GongFuXiong/leetcode
/topic3_List/MS0203_deleteNode/code.py
949
3.859375
4
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. 解析:因为 nod...
636133e7b89d38c41c56a0bbebeca093aabfa7b4
GongFuXiong/leetcode
/old/t20190822_canJump/canJump.py
3,325
3.671875
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/8/22 @url:https://leetcode-cn.com/problems/jump-game/ @desc: 55. 跳跃游戏 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该...
53c5d69766ed6394f64be7e270b8127364e9c061
GongFuXiong/leetcode
/topic8_binary_search/T15_three_sum/interview.py
1,544
3.5625
4
''' 15. 三数之和 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有满足条件且不重复的三元组。 注意:答案中不可以包含重复的三元组。 示例: 给定数组 nums = [-1, 0, 1, 2, -1, -4], 满足要求的三元组集合为: [ [-1, 0, 1], [-1, -1, 2] ] ''' class Solution: def threeSum(self, num...
b900888e707bddf303fb3e252d93efef633b1b59
GongFuXiong/leetcode
/topic4_dynamic_planning_study/T845_longestMountain/interview.py
2,103
3.9375
4
''' 845. 数组中的最长山脉 我们把数组 A 中符合下列属性的任意连续子数组 B 称为 “山脉”: B.length >= 3 存在 0 < i < B.length - 1 使得 B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1] (注意:B 可以是 A 的任意子数组,包括整个数组 A。) 给出一个整数数组 A,返回最长 “山脉” 的长度。 如果不含有 “山脉” 则返回 0。   示例 1: 输入:[2,1,4,7,3,2,5] 输出:5 解...
492844867026eca8972723ece8ae88c8358d8160
GongFuXiong/leetcode
/old/t20190826_subsets/exist.py
3,271
3.609375
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/8/30 @url:https://leetcode-cn.com/problems/word-search/ @desc: 79. 单词搜索 给定一个二维网格和一个单词,找出该单词是否存在于网格中。 单词必...
1cd492aea267fe7c8490cbad77cf385cb976af3b
GongFuXiong/leetcode
/topic23_math/T67_addBinary/interview.py
1,710
3.609375
4
''' 67. 二进制求和 给你两个二进制字符串,返回它们的和(用二进制表示)。 输入为 非空 字符串且只包含数字 1 和 0。   示例 1: 输入: a = "11", b = "1" 输出: "100" 示例 2: 输入: a = "1010", b = "1011" 输出: "10101" ''' class Solution: def addBinary(self, a: str, b: str) -> str: carry_flag = 0 # 是否进位 sum_str = ''...
9be813d538f7919d91fe4b6f0527828b9f170412
GongFuXiong/leetcode
/topic5_string/T1002_commonChars/interview.py
1,957
3.640625
4
''' 1002. 查找常用字符 给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。 你可以按任意顺序返回答案。 示例 1: 输入:["bella","label","roller"] 输出:["e","l","l"] 示例 2: 输入:["cool","lock","cook"] 输出:["c","o"] ''' from collections import defaultdict c...
e99178d39fa86eb3edd5eefe226952d0dfdcdeb8
GongFuXiong/leetcode
/old/t20190904_search2/search2.py
2,341
3.5625
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/9/04 @url: @desc: 假设按照升序排序的数组在预先未知的某个点上进行了旋转。 ( 例如,数组 [0,0,1,2,2,5,6] 可能变为 [2,5,6,0,0,1,2] )。 编写一个函数来判断给定的目...
5de98fafd1ac39c4c42176f307eb83d8322be0d0
GongFuXiong/leetcode
/topic2_arr/T1431_kidsWithCandies/interview.py
2,153
3.78125
4
''' 1431. 拥有最多糖果的孩子 给你一个数组 candies 和一个整数 extraCandies ,其中 candies[i] 代表第 i 个孩子拥有的糖果数目。 对每一个孩子,检查是否存在一种方案,将额外的 extraCandies 个糖果分配给孩子们之后,此孩子有 最多 的糖果。注意,允许有多个孩子同时拥有 最多 的糖果数目。   示例 1: 输入:candies = [2,3,5,1,3], extraCandies = 3 输出:[true,true,true,false,true] 解释: 孩子 1 有 2 个糖果,如果他得到所有...
eaa28e921ca65595ff5c4ab3c25c8f4728290b89
GongFuXiong/leetcode
/old/t20190928_multiply/multiply.py
1,331
3.953125
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/9/28 @url:https://leetcode-cn.com/problems/multiply-strings/submissions/ @desc: 43. 字符串相乘 给定两个以字符串形式表示的非负整数 ...
07f97eb039f75955dad5963864ae3011006b2818
GongFuXiong/leetcode
/old/t20190926_isPalindrome/isPalindrome.py
1,912
3.828125
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/9/26 @url:https://leetcode-cn.com/problems/palindrome-number/ @desc: 9. 回文数 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右...
e614af7ab6facbd8e3509aabde8c90dab6a2876a
GongFuXiong/leetcode
/topic4_dynamic_planning_study/T120_minimumTotal/demo.py
1,214
3.6875
4
''' 120. 三角形最小路径和 给定一个三角形,找出自顶向下的最小路径和。每一步只能移动到下一行中相邻的结点上。 相邻的结点 在这里指的是 下标 与 上一层结点下标 相同或者等于 上一层结点下标 + 1 的两个结点。 例如,给定三角形: [ [2], [3,4], [6,5,7], [4,1,8,3] ] ''' class Solution: def minimumTotal(self, triangle): triangle_len = len(triangle) ...
82135aa10202af887f9d82fd9aab8c8990ed3888
GongFuXiong/leetcode
/topic5_string/T242_isAnagram/interview.py
1,003
3.59375
4
''' 242. 有效的字母异位词 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 示例 1: 输入: s = "anagram", t = "nagaram" 输出: true 示例 2: 输入: s = "rat", t = "car" 输出: false ''' class Solution: def isAnagram(self, s, t): if len(s) != len(t): return False s_dict = {} ...
2fdc81bdfbd5baf88c5371e7c5f80874fc88fb87
GongFuXiong/leetcode
/topic9_hash_table/compareTime.py
1,256
3.59375
4
import time # 读取小文件 small_file = "small.txt" small_list = [] small_set = set() with open(small_file,"r",encoding="utf-8") as f: line = f.readline() while line: small_list.append(line) small_set.add(line) line = f.readline() print("小样本情况下") time_start=time.time() print(f"200 in small_li...
80d9ff377e6fddac8a020ba37542aa702032b7cb
GongFuXiong/leetcode
/topic2_arr/T1_twoSum/demo.py
896
3.828125
4
''' 1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1] ''' class Solution: def twoSum(self, nums, target): temp_dict = {} ...
a57ab7ffd6b16a039c8513f0d0c31c9570a7391d
GongFuXiong/leetcode
/old/t20190914_productExceptSelf/productExceptSelf.py
1,274
3.546875
4
#!/usr/bin/env python # encoding: utf-8 ''' @author: KM @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. @contact: yangkm601@gmail.com @software: garner @time: 2019/9/12 @url:https://leetcode-cn.com/problems/decode-ways/ @desc: 238. 除自身以外数组的乘积 给定长度为 n 的整数数组 nums,其中 n > 1,返...
0682d7cb9ca03d0028b95c8458fd1f051127f813
tcheng878/DailyAlgos
/find_medium_from_data_stream.py
1,086
3.546875
4
class MedianFinder(object): def __init__(self): """ initialize your data structure here. """ self.lis = [] def addNum(self, num): """ :type num: int :rtype: None """ if len(self.lis) == 0 or num >= self.lis[-1]: ...
15060ebd2c62e72fd02845f32794a7e2e547ac3e
ikejs/interview-drills
/hasCorrectlyBalancedParentheses.py
469
3.734375
4
str = "Make (School is) awesome. The quick (brown fox (jumped over) the lazy dog." # change string to have balanced parentheses or not def hasCorrectlyBalancedParentheses(string): closingParenthesesNeeded = 0 for char in string: if char == "(": closingParenthesesNeeded += 1 if char == ")": clos...
f980a095e3297b7bd71f2114b6c60917e62fc8fb
Kestrel67/Python-Libraries
/Arithmetic/divisors.py
450
3.78125
4
from math import sqrt # diviseurs de n (dummy) def divisors(n, naturals = True): assert isinstance(n, int) if n == 1: return {1} d = set() p = 1 n = abs(n) while p <= sqrt(n): if not n % p: d.add(p) d.add(n // p) p += 1 if not natu...
151744dfd588c45596b06c39eb3d6c570de0f2b2
Kestrel67/Python-Libraries
/Arithmetic/prime.py
1,738
3.8125
4
from math import sqrt from random import randrange # test de primalité naif def prime(n): if n <= 1 or not n & 1: return False f = 3 while f <= int(sqrt(n)): if n % f == 0: return False f += 2 return True # test de primalité évolué (Fermat) # primes : bases à tester (supposés premiers) # e...
d1910bdb20b30e8b1fae7ac29dbba272352ef1d1
kickergit/Ardisik-Sayilari-Toplama---Consecutive-Number-Addition
/ArdisikSayiToplama.py
386
3.734375
4
#ardışık sayıları toplama gahos efendi print("ARDIŞIK SAYILARI TOPLAMA") toplam = 0 baslangic = int(input("Başlangıç (Tam sayı giriniz!):" )) bitis = int(input("Bitiş (Tam sayı giriniz!):")) +1 artis = int(input("Artış Miktari (Tam sayı giriniz!)" )) for a in range(baslangic, bitis, artis): toplam+=a ...
08c9bb9ca22e3ab6c80599c94981c8b3f9f078ea
sandeepdj/learnPython
/03_variables.py
919
3.84375
4
#A Python variable is a reserved memory location to store values. #In other words, a variable in a python program gives data to the computer for processing. #Data_Types - Numbers, List, Tuple, Strings, Dictionary # Declare variable a = 100 print(a) # print a -in python 2 # Redeclare varibale a = 200 print(a) #...
e6832dcb6683e8d84e47aaffe2d26316ecec8967
widderslainte/langmaker
/langmaker/lexeme.py
1,524
3.625
4
''' System for generating lexemes, lemmas, and words, building on existing linguistic data. Come here for a dictionary ''' from langmaker.morphology import Morphology class Lexeme(object): ''' works with words ''' dictionary = {} def __init__(self, morphology=None): self.morphology = morphology or...
2b027485364886cb4d1c65f95ccdaa4bd8090fd1
svkostrov/Learning_something
/python/mnojestva.py
781
3.734375
4
a = {i ** 2 for i in range (10)} print(type(a), "\n") print("Множество а", a, "\n") print("Добавляем во множество а 666\n") c = 666 a.add(c) print("Содержится ли теперь 666 во множистеве?", c in a, '\n') x={'11', '22', "33"} print("Множество x", x) if 1: a.isdisjoint(x) #если не имеет общих элементов print ("а и x ...
82ee5fe6b4eca15f787abc1ffed38e5f60fcb3e8
svkostrov/Learning_something
/python_tkinter/tkinter1.py
593
3.71875
4
from tkinter import * root = Tk() top_frame = Frame(root) top_frame.pack(side=TOP) bottom_frame = Frame(root) bottom_frame.pack(side=BOTTOM) label = Label(top_frame, text="Hello") button1 = Button(top_frame, text="Кнопка 1", fg="red") button2 = Button(top_frame, text="Кнопка 2", fg="blue") button3 = Button(top_fram...
918b3a7163db3c1fc751bc128487c381f2a6807e
VeraHakobyan/HW3
/LineSegmentIntersection.py
484
3.6875
4
a1 = float(input()) b1 = float(input()) lst1 = [a1, b1] lst1.sort() a2 = float(input()) b2 = float(input()) lst2 = [a2, b2] lst2.sort() if lst1[0] < lst2[0]: if lst2[1] > lst1[1] > lst2[0]: print(lst1[1] - lst2[0]) elif lst1[1] > lst2[1]: print(lst2[1] - lst2[0]) else: print(0) el...
28cc780c496e21090cd63cee2f0e07e053fbf038
MishRanu/udemy-python-masterclass
/adventuregame.py
1,292
3.953125
4
location = {0: "You are staring at the damn screen", 1: "Baner road", 2: "Dmart crossing", 3: "vasant vihar", 4: "sky fitness", 5: "pashan" } exits = {0: {"Q":0}, 1:{"W":2, "E": 3, "N":5, "S": 4, "Q": 0}, 2: {"W": 5, "Q": 0}, ...
64ff3cb6699e46f85427eab24751a90cb0bb7215
MishRanu/udemy-python-masterclass
/sets_challenge.py
658
4.34375
4
# Create a program that takes some text and returns a list of # all the characters in the text that are not vowels, sorted in # alphabetical order. # # You can either enter the text from the keyboard or # initialise a string variable with the string. vowels_set = frozenset(('a', 'e', 'i', 'o', 'u')) vowels_set2 = froz...
9c1ff5c3d6a2cafec41b73d82bdf7329fe036a83
MishRanu/udemy-python-masterclass
/rangeschallenge.py
1,093
4.25
4
# Experiment with different ranges and slices to get a feel for how they work. # Remember that you can print the range as well as iterating through it to print # its values, to check that your ranges are what you expected. # You may also want to include things like. # o = range(0, 100, 4) print(o) p = o[::5] print(p) f...
528aa830e460d86342ad3d48634d7fcb435fbe48
MishRanu/udemy-python-masterclass
/ordered_sets_with_tuples.py
1,627
4.375
4
t = "a", "b", "c" print(t) print("a", "b", "c") print({"a", "b", "c"}) welcome = "Welcome to the Nightmare", "Alice Cooper", 1975 bad = 'Bad Comany', "Bad Company", 1974 budgie = "Budgie", "Budgies", 1984 print(welcome) print(welcome[1]) budgie = "Piece of papers", "Pickwick Company", 1981 budgie = budgie[0], "Anur...
3724a6694f7775a24f4155f4a17941c12ff9fc3b
brightdragom/DataProgramming
/py-sources/03-01-arrithop-산술.py
284
3.953125
4
#arithmetic operator a = 5 b = 3 x = a + b print('a + b = ', a + b) print(a + b) print(x) print('a - b = ', a - b) print('a * b = ', a * b) print('a / b = ', a / b) #그냥 결과 print('a ** b = ', a ** b) #제곱 print('a // b = ', a // b) #몫 print('a % b = ', a % b) #나머지
43d542d2a9050ac064966f48ee376598879145ea
brightdragom/DataProgramming
/py-sources/02-02-list-range.py
569
4.1875
4
# range( ) # range ( start, stop, [step] ) _ start 생략가능(0번) 인덱스번호, # step-1까지 : 종료 인덱스번호의 자료 , step : 기본 1(증가), -1(감소) lst = list(range(5)) lst2 = list(range(0,5)) lst3 = list(range(1,5)) lst33 = list(range(-5, 5)) print(lst) print(lst2) print(lst3) print(lst33) print('=' * 20) lst4 = list(range(1,6)) lst5 = list(ra...