From 9a90b142314d01f898545b0a2d8ab6d84f339710 Mon Sep 17 00:00:00 2001 From: helyus1412 Date: Tue, 8 Jun 2021 15:38:15 +0700 Subject: [PATCH] done --- soal1.py | 18 ++++++++++++++++++ soal2.py | 18 ++++++++++++++++++ soal3.py | 16 ++++++++++++++++ soal4.py | 15 +++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 soal1.py create mode 100644 soal2.py create mode 100644 soal3.py create mode 100644 soal4.py diff --git a/soal1.py b/soal1.py new file mode 100644 index 0000000..75d01eb --- /dev/null +++ b/soal1.py @@ -0,0 +1,18 @@ +n = 9 +ar = [10, 20, 20, 10, 10, 30, 50, 10, 20] + + +def sockMerchant(n, ar): + count = 0 + dict = {} + + for i in ar: + dict[i] = dict.get(i, 0) + 1 + + for i in dict.keys(): + count += dict[i] // 2 + + return count + + +print(sockMerchant(n, ar)) diff --git a/soal2.py b/soal2.py new file mode 100644 index 0000000..bc5f7e5 --- /dev/null +++ b/soal2.py @@ -0,0 +1,18 @@ +k = 2 +a = [0, -1, 2, 1] + + +def angryProfessor(k, a): + on_time = 0 + + for i in range(len(a)): + if a[i] <= 0: + on_time += 1 + + if on_time >= k: + return "NO" + else: + return "YES" + + +print(angryProfessor(k, a)) diff --git a/soal3.py b/soal3.py new file mode 100644 index 0000000..7cd1ee2 --- /dev/null +++ b/soal3.py @@ -0,0 +1,16 @@ +import math + +arr = [1, 2, 3, 5, 4, 4, 3, 2, 1, 3, 4] + + +def migratorBirds(arr): + bird_count = [0]*len(arr) + for i in arr: + bird_count[i] += 1 + print(bird_count) + + maks = max(bird_count) + return bird_count.index(maks) + + +print(migratorBirds(arr)) diff --git a/soal4.py b/soal4.py new file mode 100644 index 0000000..0717139 --- /dev/null +++ b/soal4.py @@ -0,0 +1,15 @@ +s = 'aba' # len = 3 +n = 10 + +# abaabaabaa + + +def repeatedString(s, n): + s_awal = s.count('a') * (n // len(s)) # aaaaaa + s_sisa = s[:(n % len(s))].count('a') # a + # print(s_awal) + # print(s_sisa) + return s_awal + s_sisa + + +print(repeatedString(s, n))