Skip to content

Commit

Permalink
Merge branch 'main' into eng2101
Browse files Browse the repository at this point in the history
Signed-off-by: RangHo Lee <[email protected]>
  • Loading branch information
RangHo authored Oct 30, 2023
2 parents 2afa74f + bc2e571 commit d2bdb8e
Show file tree
Hide file tree
Showing 239 changed files with 128,781 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: RangHo
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: rangho
Expand All @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: rangho
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: 'https://qr.kakaopay.com/FVGoIv2lp'
43 changes: 43 additions & 0 deletions COR1010/Final/F_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def get_LCM(x: int, y: int) -> int:
"""Calculate the least common multiple of two integers.
:param int x: The first integer.
:param int y: The second integer.
:return: The least common multiple of x and y.
:rtype: int
"""

# Find the bigger and the smaller number
t_max = max(x, y)

t_current = t_max
while True:
# If the target is divisible by both numbers, return it
if t_current % x == 0 and t_current % y == 0:
return t_current

# Otherwise, find the next target
t_current += t_max


n, b, x, y = map(int, input("n,b,x,y : ").split(','))

# Make sure that input is sane
if n < 1 or x < 1 or y < 1:
print("Invalid input")
exit()

# Find the least common multiple of x and y
lcm = get_LCM(x, y)

# If b is less than zero, start from the first one
if b < 0:
start = 1
else:
start = b // lcm + 1

# Print n common multiples
while n > 0:
print(lcm * start, end=' ')
start += 1
n -= 1
45 changes: 45 additions & 0 deletions COR1010/Final/F_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
def readWord(filename: str) -> list:
"""Read the given file into a list of words.
:param str filename: The name of the file to read.
:return: A list of words.
:rtype: list
"""

# Open the file, read into lines, and strip each line
with open(filename, "r") as f:
words = [line.strip() for line in f]

# Return the result
return words


def printDic(dic: dict[str, set]) -> None:
"""Print the given dictionary with proper format.
:param dict dic: The dictionary to print.
:return: None
:rtype: None
"""

# Print the dictionary
for first_letter, word in dic.items():
print(f"{word} starts with '{first_letter}'")


word_dic = {}
words = readWord("vocabulary.txt")

# Iterate through each word
for word in words:
first_letter = word[0]

# If the first letter is not in the dictionary, add it;
# else, create a new set
if first_letter in word_dic:
word_dic[first_letter].add(word)
else:
word_dic[first_letter] = {word}

# Print the dictionary
printDic(word_dic)
57 changes: 57 additions & 0 deletions COR1010/Final/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 기초인공지능프로그래밍 기말고사

기말고사는 2개의 프로그래밍 문제를 풀었습니다.

## 문제 1. 최소공배수 구하기

> 네 개의 정수 `n`, `b`, `x`, `y`를 입력받는다.
> 아래의 조건에 맞게 `x`, `y`의 공배수(common multiple)를 출력하는 프로그램을
> 작성하시오. (25점)
> * $b \ge 0$인 경우 b보다 큰 x와 y의 공배수 n개를 출력한다.
> * $b \lt 0$인 경우 0보다 큰 x와 y의 공배수 n개를 출력한다.
> * n, x, y가 0보다 작거나 같은 경우 에러메시지를 출력한다.
이 문제는 반복문과 조건문을 활용하여 모든 조건에 부합하는 수를 찾을 수 있는지를
묻는 문제입니다.
여기서 입력값은 하나의 `input` 함수 호출으로 주어집니다.
입력값의 형식은 항상 올바르다고 가정하여 숫자가 3개 이하 또는 5개 이상 주어지는
경우에 대한 예외 처리는 필요하지 않습ㄴ다.
다만, 위 조건에서 알 수 있듯이, 입력으로 주어지는 숫자가 항상 공배수를 구할 수
있는 숫자는 아니므로, 이에 대한 예외 처리는 필요합니다.

## 문제 2. 파일 읽기

> 파일(`vocabulary.txt`)에서 단어를 읽어 리스트에 저장한 후, 리스트에 저장되어
> 있는 단어를 사전으로 구성하여 출력하는 코드를 작성하시오.
> 단어의 첫 번째 글자가 키이고, 동일한 글자로 시작하는 단어들의 집합이 값이 되는
> 사전을 구성한 후 아래와 같이 출력하시오.
> (파일의 내용은 변경될 수 있다.) (30점)
이 문제는 파일 입출력과 리스트, 집합, 사전 등 여러 컨테이너 자료형을 사용할 수
있는지 묻는 문제입니다.
파일 이름은 변하지 않으며, 현재 실행 중인 디렉터리에 존재한다고 가정합니다.

예시 파일 내용은 아래와 같이 한 줄에 하나의 단어가 적혀 있습니다.

```
chair
sofa
book
table
candle
desk
cushion
chair
cup
book
curtain
blanket
tissue
clock
book
curtain
tissue
cup
chair
book
```
10 changes: 10 additions & 0 deletions COR1010/H1_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
total = 3890
coin500 = total // 500; total = total % 500
coin100 = total // 100; total = total % 100
coin50 = total // 50; total = total % 50
coin10 = total // 10

print("500원짜리 :", coin500)
print("100원짜리 :", coin100)
print("50원짜리 :", coin50)
print("10원짜리 :", coin10)
9 changes: 9 additions & 0 deletions COR1010/H1_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import math

a = 5
c = 8
B = 60

area = 0.5 * a * c * math.sin(math.radians(B))
print("a :", a, "c :", c, "B(각도) :", B)
print("삼각형의 넓이 :", round(area, 2))
10 changes: 10 additions & 0 deletions COR1010/H2_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sample = "abcABCdEFaBCDeFAbCdEf"
sample = sample.lower()

index_abc = sample.find("abc")
index_def = sample.rfind("def")
count_abc = sample.count("abc")
count_def = sample.count("def")

print("\"abc 문자열 : %d 인덱스, %d번 존재\"" % (index_abc, count_abc))
print("\"def 문자열 : %d 인덱스, %d번 존재\"" % (index_def, count_def))
11 changes: 11 additions & 0 deletions COR1010/H2_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
print('두 점의 좌표를 입력하시오.')
x1, y1, z1 = input('X1,Y1,Z1 : ').split()
x2, y2, z2 = input('X2,Y2,Z2 : ').split()
x1 = float(x1)
y1 = float(y1)
z1 = float(z1)
x2 = float(x2)
y2 = float(y2)
z2 = float(z2)
d = ((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)**0.5
print('두 점 ({}, {}, {}) ({}, {}, {})의 거리는 {:.2f}이다.'.format(x1, y1, z1, x2, y2, z2, d))
7 changes: 7 additions & 0 deletions COR1010/H2_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
first = input("First Name : ")
last = input("Last Name : ")
year = int(input("Year of birth : "))

login_id = last.title() + str(year)[:1:-1] + first[::-1].upper()

print("Login ID :", login_id)
14 changes: 14 additions & 0 deletions COR1010/H3_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
n = int(input("Etnter the number : "))

if n > 0:
if n % 3 == 0:
if n % 4 == 0:
print(n, "is divided by both 3 and 4")
else:
print(n, "is divided by 3")
elif n % 4 == 0:
print(n, "is divided by 4")
else:
print(n, "is not divided by any number")
else:
print(n, "is not valid input")
24 changes: 24 additions & 0 deletions COR1010/H3_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
usage = int(input("전기사용량(kWh)은? : "))

base1 = 910
base2 = 1600
base3 = 7300
rate1 = 93.3
rate2 = 187.9
rate3 = 280.6

if usage <= 200:
total = int(base1 + usage * rate1)
elif usage <= 400:
total = int(base2 + (usage - 200) * rate2 + 200 * rate1)
else:
total = int(base3 + (usage - 400) * rate3 + 200 * rate2 + 200 * rate1)

# 부가가치세
total += (total * 0.1)

#전력산업기반기금
total += total * 0.037

print("게산된 금액은 {:,}원 입니다.".format(int(total)))

14 changes: 14 additions & 0 deletions COR1010/H4_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
word = list(input("단어를 입력하시오 : "))

print(word)

if word[0].lower() not in "aeiou":
piglatin = word[1:] + word[0:1]
else:
piglatin = word.copy()

piglatin.extend(list("ay"))

print(piglatin)

print(f"{''.join(word)} ==> {''.join(piglatin)}")
24 changes: 24 additions & 0 deletions COR1010/H4_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
old_list = [[1, 2], [3, 4], [5, 6], [7, 8]]
new_list = []

element1 = []
element1.append(old_list[0][0] + old_list[0][1])
element1.append(old_list[0][0] * old_list[0][1])
new_list.append(element1)

element2 = []
element2.append(old_list[1][0] + old_list[1][1])
element2.append(old_list[1][0] * old_list[1][1])
new_list.append(element2)

element3 = []
element3.append(old_list[2][0] + old_list[2][1])
element3.append(old_list[2][0] * old_list[2][1])
new_list.append(element3)

element4 = []
element4.append(old_list[3][0] + old_list[3][1])
element4.append(old_list[3][0] * old_list[3][1])
new_list.append(element4)

print(new_list)
11 changes: 11 additions & 0 deletions COR1010/H4_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

odd_index_sum = sum(data[::2])
even_index_sum = sum(data[1::2])
average = sum(data) / len(data)

data.insert(0, odd_index_sum)
data.insert(1, even_index_sum)
data.append(average)

print(data)
17 changes: 17 additions & 0 deletions COR1010/H5_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
num_strs = input("Enter numbers : ").split()

primes = []
for num_str in num_strs:
num = int(num_str)

# Check if num is prime
is_prime = True
for n in range(2, int(num**0.5) + 1):
if num % n == 0:
is_prime = False
break

if is_prime:
primes.append(num)

print("Prime number :", primes)
16 changes: 16 additions & 0 deletions COR1010/H5_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import math

data = input("Enter data : \n").split()

# Calculate E(X^2) and E(X)^2
expected_sq_x = 0
sq_expected_x = 0
for value in data:
expected_sq_x += float(value)**2
sq_expected_x += float(value)
expected_sq_x = expected_sq_x / len(data)
sq_expected_x = (sq_expected_x / len(data))**2

sigma = math.sqrt(expected_sq_x - sq_expected_x)

print("Standard deviation = {:.5f}".format(sigma))
10 changes: 10 additions & 0 deletions COR1010/H6_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
base10 = int(input("Enter the number : "))

base8 = base10
base8_str = ""
while base8 > 0:
rem = base8 % 8
base8 = base8 // 8
base8_str = str(rem) + base8_str

print(f"{base10} is {base8_str} in oct")
16 changes: 16 additions & 0 deletions COR1010/H6_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ns = [int(n) for n in input("Enter two numbers : ").split()]

is_mutual_prime = True
min_n = min(ns)

i = 2
while i <= min_n:
if ns[0] % i == 0 and ns[1] % i == 0:
is_mutual_prime = False
break
i += 1

if is_mutual_prime:
print("They are mutually prime.")
else:
print("They are not mutually prime.")
8 changes: 8 additions & 0 deletions COR1010/H7_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
word = input("Enter a word : ")

occurances = {}
for c in word:
c = c.lower()
occurances[c] = occurances.get(c, 0) + 1

print(occurances)
Loading

0 comments on commit d2bdb8e

Please sign in to comment.