Skip to content

Commit cd5cb8c

Browse files
Merge branch 'code-differently:main' into feat/lesson_07d
2 parents 198e751 + b9be8c7 commit cd5cb8c

File tree

14 files changed

+5997
-1
lines changed

14 files changed

+5997
-1
lines changed

lesson_04/dariusd/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Prime Time
2+
3+
## Composite # Check Python
4+
### Requirements
5+
- Python 3.x
6+
7+
```python
8+
# Function to check if a number is composite
9+
def is_composite(number):
10+
if number < 2:
11+
return f"{number} is neither prime nor composite."
12+
13+
# Check for factors from 2 to sqrt(number)
14+
for i in range(2, int(number**0.5) + 1):
15+
if number % i == 0:
16+
return f"{number} is a composite number."
17+
18+
return f"{number} is a prime number."
19+
```
20+
21+
## Prime # Check Bash
22+
23+
```bash
24+
# Function to check if a number is prime
25+
is_prime() {
26+
local num=$1
27+
if ((num <= 1)); then
28+
echo "$num is not prime."
29+
return 1
30+
fi
31+
# Function to check factors from 2 to square root(number)
32+
for ((i = 2; i <= num / 2; i++)); do
33+
if ((num % i == 0)); then
34+
echo "$num is not prime."
35+
return 1
36+
fi
37+
done
38+
echo "$num is prime."
39+
}
40+
```
41+
42+
## Explanation
43+
44+
The Python Script isn't your conventional prime number detector. Instead I took the approach of using a composite number detector that uses the function `is_composite` to show weather the `number` you input is composite. If inputted number is less than 2 then `it's neither prime nor composite`. If previous rule is false(greater than 2) then we run factors of 2 to the square root to determine `results`. Any factor larger than the square root would already have a corresponding smaller factor so will know if our `number is composite` or not.
45+
46+
Next, the Bash Script is a classic prime numbers check that uses the function `is_prime` to... you've guessed it check if users number is a prime. Said function will first check if the inputted `number` is greater than or equal to 1; If said previous rule was true then the we stop. If false, then it will run sequence to determine if said number is has factors from 2 to square root of number. When done if 2 factors are found it `isn't a prime number` and `is a prime number` if 2 aren't found. System will `echo`(notify user) of final verdict.
47+
48+
## Differences
49+
50+
51+
1. **Syntax**:
52+
- In Python, we use `def` as our keyword and `int` as a way to describe the inputted number.
53+
- In Bash we use `local` as our keyword and `num`/`$num` as a way to describe inputted number from users.
54+
55+
2. **Function Calls**:
56+
- `Print` is used to call functions and output information for Python while `Echo` is used for Bash, in which both give info to the the user.
57+
58+
3. **Composite vs Prime**:
59+
- The Python script is used to determine weather the inputted number `is a Composite number`; In doing so we also get the reciprocal on if it's a prime number as well.
60+
- The Bash Script is the opposite in which where looking for if the inputted number `is prime` and in doing so we get the reciprocal if it isn't.

lesson_08/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ Please review the following resources before lecture:
1313

1414
## Homework
1515

16-
- TODO(anthonydmays): Add moar details
16+
- [ ] Memorize the `printPermutations` and `reverseString` methods in [algos_app][algos-app].
17+
- [ ] Do pre-work for [lesson 09](/lesson_09/).
18+
19+
[algos-app]: ./algos/src/lesson8.ts

lesson_08/algos/.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
insert_final_newline = true
9+
organize_imports = true
10+
trim_trailing_whitespace = true
11+
quote_type = single

lesson_08/algos/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

lesson_08/algos/.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore artifacts:
2+
build
3+
coverage

lesson_08/algos/.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

lesson_08/algos/eslint.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import stylistic from '@stylistic/eslint-plugin';
5+
import eslintConfigPrettier from 'eslint-config-prettier';
6+
import tseslint from 'typescript-eslint';
7+
8+
export default tseslint.config(
9+
eslint.configs.recommended,
10+
...tseslint.configs.strict,
11+
...tseslint.configs.stylistic,
12+
eslintConfigPrettier,
13+
{
14+
ignores: ['build'],
15+
plugins: { '@stylistic': stylistic },
16+
rules: {
17+
'@typescript-eslint/interface-name-prefix': 'off',
18+
'@typescript-eslint/explicit-function-return-type': 'off',
19+
'@typescript-eslint/no-explicit-any': 'error',
20+
'@typescript-eslint/no-extraneous-class': 'off',
21+
'@stylistic/quotes': [
22+
'error',
23+
'single',
24+
{ avoidEscape: true, allowTemplateLiterals: false },
25+
],
26+
},
27+
},
28+
);

lesson_08/algos/jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} **/
2+
export default {
3+
testEnvironment: 'node',
4+
transform: {
5+
'^.+.tsx?$': ['ts-jest', { useESM: true }],
6+
},
7+
moduleNameMapper: {
8+
'^(\\.\\.?\\/.+)\\.js$': '$1',
9+
},
10+
extensionsToTreatAsEsm: ['.ts'],
11+
};

0 commit comments

Comments
 (0)