Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 865296e

Browse files
committed
docs: documentation, ci/cd and apply Black formatter.
1 parent b66e59e commit 865296e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2049
-1144
lines changed

.github/workflows/computer_programming.yaml

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
spell_check:
10+
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: check out repo
13+
- name: Check Repository
1414
uses: actions/checkout@v4
15-
- name: spell check
15+
- name: Spell Check
1616
uses: rojopolis/[email protected]
17-
with:
17+
with:
18+
task_name: English
1819
output_file: spellcheck-output.txt
20+
- name: Install Pipenv
21+
run: python -m pip install pipenv
22+
- name: Install Dependencies
23+
run: pipenv sync --system -d
24+
- name: Style Check
25+
run: black --check .
26+
- name: Run Tests
27+
run: pytest

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ RUN apt-get update \
1010
RUN apt-get install python3 -y && apt-get install python3-pip -y && apt-get install pipenv -y && ln -s /usr/bin/python3 /usr/bin/python
1111
RUN apt-get install ghc -y
1212

13+
RUN pipenv sync --system -d
14+
1315
RUN adduser -u 5678 --disabled-password --gecos "" computer_programming && chown -R computer_programming /computer_programming
1416
USER computer_programming

Pipfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
pyspelling = "==2.10"
7+
numpy = "*"
8+
matplotlib = "*"
9+
graphviz = "*"
810

911
[dev-packages]
12+
pyspelling = "*"
13+
ipykernel = "*"
14+
pytest = "*"
15+
black = "*"
1016

1117
[requires]
1218
python_version = "3.13"

Pipfile.lock

+865-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# What is Computer Programming?
2-
32
![build status](https://github.com/praisetompane/computer_programming/actions/workflows/computer_programming.yaml/badge.svg) <br>
43

54
## Objectives
65
- Attempts to define a unified scientific discipline of computer programming independent of programming language implementations.
76

8-
## Definitions:
7+
## Definitions
98
- def computer programming: the act of extending or changing a system's functionality (Haridi and Van Roy, 2004:xv).
109
- formal: ???
1110
- in words: ???
@@ -104,14 +103,12 @@ pyspelling -c spellcheck.yaml
104103
```
105104

106105

107-
## References:
108-
- Van Roy P, Haridi S. 2004. Concepts, Techniques and Models of Computer Programming. The MIT Press.
109-
- Sipser, M. 2012. Introduction to the Theory of Computation. 3rd ed. Cengage Learning.
110-
111-
# Legend:
112-
113-
**Q**: Question for later research
106+
## References
107+
- Van Roy P, Haridi S. 2004. Concepts, Techniques and Models of Computer Programming. The MIT Press.
108+
- Sipser, M. 2012. Introduction to the Theory of Computation. 3rd ed. Cengage Learning.
114109

110+
# Legend
111+
**Q**: Question for later research <br>
115112
**MYINC**: My Insight/Conjecture [Could Be Unoriginal/False and Likely Is]
116113

117114
**Disclaimer**: This is an ongoing and incomplete project to unpack these concepts and serves as my distributed memory.

programs_per_computational_model/0_declarative/arrays_and_strings/1.9.1. string-rotation.py

+52-52
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
"""
2-
Context:
3-
Given:
4-
method isSubstring
5-
checks if one word is a substring of another
6-
7-
Definitions:
8-
rotation = letters moved n places left/right
9-
split string into two parts
10-
x,y
11-
rotated string = yx
12-
original string = xy
13-
--------------------------------------
14-
s1 = abcd
15-
s2 = cdab
16-
17-
s1
18-
x = ab
19-
y = cd
20-
yx = cdab = s2
21-
22-
is not:
23-
shuffling letters into arbitary positions
24-
25-
Objective:
26-
Given two strings
27-
s1 and s2
28-
29-
Write Algorithm to check
30-
if s2 is a
31-
rotation
32-
of s1
33-
34-
Assumptions:
35-
s1 and s2 are same length
36-
Constraints:
37-
Only 1 call to isSubstring
38-
39-
Algorithm flow:
40-
Using definition of rotation
41-
yxyx contains xy
42-
cdabcd contains abcd
43-
44-
Flow:
45-
s2contact = concat s2 and s2
46-
check if s1 isSubstring of s2contact
47-
Possible Solutions
48-
49-
Example(s):
2+
Context:
3+
Given:
4+
method isSubstring
5+
checks if one word is a substring of another
6+
7+
Definitions:
8+
rotation = letters moved n places left/right
9+
split string into two parts
10+
x,y
11+
rotated string = yx
12+
original string = xy
13+
--------------------------------------
14+
s1 = abcd
15+
s2 = cdab
16+
17+
s1
18+
x = ab
19+
y = cd
20+
yx = cdab = s2
21+
22+
is not:
23+
shuffling letters into arbitary positions
24+
25+
Objective:
26+
Given two strings
27+
s1 and s2
28+
29+
Write Algorithm to check
30+
if s2 is a
31+
rotation
32+
of s1
33+
34+
Assumptions:
35+
s1 and s2 are same length
36+
Constraints:
37+
Only 1 call to isSubstring
38+
39+
Algorithm flow:
40+
Using definition of rotation
41+
yxyx contains xy
42+
cdabcd contains abcd
43+
44+
Flow:
45+
s2contact = concat s2 and s2
46+
check if s1 isSubstring of s2contact
47+
Possible Solutions
48+
49+
Example(s):
5050
5151
5252
"""
@@ -59,10 +59,10 @@ def is_substring(search_string, source_string):
5959
return is_substring(s1, s2 + s2)
6060

6161

62-
assert (string_rotation("waterbottle", "erbottlewat")) # True
63-
assert (string_rotation("abcd", "cdab")) # True
64-
assert (not string_rotation("abcd", "cdaob")) # False
65-
assert (not string_rotation("abcd", "")) # False
62+
assert string_rotation("waterbottle", "erbottlewat") # True
63+
assert string_rotation("abcd", "cdab") # True
64+
assert not string_rotation("abcd", "cdaob") # False
65+
assert not string_rotation("abcd", "") # False
6666
print("completed successfully")
6767

6868
"""

programs_per_computational_model/0_declarative/arrays_and_strings/min_max_sum.py

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
"""
2-
Context:
3-
Given:
4-
five positive integers
5-
6-
Objective:
7-
find:
8-
minimum sum of four of the integers
9-
maximum sum of four of the integers
10-
print the min and max
11-
on one line, space separated
12-
13-
Example:
14-
[1,3,5,7,9]
15-
min_sum = 1 + 3 + 5 + 7
16-
max_xum = 3 + 5 + 7 + 9
17-
18-
Assumptions():?
19-
Is array always sorted? No mention, there assume it's not
20-
output can 32 bit integer
21-
22-
Constraints:
23-
1 <= arr[i] <= 10^9 : array value range
24-
require 64 bit integer
25-
26-
Flow:
27-
sort array
28-
array_size = 5
29-
min_sum = sum(arr[:array_size])
30-
max_sum = sum(arr[2:])
31-
print(min_sum max_sum)
32-
33-
Performance
34-
N = size of array
35-
S = O(NlogN): sorting time
36-
MIS = O(N - 1) = 𝑂(𝑁) : minimum sum
37-
MAS = O(N - 1) = 𝑂(𝑁) : maximum sum
38-
39-
𝑂(𝑁𝑙𝑜𝑔𝑁 + 𝑁)
2+
Context:
3+
Given:
4+
five positive integers
5+
6+
Objective:
7+
find:
8+
minimum sum of four of the integers
9+
maximum sum of four of the integers
10+
print the min and max
11+
on one line, space separated
12+
13+
Example:
14+
[1,3,5,7,9]
15+
min_sum = 1 + 3 + 5 + 7
16+
max_xum = 3 + 5 + 7 + 9
17+
18+
Assumptions():?
19+
Is array always sorted? No mention, there assume it's not
20+
output can 32 bit integer
21+
22+
Constraints:
23+
1 <= arr[i] <= 10^9 : array value range
24+
require 64 bit integer
25+
26+
Flow:
27+
sort array
28+
array_size = 5
29+
min_sum = sum(arr[:array_size])
30+
max_sum = sum(arr[2:])
31+
print(min_sum max_sum)
32+
33+
Performance
34+
N = size of array
35+
S = O(NlogN): sorting time
36+
MIS = O(N - 1) = 𝑂(𝑁) : minimum sum
37+
MAS = O(N - 1) = 𝑂(𝑁) : maximum sum
38+
39+
𝑂(𝑁𝑙𝑜𝑔𝑁 + 𝑁)
4040
"""
4141

4242

programs_per_computational_model/0_declarative/arrays_and_strings/pangram.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
def pangram: a string that contains every letter of the alphabet
55
"""
66

7+
78
def is_subset(s):
8-
universe = set(s.lower()) # not necessary, this is for set use explicitness
9+
universe = set(s.lower()) # not necessary, this is for set use explicitness
910
fixed_domain = set(string.ascii_lowercase)
10-
if(fixed_domain.issubset(universe)):
11+
if fixed_domain.issubset(universe):
1112
return "pangram"
1213
return "not pangram"
1314

14-
assert(is_subset("We promptly judged antique ivory buckles for the next prize") == "pangram")
15-
assert(is_subset("We promptly judged antique ivory buckles") == "not pangram")
15+
16+
assert (
17+
is_subset("We promptly judged antique ivory buckles for the next prize")
18+
== "pangram"
19+
)
20+
assert is_subset("We promptly judged antique ivory buckles") == "not pangram"

programs_per_computational_model/0_declarative/arrays_and_strings/values_in_range.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
abstract function to return subset of values
3-
in interval [start_point, end_point]
2+
abstract function to return subset of values
3+
in interval [start_point, end_point]
44
5-
members of values collection must have:
6-
- well defined ordering
7-
∴ > , <, >=, >=, = definitions
5+
members of values collection must have:
6+
- well defined ordering
7+
∴ > , <, >=, >=, = definitions
88
"""
99

1010

programs_per_computational_model/0_declarative/numbers/256th_day_of_year.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
def date_on_256th_day(year):
22
def is_leap_year(year: int):
3-
if((year % 400 == 0) or (year % 100 != 0) and (year % 4 == 0)):
3+
if (year % 400 == 0) or (year % 100 != 0) and (year % 4 == 0):
44
return True
5-
else: return False
5+
else:
6+
return False
67

78
def calculate_day(year):
89
if is_leap_year(year):
@@ -14,7 +15,8 @@ def calculate_day(year):
1415

1516
return f"{day}.09.{year}"
1617

17-
#NB: incomplete
18+
19+
# NB: incomplete
1820
print(date_on_256th_day(1800))
1921
"""
2022
References:

programs_per_computational_model/3_stateful/arrays_and_strings/1.1.1.StringUniqueCharacters-Solution1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Assumptions:
3-
The string uses 128 ASCII character set
2+
Assumptions:
3+
The string uses 128 ASCII character set
44
"""
55

66

programs_per_computational_model/3_stateful/arrays_and_strings/1.1.1.StringUniqueCharacters-Solution2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Assumptions:
3-
The string uses 128 ASCII character set
2+
Assumptions:
3+
The string uses 128 ASCII character set
44
"""
55

66

programs_per_computational_model/3_stateful/arrays_and_strings/1.1.2.StringPermutation-Solution1.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
For two strings to be permutations of each other, they must contain the same:
3-
- characters
4-
characters include all possible characters in Unicode char set (whitespace etc)
5-
- number of characters
6-
Constraints:
7-
- case senstivity matters
2+
For two strings to be permutations of each other, they must contain the same:
3+
- characters
4+
characters include all possible characters in Unicode char set (whitespace etc)
5+
- number of characters
6+
Constraints:
7+
- case senstivity matters
88
"""
99

1010

programs_per_computational_model/3_stateful/arrays_and_strings/1.1.2.StringPermutation-Solution2.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
For two strings to be permutations of each other, they must contain the same:
3-
- characters
4-
characters include all possible characters in Unicode char set (whitespace etc)
5-
- number of characters
6-
Constraints:
7-
- case senstivity matters
8-
Assumptions:
9-
- Strings will be ASCII encoded = 128 characters
2+
For two strings to be permutations of each other, they must contain the same:
3+
- characters
4+
characters include all possible characters in Unicode char set (whitespace etc)
5+
- number of characters
6+
Constraints:
7+
- case senstivity matters
8+
Assumptions:
9+
- Strings will be ASCII encoded = 128 characters
1010
1111
"""
1212

0 commit comments

Comments
 (0)