Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jinhua115315
Python
提交
b838f104
P
Python
项目概览
jinhua115315
/
Python
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
P
Python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b838f104
编写于
11月 16, 2019
作者:
C
Christian Clauss
提交者:
John Law
11月 15, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix indentation contains tabs (flake8 E101,W191) (#1573)
上级
dbaedd4e
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
232 addition
and
232 deletion
+232
-232
.travis.yml
.travis.yml
+1
-1
backtracking/all_combinations.py
backtracking/all_combinations.py
+3
-3
backtracking/all_permutations.py
backtracking/all_permutations.py
+9
-9
backtracking/all_subsequences.py
backtracking/all_subsequences.py
+9
-9
backtracking/sum_of_subsets.py
backtracking/sum_of_subsets.py
+10
-10
boolean_algebra/quine_mc_cluskey.py
boolean_algebra/quine_mc_cluskey.py
+27
-27
ciphers/xor_cipher.py
ciphers/xor_cipher.py
+55
-55
compression/peak_signal_to_noise_ratio.py
compression/peak_signal_to_noise_ratio.py
+1
-1
data_structures/stacks/infix_to_prefix_conversion.py
data_structures/stacks/infix_to_prefix_conversion.py
+1
-1
data_structures/stacks/postfix_evaluation.py
data_structures/stacks/postfix_evaluation.py
+1
-1
dynamic_programming/rod_cutting.py
dynamic_programming/rod_cutting.py
+90
-90
other/magicdiamondpattern.py
other/magicdiamondpattern.py
+9
-9
other/nested_brackets.py
other/nested_brackets.py
+3
-3
project_euler/problem_27/problem_27_sol1.py
project_euler/problem_27/problem_27_sol1.py
+11
-11
searches/interpolation_search.py
searches/interpolation_search.py
+2
-2
未找到文件。
.travis.yml
浏览文件 @
b838f104
...
...
@@ -5,7 +5,7 @@ before_install: pip install --upgrade pip setuptools
install
:
pip install -r requirements.txt
before_script
:
-
black --check . ||
true
-
flake8 . --count --select=E
9,F4,F63,F7,F82
--show-source --statistics
-
flake8 . --count --select=E
101,E9,F4,F63,F7,F82,W191
--show-source --statistics
script
:
-
scripts/validate_filenames.py
# no uppercase, no spaces, in a directory
-
mypy --ignore-missing-imports .
...
...
backtracking/all_combinations.py
浏览文件 @
b838f104
# -*- coding: utf-8 -*-
"""
In this problem, we want to determine all possible combinations of k
numbers out of 1 ... n. We use backtracking to solve this problem.
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!)))
In this problem, we want to determine all possible combinations of k
numbers out of 1 ... n. We use backtracking to solve this problem.
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!)))
"""
...
...
backtracking/all_permutations.py
浏览文件 @
b838f104
"""
In this problem, we want to determine all possible permutations
of the given sequence. We use backtracking to solve this problem.
In this problem, we want to determine all possible permutations
of the given sequence. We use backtracking to solve this problem.
Time complexity: O(n! * n),
where n denotes the length of the given sequence.
Time complexity: O(n! * n),
where n denotes the length of the given sequence.
"""
...
...
@@ -13,10 +13,10 @@ def generate_all_permutations(sequence):
def
create_state_space_tree
(
sequence
,
current_sequence
,
index
,
index_used
):
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly len(sequence) - index children.
It terminates when it reaches the end of the given sequence.
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly len(sequence) - index children.
It terminates when it reaches the end of the given sequence.
"""
if
index
==
len
(
sequence
):
print
(
current_sequence
)
...
...
@@ -32,7 +32,7 @@ def create_state_space_tree(sequence, current_sequence, index, index_used):
"""
remove the comment to take an input from the user
remove the comment to take an input from the user
print("Enter the elements")
sequence = list(map(int, input().split()))
...
...
backtracking/all_subsequences.py
浏览文件 @
b838f104
"""
In this problem, we want to determine all possible subsequences
of the given sequence. We use backtracking to solve this problem.
In this problem, we want to determine all possible subsequences
of the given sequence. We use backtracking to solve this problem.
Time complexity: O(2^n),
where n denotes the length of the given sequence.
Time complexity: O(2^n),
where n denotes the length of the given sequence.
"""
...
...
@@ -13,10 +13,10 @@ def generate_all_subsequences(sequence):
def
create_state_space_tree
(
sequence
,
current_subsequence
,
index
):
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly two children.
It terminates when it reaches the end of the given sequence.
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly two children.
It terminates when it reaches the end of the given sequence.
"""
if
index
==
len
(
sequence
):
print
(
current_subsequence
)
...
...
@@ -29,7 +29,7 @@ def create_state_space_tree(sequence, current_subsequence, index):
"""
remove the comment to take an input from the user
remove the comment to take an input from the user
print("Enter the elements")
sequence = list(map(int, input().split()))
...
...
backtracking/sum_of_subsets.py
浏览文件 @
b838f104
"""
The sum-of-subsetsproblem states that a set of non-negative integers, and a value M,
determine all possible subsets of the given set whose summation sum equal to given M.
The sum-of-subsetsproblem states that a set of non-negative integers, and a value M,
determine all possible subsets of the given set whose summation sum equal to given M.
Summation of the chosen numbers must be equal to given number M and one number can
be used only once.
Summation of the chosen numbers must be equal to given number M and one number can
be used only once.
"""
...
...
@@ -18,12 +18,12 @@ def generate_sum_of_subsets_soln(nums, max_sum):
def
create_state_space_tree
(
nums
,
max_sum
,
num_index
,
path
,
result
,
remaining_nums_sum
):
"""
Creates a state space tree to iterate through each branch using DFS.
It terminates the branching of a node when any of the two conditions
given below satisfy.
This algorithm follows depth-fist-search and backtracks when the node is not branchable.
Creates a state space tree to iterate through each branch using DFS.
It terminates the branching of a node when any of the two conditions
given below satisfy.
This algorithm follows depth-fist-search and backtracks when the node is not branchable.
"""
"""
if
sum
(
path
)
>
max_sum
or
(
remaining_nums_sum
+
sum
(
path
))
<
max_sum
:
return
if
sum
(
path
)
==
max_sum
:
...
...
@@ -41,7 +41,7 @@ def create_state_space_tree(nums, max_sum, num_index, path, result, remaining_nu
"""
remove the comment to take an input from the user
remove the comment to take an input from the user
print("Enter the elements")
nums = list(map(int, input().split()))
...
...
boolean_algebra/quine_mc_cluskey.py
浏览文件 @
b838f104
def
compare_string
(
string1
,
string2
):
"""
>>> compare_string('0010','0110')
'0_10'
>>> compare_string('0110','1101')
-1
"""
>>> compare_string('0010','0110')
'0_10'
>>> compare_string('0110','1101')
-1
"""
l1
=
list
(
string1
)
l2
=
list
(
string2
)
count
=
0
...
...
@@ -21,9 +21,9 @@ def compare_string(string1, string2):
def
check
(
binary
):
"""
>>> check(['0.00.01.5'])
['0.00.01.5']
"""
>>> check(['0.00.01.5'])
['0.00.01.5']
"""
pi
=
[]
while
1
:
check1
=
[
"$"
]
*
len
(
binary
)
...
...
@@ -45,9 +45,9 @@ def check(binary):
def
decimal_to_binary
(
no_of_variable
,
minterms
):
"""
>>> decimal_to_binary(3,[1.5])
['0.00.01.5']
"""
>>> decimal_to_binary(3,[1.5])
['0.00.01.5']
"""
temp
=
[]
s
=
""
for
m
in
minterms
:
...
...
@@ -61,12 +61,12 @@ def decimal_to_binary(no_of_variable, minterms):
def
is_for_table
(
string1
,
string2
,
count
):
"""
>>> is_for_table('__1','011',2)
True
>>> is_for_table('01_','001',1)
False
"""
>>> is_for_table('__1','011',2)
True
>>> is_for_table('01_','001',1)
False
"""
l1
=
list
(
string1
)
l2
=
list
(
string2
)
count_n
=
0
...
...
@@ -81,12 +81,12 @@ def is_for_table(string1, string2, count):
def
selection
(
chart
,
prime_implicants
):
"""
>>> selection([[1]],['0.00.01.5'])
['0.00.01.5']
>>> selection([[1]],['0.00.01.5'])
['0.00.01.5']
"""
>>> selection([[1]],['0.00.01.5'])
['0.00.01.5']
>>> selection([[1]],['0.00.01.5'])
['0.00.01.5']
"""
temp
=
[]
select
=
[
0
]
*
len
(
chart
)
for
i
in
range
(
len
(
chart
[
0
])):
...
...
@@ -128,9 +128,9 @@ def selection(chart, prime_implicants):
def
prime_implicant_chart
(
prime_implicants
,
binary
):
"""
>>> prime_implicant_chart(['0.00.01.5'],['0.00.01.5'])
[[1]]
"""
>>> prime_implicant_chart(['0.00.01.5'],['0.00.01.5'])
[[1]]
"""
chart
=
[[
0
for
x
in
range
(
len
(
binary
))]
for
x
in
range
(
len
(
prime_implicants
))]
for
i
in
range
(
len
(
prime_implicants
)):
count
=
prime_implicants
[
i
].
count
(
"_"
)
...
...
ciphers/xor_cipher.py
浏览文件 @
b838f104
"""
author: Christian Bender
date: 21.12.2017
class: XORCipher
This class implements the XOR-cipher algorithm and provides
some useful methods for encrypting and decrypting strings and
files.
Overview about methods
- encrypt : list of char
- decrypt : list of char
- encrypt_string : str
- decrypt_string : str
- encrypt_file : boolean
- decrypt_file : boolean
author: Christian Bender
date: 21.12.2017
class: XORCipher
This class implements the XOR-cipher algorithm and provides
some useful methods for encrypting and decrypting strings and
files.
Overview about methods
- encrypt : list of char
- decrypt : list of char
- encrypt_string : str
- decrypt_string : str
- encrypt_file : boolean
- decrypt_file : boolean
"""
class
XORCipher
(
object
):
def
__init__
(
self
,
key
=
0
):
"""
simple constructor that receives a key or uses
default key = 0
"""
simple constructor that receives a key or uses
default key = 0
"""
# private field
self
.
__key
=
key
def
encrypt
(
self
,
content
,
key
):
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
# precondition
assert
isinstance
(
key
,
int
)
and
isinstance
(
content
,
str
)
...
...
@@ -55,11 +55,11 @@ class XORCipher(object):
def
decrypt
(
self
,
content
,
key
):
"""
input: 'content' of type list and 'key' of type int
output: decrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type list and 'key' of type int
output: decrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
# precondition
assert
isinstance
(
key
,
int
)
and
isinstance
(
content
,
list
)
...
...
@@ -80,11 +80,11 @@ class XORCipher(object):
def
encrypt_string
(
self
,
content
,
key
=
0
):
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
# precondition
assert
isinstance
(
key
,
int
)
and
isinstance
(
content
,
str
)
...
...
@@ -105,11 +105,11 @@ class XORCipher(object):
def
decrypt_string
(
self
,
content
,
key
=
0
):
"""
input: 'content' of type string and 'key' of type int
output: decrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type string and 'key' of type int
output: decrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
# precondition
assert
isinstance
(
key
,
int
)
and
isinstance
(
content
,
str
)
...
...
@@ -130,12 +130,12 @@ class XORCipher(object):
def
encrypt_file
(
self
,
file
,
key
=
0
):
"""
input: filename (str) and a key (int)
output: returns true if encrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: filename (str) and a key (int)
output: returns true if encrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
# precondition
assert
isinstance
(
file
,
str
)
and
isinstance
(
key
,
int
)
...
...
@@ -155,12 +155,12 @@ class XORCipher(object):
def
decrypt_file
(
self
,
file
,
key
):
"""
input: filename (str) and a key (int)
output: returns true if decrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: filename (str) and a key (int)
output: returns true if decrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
# precondition
assert
isinstance
(
file
,
str
)
and
isinstance
(
key
,
int
)
...
...
@@ -195,11 +195,11 @@ class XORCipher(object):
# print(crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key))
# if (crypt.encrypt_file("test.txt",key)):
#
print("encrypt successful")
#
print("encrypt successful")
# else:
#
print("encrypt unsuccessful")
#
print("encrypt unsuccessful")
# if (crypt.decrypt_file("encrypt.out",key)):
#
print("decrypt successful")
#
print("decrypt successful")
# else:
#
print("decrypt unsuccessful")
#
print("decrypt unsuccessful")
compression/peak_signal_to_noise_ratio.py
浏览文件 @
b838f104
"""
Peak signal-to-noise ratio - PSNR - https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
Peak signal-to-noise ratio - PSNR - https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
Soruce: https://tutorials.techonical.com/how-to-calculate-psnr-value-of-two-images-using-python/
"""
...
...
data_structures/stacks/infix_to_prefix_conversion.py
浏览文件 @
b838f104
...
...
@@ -11,7 +11,7 @@ Enter an Infix Equation = a + b ^c
a | + | cb^a
| | cb^a+
a+b^c (Infix) -> +a^bc (Prefix)
a+b^c (Infix) -> +a^bc (Prefix)
"""
...
...
data_structures/stacks/postfix_evaluation.py
浏览文件 @
b838f104
...
...
@@ -14,7 +14,7 @@ Enter a Postfix Equation (space separated) = 5 6 9 * +
| pop(5) |
+ | push(5+54) | 59
Result = 59
Result = 59
"""
import
operator
as
op
...
...
dynamic_programming/rod_cutting.py
浏览文件 @
b838f104
...
...
@@ -13,28 +13,28 @@ pieces separately or not cutting it at all if the price of it is the maximum obt
def
naive_cut_rod_recursive
(
n
:
int
,
prices
:
list
):
"""
Solves the rod-cutting problem via naively without using the benefit of dynamic programming.
The results is the same sub-problems are solved several times leading to an exponential runtime
Solves the rod-cutting problem via naively without using the benefit of dynamic programming.
The results is the same sub-problems are solved several times leading to an exponential runtime
Runtime: O(2^n)
Runtime: O(2^n)
Arguments
-------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
Arguments
-------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices for each piece.
Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices for each piece.
Examples
--------
>>> naive_cut_rod_recursive(4, [1, 5, 8, 9])
10
>>> naive_cut_rod_recursive(10, [1, 5, 8, 9, 10, 17, 17, 20, 24, 30])
30
"""
Examples
--------
>>> naive_cut_rod_recursive(4, [1, 5, 8, 9])
10
>>> naive_cut_rod_recursive(10, [1, 5, 8, 9, 10, 17, 17, 20, 24, 30])
30
"""
_enforce_args
(
n
,
prices
)
if
n
==
0
:
...
...
@@ -50,33 +50,33 @@ def naive_cut_rod_recursive(n: int, prices: list):
def
top_down_cut_rod
(
n
:
int
,
prices
:
list
):
"""
Constructs a top-down dynamic programming solution for the rod-cutting problem
via memoization. This function serves as a wrapper for _top_down_cut_rod_recursive
Runtime: O(n^2)
Arguments
--------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
Note
----
For convenience and because Python's lists using 0-indexing, length(max_rev) = n + 1,
to accommodate for the revenue obtainable from a rod of length 0.
Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices for each piece.
Examples
-------
>>> top_down_cut_rod(4, [1, 5, 8, 9])
10
>>> top_down_cut_rod(10, [1, 5, 8, 9, 10, 17, 17, 20, 24, 30])
30
"""
Constructs a top-down dynamic programming solution for the rod-cutting problem
via memoization. This function serves as a wrapper for _top_down_cut_rod_recursive
Runtime: O(n^2)
Arguments
--------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
Note
----
For convenience and because Python's lists using 0-indexing, length(max_rev) = n + 1,
to accommodate for the revenue obtainable from a rod of length 0.
Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices for each piece.
Examples
-------
>>> top_down_cut_rod(4, [1, 5, 8, 9])
10
>>> top_down_cut_rod(10, [1, 5, 8, 9, 10, 17, 17, 20, 24, 30])
30
"""
_enforce_args
(
n
,
prices
)
max_rev
=
[
float
(
"-inf"
)
for
_
in
range
(
n
+
1
)]
return
_top_down_cut_rod_recursive
(
n
,
prices
,
max_rev
)
...
...
@@ -84,23 +84,23 @@ def top_down_cut_rod(n: int, prices: list):
def
_top_down_cut_rod_recursive
(
n
:
int
,
prices
:
list
,
max_rev
:
list
):
"""
Constructs a top-down dynamic programming solution for the rod-cutting problem
via memoization.
Runtime: O(n^2)
Arguments
--------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
max_rev: list, the computed maximum revenue for a piece of rod.
``max_rev[i]`` is the maximum revenue obtainable for a rod of length ``i``
Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices for each piece.
"""
Constructs a top-down dynamic programming solution for the rod-cutting problem
via memoization.
Runtime: O(n^2)
Arguments
--------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
max_rev: list, the computed maximum revenue for a piece of rod.
``max_rev[i]`` is the maximum revenue obtainable for a rod of length ``i``
Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices for each piece.
"""
if
max_rev
[
n
]
>=
0
:
return
max_rev
[
n
]
elif
n
==
0
:
...
...
@@ -120,28 +120,28 @@ def _top_down_cut_rod_recursive(n: int, prices: list, max_rev: list):
def
bottom_up_cut_rod
(
n
:
int
,
prices
:
list
):
"""
Constructs a bottom-up dynamic programming solution for the rod-cutting problem
Runtime: O(n^2)
Arguments
----------
n: int, the maximum length of the rod.
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
Returns
-------
The maximum revenue obtainable from cutting a rod of length n given
the prices for each piece of rod p.
Examples
-------
>>> bottom_up_cut_rod(4, [1, 5, 8, 9])
10
>>> bottom_up_cut_rod(10, [1, 5, 8, 9, 10, 17, 17, 20, 24, 30])
30
"""
Constructs a bottom-up dynamic programming solution for the rod-cutting problem
Runtime: O(n^2)
Arguments
----------
n: int, the maximum length of the rod.
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
Returns
-------
The maximum revenue obtainable from cutting a rod of length n given
the prices for each piece of rod p.
Examples
-------
>>> bottom_up_cut_rod(4, [1, 5, 8, 9])
10
>>> bottom_up_cut_rod(10, [1, 5, 8, 9, 10, 17, 17, 20, 24, 30])
30
"""
_enforce_args
(
n
,
prices
)
# length(max_rev) = n + 1, to accommodate for the revenue obtainable from a rod of length 0.
...
...
@@ -160,15 +160,15 @@ def bottom_up_cut_rod(n: int, prices: list):
def
_enforce_args
(
n
:
int
,
prices
:
list
):
"""
Basic checks on the arguments to the rod-cutting algorithms
Basic checks on the arguments to the rod-cutting algorithms
n: int, the length of the rod
prices: list, the price list for each piece of rod.
n: int, the length of the rod
prices: list, the price list for each piece of rod.
Throws ValueError:
Throws ValueError:
if n is negative or there are fewer items in the price list than the length of the rod
"""
if n is negative or there are fewer items in the price list than the length of the rod
"""
if
n
<
0
:
raise
ValueError
(
f
"n must be greater than or equal to 0. Got n =
{
n
}
"
)
...
...
other/magicdiamondpattern.py
浏览文件 @
b838f104
...
...
@@ -3,9 +3,9 @@
# Function to print upper half of diamond (pyramid)
def
floyd
(
n
):
"""
Parameters:
n : size of pattern
"""
Parameters:
n : size of pattern
"""
for
i
in
range
(
0
,
n
):
for
j
in
range
(
0
,
n
-
i
-
1
):
# printing spaces
print
(
" "
,
end
=
""
)
...
...
@@ -17,9 +17,9 @@ def floyd(n):
# Function to print lower half of diamond (pyramid)
def
reverse_floyd
(
n
):
"""
Parameters:
n : size of pattern
"""
Parameters:
n : size of pattern
"""
for
i
in
range
(
n
,
0
,
-
1
):
for
j
in
range
(
i
,
0
,
-
1
):
# printing stars
print
(
"* "
,
end
=
""
)
...
...
@@ -31,9 +31,9 @@ def reverse_floyd(n):
# Function to print complete diamond pattern of "*"
def
pretty_print
(
n
):
"""
Parameters:
n : size of pattern
"""
Parameters:
n : size of pattern
"""
if
n
<=
0
:
print
(
" ... .... nothing printing :("
)
return
...
...
other/nested_brackets.py
浏览文件 @
b838f104
...
...
@@ -3,9 +3,9 @@ The nested brackets problem is a problem that determines if a sequence of
brackets are properly nested. A sequence of brackets s is considered properly nested
if any of the following conditions are true:
- s is empty
- s has the form (U) or [U] or {U} where U is a properly nested string
- s has the form VW where V and W are properly nested strings
- s is empty
- s has the form (U) or [U] or {U} where U is a properly nested string
- s has the form VW where V and W are properly nested strings
For example, the string "()()[()]" is properly nested but "[(()]" is not.
...
...
project_euler/problem_27/problem_27_sol1.py
浏览文件 @
b838f104
...
...
@@ -39,17 +39,17 @@ def is_prime(k: int) -> bool:
def
solution
(
a_limit
:
int
,
b_limit
:
int
)
->
int
:
"""
>>> solution(1000, 1000)
-59231
>>> solution(200, 1000)
-59231
>>> solution(200, 200)
-4925
>>> solution(-1000, 1000)
0
>>> solution(-1000, -1000)
0
"""
>>> solution(1000, 1000)
-59231
>>> solution(200, 1000)
-59231
>>> solution(200, 200)
-4925
>>> solution(-1000, 1000)
0
>>> solution(-1000, -1000)
0
"""
longest
=
[
0
,
0
,
0
]
# length, a, b
for
a
in
range
((
a_limit
*
-
1
)
+
1
,
a_limit
):
for
b
in
range
(
2
,
b_limit
):
...
...
searches/interpolation_search.py
浏览文件 @
b838f104
...
...
@@ -113,7 +113,7 @@ if __name__ == "__main__":
import
sys
"""
user_input = input('Enter numbers separated by comma:
\n
').strip()
user_input = input('Enter numbers separated by comma:
\n
').strip()
collection = [int(item) for item in user_input.split(',')]
try:
__assert_sorted(collection)
...
...
@@ -122,7 +122,7 @@ if __name__ == "__main__":
target_input = input('Enter a single number to be found in the list:
\n
')
target = int(target_input)
"""
"""
debug
=
0
if
debug
==
1
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录