Skip to content

Commit fe2edf7

Browse files
authored
Merge branch 'code-differently:main' into Work07
2 parents 84589c8 + b9be8c7 commit fe2edf7

File tree

16 files changed

+6117
-1
lines changed

16 files changed

+6117
-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_04/justineklund/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Python examples
2+
3+
```python
4+
def is_prime(n):
5+
if n < 2:
6+
return False
7+
for i in range(2, int(n**0.5) + 1):
8+
if n % i == 0:
9+
return False
10+
return True
11+
12+
# Example usage
13+
num = 29
14+
if is_prime(num):
15+
print(f"{num} is a prime number.")
16+
else:
17+
print(f"{num} is not a prime number.")
18+
```
19+
20+
21+
Java Examples
22+
23+
```java
24+
public class PrimeChecker {
25+
public static boolean isPrime(int n) {
26+
if (n < 2) return false;
27+
for (int i = 2; i <= Math.sqrt(n); i++) {
28+
if (n % i == 0) return false;
29+
}
30+
return true;
31+
}
32+
33+
public static void main(String[] args) {
34+
int num = 29;
35+
System.out.println(num + " is prime: " + isPrime(num));
36+
}
37+
}
38+
```
39+
40+
Similarties
41+
They both use if and for standards to go about the command. This essentially gives the computer a path to go through to make sure the number is prime or not. They also both use the true and false function. This tells the computer how to go about the next commands. Also they both use division. Division is important because if it can be di
42+
vided or not crtical in figuring out if the number is prime.
43+
44+
Differences
45+
A big difference is in the certain command language used. Examples begin in how they start. Java begins with public static and python begins with def is prime. This continues all throughout the code line with multiple commands being different.

lesson_04/karenalabi/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Lesson 04
2+
3+
## Python Implementation
4+
5+
```python
6+
# Defines a function named (primenumcheck) that calls a parameter (numbers)
7+
def primenumcheck (number):
8+
# Conditional statements that determine if the number being returned is prime
9+
if number <= 1:
10+
return False
11+
if number == 2:
12+
return True
13+
if number % 2 == 0:
14+
return False
15+
# For loop to check if numbers greater than 2 are prime
16+
for i in range(3, int(number ** 0.5) + 1, 2):
17+
if number % i == 0:
18+
return False
19+
return True
20+
```
21+
22+
## Java Implementation
23+
24+
```java
25+
// Declaring the class in program (PrimeNumberChecker)
26+
public class PrimeNumberChecker
27+
// boolean method to check if integer is Prime
28+
// access modifier to start the program
29+
public static boolean checkIfPrime (int number) {
30+
// Conditional statements to determine if number is prime
31+
if (number <= 1) {
32+
return false;
33+
}
34+
if (number == 2) {
35+
return true;
36+
}
37+
if (number % 2 == 0) {
38+
return false;
39+
}
40+
// For loop to check if mumbers greater than 2 are prime
41+
for (int i = 3; i <= Math.sqrt(number); i += 2) {
42+
if (number % i == 0) {
43+
return false;
44+
}
45+
}
46+
return true;
47+
}
48+
```
49+
50+
51+
## Explanation
52+
The Python implementation defines a function named with the `def` keyword. The function is called `primenumcheck` and it calls a parameter `number` and determines whether it is prime. The python implementation then uses condiitonal if - statements to return false if the number is less than or equal to 1, or if the number is divisible by 2 becuase prime numbers can only be divisible by themselves and are greater than 1. The function will return true if the number returned is equal to 2. The python implementation also uses a `for` loop to iterate through the odd numbers up to the squareoot of that given number. If any of these numbers evenly divides `number`, it is not prime, and will return false. The loop increments by 2 (`i += 2`) to rule out even numbers.
53+
54+
The Java implementation follows a similar logic to the python implementation. It defines a public class named `PrimeNumberChecker`. Within this class, a `boolean` method called `checkIfPrime` is implemented to determine if an integer is prime or not. The method takes an `int` (integer) parameter called `number` and uses conditional statements (if-statements) to check if the input number is prime. Similar to the python inplementation, the java implementation also used a for-loop to iterate through numbers not evenly divisible by the given number.
55+
56+
### Differences
57+
58+
1. **Syntax**:
59+
- In Python, the function is defined using the `def` keyword. The fucntion can be defined by directly calling the name `primenumcheck`. Whereas, in Java, the proper term is a method and methods are defined within a class using a return type `boolean`, in this case. The Java implementation will return true or fase based on the int parameter called `number`.
60+
61+
- Python uses indentation to define the beginning and end of that portion of code, while Java uses curly braces `{}`.
62+
63+
- Python capitalizes its boolean values. It uses `True` and `False`. Java does not capitalize the boolean values.
64+
65+
- Python uses hashes to comment out the code while java uses back slashes
66+
67+
2. **Type System**:
68+
- Java requires the type of method (`boolean` or `int`) to be declared within an access modifier: `public static boolean checkIfPrime` , whereas the Python function can be called by its name: `def primenumcheck`
69+
70+
- Java uses `boolean` to return `checkIfPrime` method, whereas the Python implementation returns True or False based on the if-statement conditions
71+
3. **Function Calls**:
72+
- the python implementation uses a range within the for loop
73+
74+
- the java implementation uses the math sqroot
75+

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)