Skip to content

Commit e466f99

Browse files
committed
Merge branch 'lesson_07-homework' of https://github.com/jxwatson251/code-differently-25-q1 into lesson_07-homework
2 parents 9041984 + 244d04a commit e466f99

Some content is hidden

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

48 files changed

+7683
-14
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Check Lesson 09 Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_09/types/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up JDK
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '21'
23+
distribution: 'temurin'
24+
25+
- name: Build Lesson 09 with Gradle
26+
working-directory: ./lesson_09/types
27+
run: ./gradlew check

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/dylanlafferty/ReadME.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## Java Implementation
2+
3+
```class PrimeChecker {
4+
public static boolean isPrime(int number) {
5+
if (number <= 1) {
6+
return false;
7+
}
8+
9+
// Check if number is divisible by any number from 2 to sqrt(number)
10+
for (int i = 2; i <= Math.sqrt(number); i++) {
11+
if (number % i == 0) {
12+
return false;
13+
}
14+
}
15+
return true;
16+
}
17+
18+
public static void main(String[] args) {
19+
int num1 = 11; //This number may be changed to change the input
20+
int num2 = 15; //This one too
21+
System.out.println(num1 + " is prime: " + isPrime(num1));
22+
System.out.println(num2 + " is prime: " + isPrime(num2));
23+
}
24+
}
25+
```
26+
27+
## JavaScript implementation
28+
29+
```
30+
// let number = prompt("Enter a number to check if it is a Prime number");
31+
32+
function checkPrime(number) {
33+
if (number === null || number === undefined) {
34+
console.log("You have not entered a number");
35+
return;
36+
}
37+
38+
if (number <= 1) {
39+
console.log("This is not a prime number");
40+
return false; // Numbers less than or equal to 1 are not prime
41+
}
42+
43+
for (let i = 2; i < Math.sqrt(number); i++) {
44+
if (number % i === 0) {
45+
console.log("This is not a prime number");
46+
return false; // If divisible by any number other than 1 and itself
47+
}
48+
}
49+
50+
console.log("This is a prime number");
51+
return true; // If no divisors were found, the number is prime
52+
}
53+
54+
console.log(checkPrime(45)); //
55+
console.log(checkPrime(23)); //
56+
console.log(checkPrime(13)); //
57+
```
58+
59+
## Explaination
60+
61+
The Java
62+
The Java implementation uses a class named `PrimeChecker`. `PrimeChecker` will get an integer named `number` and run it through 2 tests. The first test will be to see if `number` is less than or greater than 1 which then will return `false`. It will then see if the number is able to be divided by anything other than itself and if not then it will return `True`.
63+
64+
The JavaScript implementation uses a function named `checkPrime`. `CheckPrime` first checks if a `number` has been entered. If a `number` has been entered and if it is less than or equal to 1 it will return `True`. If this passes the for loop will run and see if that `number` can be divided into itself and if it can then return `False`.
65+
66+
## Similarites
67+
1. **Syntax**
68+
- Both languages write If statements in the same way using `if(instance) { code } `.
69+
- The For Loop are both written using `for` and adding the statements inside of `(statement1)`.
70+
- Math works the same in both languages using the `%` for division.
71+
2. **Input Fields**
72+
- Both Languages can have a predefined input inside of the code.
73+
- Both Languages can return either `true` or `false` to the console.
74+
75+
## Differences
76+
1. **Syntax**
77+
- In `Java` there are two Static functions but one it required to be defined as main. However in `JavaScript` you do not need to define a main function.
78+
- In `Java` in order to print something you have to write a `system.out.print` compared to `JavaScript` It uses the `console.log`.
79+
2. ## Declarations
80+
- With `Java` You have to let the computer know what type of input you are giving it. So if you would want to give a variable a number you need to declare that as an integer or `int`. While you can just write a number out in `javaScript`.
81+

lesson_04/ezra4/README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
## Python Implementation
22

33
```python
4-
def prime_num(num):
4+
def is_prime(num):
55
if num <= 1:
66
return False
7-
for i in range(2, num):
7+
for i in range(2, num):
88
if num % i == 0:
99
return False
1010
return True
11+
12+
def main():
13+
num = int(input("Enter a number: "))
14+
print(f"{num} is prime." if is_prime(num) else f"{num} is not prime.")
15+
16+
if __name__ == "__main__":
17+
main()
1118
```
1219

1320
## Java Implementation
1421

1522

1623
```java
17-
public static void main(String[] args) {
18-
Scanner scanner = new Scanner(System.in);
19-
System.out.print("Enter a number:");
20-
int num = scanner.nextInt();
21-
22-
if (isPrime(num)) {
23-
System.out.println(num + " is prime.");
24+
import java.util.Scanner;
25+
26+
public class PrimeChecker {
27+
public static void main(String[] args) {
28+
Scanner scanner = new Scanner(System.in);
29+
System.out.print("Enter a number: ");
30+
int num = scanner.nextInt();
31+
System.out.println(num + (isPrime(num) ? " is prime." : " is not prime."));
32+
scanner.close();
2433
}
25-
else {
26-
System.out.println(num + " is not prime.");
34+
35+
public static boolean isPrime(int num) {
36+
if (num <= 1) {
37+
return false;
38+
}
39+
for (int i = 2; i < num; i++) {
40+
if (num % i == 0) {
41+
return false;
42+
}
43+
}
44+
return true;
2745
}
2846
}
2947
```
@@ -46,5 +64,6 @@ In java we have a different approach. Unlike python we define our class using `(
4664

4765
2. Java uses `System.out.print()` to print out the statement and python uses `print()` to print statement.
4866

49-
50-
3. I notice i have to import `java.util.Scanner` to prompt user to input a number while python you only need to use, `input()`
67+
3. I notice i have to import `java.util.Scanner` to prompt user to input a number while python you only need to use, `input()`
68+
4. Java uses `{}` for blocks and `;` to end statement while python doesn't need semicolons.
69+

lesson_05/dylanlafferty/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
## Three user Stories
4+
```
5+
1. As a `Line Cook`, `I want ` an application that allows me to see an easy-to-read ticket that only displays items that belong to my station on that ticket. `So that` I can quickly make entrees faster and be able to focus on what is on my stations end other than the other stations.
6+
7+
2. As a `Software engineer`, `I want` a program that will allow me to drag and drop different css elements, `So that` I can efficently create a custom webpage without having to spend hours making the perfect CSS.
8+
9+
3. As a `Inventory Stock`, `I want` a program that will keep track of items in my storage and when that item hits a certain number it will automatically send order. `So that` I can automate my storage process and spend time reordering on other tasks in the store.
10+
```
11+
12+

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+
{}

0 commit comments

Comments
 (0)