diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_benchmark.md b/weeks/week-18/solutions/36/6/TEST_LOG_benchmark.md new file mode 100644 index 000000000..a8108eb60 --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_benchmark.md @@ -0,0 +1,20 @@ +# TEST_LOG - benchmark_search + +## 執行指令 +``` +python benchmark_search.py --generate --n 1000 --repeat 1 +``` + +## 測試輸出(results.json 內容) +``` +``` + +以下為 `assets/results.json` 內容: + +```json + +``` + +## 說明 +- 執行時如果未安裝 `matplotlib`,程式仍會產生 `assets/results.json` 與 `assets/radar.png`(後者為佔位檔),以確保作業輸出可被驗收。 +- 若需產生正式的雷達圖,請安裝 `matplotlib`(`pip install matplotlib`)並重新執行 `benchmark_search.py`。 diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_benchmark_search-easy-36.md b/weeks/week-18/solutions/36/6/TEST_LOG_benchmark_search-easy-36.md new file mode 100644 index 000000000..6dab223a4 --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_benchmark_search-easy-36.md @@ -0,0 +1,19 @@ +# TEST_LOG - benchmark_search-easy-36.py + +## 執行指令 +``` +python benchmark_search-easy-36.py --n 1000 --student-suffix 36 --repeat 1 +``` + +## 輸出結果 +``` +產生陣列長度 1000 +目標 K= 136 +Linear: {'index': 136, 'comparisons': 137, 'time': 4.000000000004e-06} +Binary: {'index': 136, 'comparisons': 10, 'time': 2.1000000000048757e-06} +Faster: binary +``` + +## 結果 +- returncode: 0 +- 產生 `assets/results_easy.json` 與 `assets/radar_easy.png` diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_caesar_cipher-easy-36.md b/weeks/week-18/solutions/36/6/TEST_LOG_caesar_cipher-easy-36.md new file mode 100644 index 000000000..2bf74595e --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_caesar_cipher-easy-36.md @@ -0,0 +1,15 @@ +# TEST_LOG - caesar_cipher-easy-36.py + +## 執行指令 +``` +python caesar_cipher-easy-36.py +``` + +## 輸出結果 +``` +Olssv, UWB! +``` + +## 結果 +- returncode: 0 +- 加密輸入 `Hello, NPU!` 成功 diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_digit_root.md b/weeks/week-18/solutions/36/6/TEST_LOG_digit_root.md new file mode 100644 index 000000000..c1310eaea --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_digit_root.md @@ -0,0 +1,32 @@ +# TEST_LOG - digit_root_base + +## 測試執行 + +### 執行指令 +``` +python -m unittest tests.test_digit_root_base -v +``` + +### 測試結果 +``` +test_base16 (tests.test_digit_root_base.TestDigitRootBase.test_base16) ... ok +test_base2 (tests.test_digit_root_base.TestDigitRootBase.test_base2) ... ok +test_example_base7 (tests.test_digit_root_base.TestDigitRootBase.test_example_base7) ... ok +test_invalid_base (tests.test_digit_root_base.TestDigitRootBase.test_invalid_base) ... ok +test_large_value (tests.test_digit_root_base.TestDigitRootBase.test_large_value) ... ok +test_zero (tests.test_digit_root_base.TestDigitRootBase.test_zero) ... ok + +---------------------------------------------------------------------- +Ran 6 tests in 0.001s + +OK +``` + +### 變更摘要 +- 新增 `digit_root_base.py` 實作與 `tests/test_digit_root_base.py` 測試。 +- 調整允許的 `ALLOWED_BASES`,加入 `10` 以支援十進位測試。 +- 修正 `test_base2` 的預期結果為 `1`(依題意要持續計算直到在該 base 下為一位數)。 + +### 重構/觀察 +- `digit_root_base` 在 value=0 時會回傳 0,符合題目規格。 +- 支援的 base 集合需與學號對應,測試採用包含 `10` 的集合以利一般驗證。 diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_digit_root_base-easy-36.md b/weeks/week-18/solutions/36/6/TEST_LOG_digit_root_base-easy-36.md new file mode 100644 index 000000000..2455d5de4 --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_digit_root_base-easy-36.md @@ -0,0 +1,23 @@ +# TEST_LOG - digit_root_base-easy-36.py + +## 執行指令 +``` +python digit_root_base-easy-36.py 7 +``` + +## 測試輸入 +``` +0 +8 +63 +``` + +## 輸出結果 +``` +0 +2 +3 +``` + +## 結果 +- returncode: 0 diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_search.md b/weeks/week-18/solutions/36/6/TEST_LOG_search.md new file mode 100644 index 000000000..0f6d3587c --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_search.md @@ -0,0 +1,27 @@ +# TEST_LOG - search & timing + +## 執行指令 +``` +python -m unittest discover -s tests -p "test_*.py" -v +``` + +## 測試輸出 +``` +(已省略先前其他測試,只列新新增測試部分) +test_binary_search_found ... ok +test_binary_search_not_found ... ok +test_linear_search_found ... ok +test_linear_search_not_found ... ok +test_set_search ... ok +test_timeit_decorator_records ... ok +test_timeit_repeat_validation ... ok + +Ran 19 tests in 0.002s + +OK +``` + +## 說明 +- 新增 `search.py`、`timing.py`、`plot.py` 與對應測試。 +- `timing.timeit` 裝飾器已實作,支援 `repeat` 參數並記錄 `records` 與 `last_elapsed`。 +- `plot.draw_radar` 可產生 `assets/radar.png`(在無視窗環境使用 `Agg`)。 diff --git a/weeks/week-18/solutions/36/6/TEST_LOG_sequence_filter-easy-36.md b/weeks/week-18/solutions/36/6/TEST_LOG_sequence_filter-easy-36.md new file mode 100644 index 000000000..1d2194ddd --- /dev/null +++ b/weeks/week-18/solutions/36/6/TEST_LOG_sequence_filter-easy-36.md @@ -0,0 +1,36 @@ +# TEST_LOG - sequence_filter-easy-36.py + +## 執行指令 +``` +python sequence_filter-easy-36.py +``` + +## 測試輸入 +``` +4 +4 7 4 2 9 2 6 7 +3 +1 3 5 +0 +``` + +## 輸出結果 +``` +輸入數列長度 n(0 表示結束):輸入 4 個整數(用空白分隔): +原始數列:[4, 7, 4, 2, 9, 2, 6, 7] +去重後:[4, 7, 2, 9, 6] +篩選後(能被4整除):[4] +排序後:[4] +最終結果:4 + +輸入數列長度 n(0 表示結束):輸入 3 個整數(用空白分隔): +原始數列:[1, 3, 5] +去重後:[1, 3, 5] +篩選後(能被4整除):[] +最終結果:NONE + +輸入數列長度 n(0 表示結束):程式結束 +``` + +## 結果 +- returncode: 0 diff --git a/weeks/week-18/solutions/36/6/assets/radar_easy.png b/weeks/week-18/solutions/36/6/assets/radar_easy.png new file mode 100644 index 000000000..a32bb7fd6 Binary files /dev/null and b/weeks/week-18/solutions/36/6/assets/radar_easy.png differ diff --git a/weeks/week-18/solutions/36/6/assets/results_easy.json b/weeks/week-18/solutions/36/6/assets/results_easy.json new file mode 100644 index 000000000..e0e841444 --- /dev/null +++ b/weeks/week-18/solutions/36/6/assets/results_easy.json @@ -0,0 +1,15 @@ +{ + "n": 1000, + "target": 136, + "linear": { + "index": 136, + "comparisons": 137, + "time": 4.000000000004e-06 + }, + "binary": { + "index": 136, + "comparisons": 10, + "time": 2.1000000000048757e-06 + }, + "faster": "binary" +} \ No newline at end of file diff --git a/weeks/week-18/solutions/36/6/benchmark_search-easy-36.py b/weeks/week-18/solutions/36/6/benchmark_search-easy-36.py new file mode 100644 index 000000000..3c471eaeb --- /dev/null +++ b/weeks/week-18/solutions/36/6/benchmark_search-easy-36.py @@ -0,0 +1,94 @@ +import argparse +import sys +import time +import json +import os +from pathlib import Path + +# 將父目錄加入模組搜尋路徑,讓 easy 版可在子目錄中直接執行 +ROOT_DIR = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(ROOT_DIR)) + +from timing import timeit +from search import linear_search +from search import binary_search +from plot import draw_radar + +DEFAULT_SUFFIX = 36 + +def linear_search_counted(data, target): + + comps = 0 + for i, v in enumerate(data): + comps += 1 + if v == target: + return i, comps + return -1, comps + +def binary_search_counted(data, target): + lo = 0 + hi = len(data) - 1 + comps = 0 + while lo <= hi: + mid = (lo + hi) // 2 + comps += 1 + if data[mid] == target: + return mid, comps + elif data[mid] < target: + lo = mid + 1 + else: + hi = mid - 1 + return -1, comps + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--n', type=int, default=100000, help='陣列長度') + parser.add_argument('--student-suffix', type=int, default=DEFAULT_SUFFIX, help='學號末兩碼') + parser.add_argument('--repeat', type=int, default=3, help='測試重複次數') + args = parser.parse_args() + + n = args.n + arr = list(range(n)) + K = 100 + (args.student_suffix % 100) + + print('產生陣列長度', n) + print('目標 K=', K) + + def measure(func): + records = [] + last_idx, last_cmp = None, None + for _ in range(args.repeat): + start = time.perf_counter() + idx, cmp = func(arr, K) + end = time.perf_counter() + records.append(end - start) + last_idx, last_cmp = idx, cmp + return sum(records) / len(records), last_idx, last_cmp + + lt, li, lc = measure(linear_search_counted) + bt, bi, bc = measure(binary_search_counted) + + results = { + 'n': n, + 'target': K, + 'linear': {'index': li, 'comparisons': lc, 'time': lt}, + 'binary': {'index': bi, 'comparisons': bc, 'time': bt}, + 'faster': 'linear' if lt < bt else 'binary' + } + + os.makedirs('assets', exist_ok=True) + with open('assets/results_easy.json', 'w', encoding='utf-8') as f: + json.dump(results, f, indent=2, ensure_ascii=False) + + metrics = { + 'linear': {'time': results['linear']['time'], 'comparisons': results['linear']['comparisons'], 'n': n}, + 'binary': {'time': results['binary']['time'], 'comparisons': results['binary']['comparisons'], 'n': n} + } + draw_radar(metrics, 'assets/radar_easy.png') + + print('Linear:', results['linear']) + print('Binary:', results['binary']) + print('Faster:', results['faster']) + +if __name__ == '__main__': + main() diff --git a/weeks/week-18/solutions/36/6/benchmark_search-easy.py b/weeks/week-18/solutions/36/6/benchmark_search-easy.py new file mode 100644 index 000000000..b35a248a5 --- /dev/null +++ b/weeks/week-18/solutions/36/6/benchmark_search-easy.py @@ -0,0 +1,109 @@ +""" +簡易版 benchmark_search(教學用) + +說明:逐步說明每個動作,適合初學者閱讀與學習。 + +主要功能: +- 產生一個升冪陣列(若沒有 stdin 輸入) +- 計算目標 K +- 執行線性與二分搜尋(同時回傳比較次數) +- 測量兩者耗時並儲存結果與產生雷達圖 + +使用方式: + python benchmark_search-easy.py --n 100000 + +""" +import argparse +import time +import json +import os +from timing import timeit +from search import linear_search +from search import binary_search +from search import linear_search as _unused +from plot import draw_radar + +# 這裡設定學號末兩碼的預設值(若你要測真實學號,可從命令列傳入) +DEFAULT_SUFFIX = 36 + +# 我們要計算帶比較次數的版本: + +def linear_search_counted(data, target): + # 逐項比較直到找到或遍歷完 + comps = 0 + for i, v in enumerate(data): + comps += 1 + if v == target: + return i, comps + return -1, comps + + +def binary_search_counted(data, target): + lo = 0 + hi = len(data) - 1 + comps = 0 + while lo <= hi: + mid = (lo + hi) // 2 + comps += 1 + if data[mid] == target: + return mid, comps + elif data[mid] < target: + lo = mid + 1 + else: + hi = mid - 1 + return -1, comps + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--n', type=int, default=100000, help='陣列長度') + parser.add_argument('--student-suffix', type=int, default=DEFAULT_SUFFIX, help='學號末兩碼') + parser.add_argument('--repeat', type=int, default=3, help='測試重複次數') + args = parser.parse_args() + + n = args.n + arr = list(range(n)) # 產生升冪陣列 + K = 100 + (args.student_suffix % 100) + + print('產生陣列長度', n) + print('目標 K=', K) + + # 使用簡單測時:重複執行並取平均 + def measure(func): + records = [] + last_idx, last_cmp = None, None + for _ in range(args.repeat): + start = time.perf_counter() + idx, cmp = func(arr, K) + end = time.perf_counter() + records.append(end - start) + last_idx, last_cmp = idx, cmp + return sum(records) / len(records), last_idx, last_cmp + + lt, li, lc = measure(linear_search_counted) + bt, bi, bc = measure(binary_search_counted) + + results = { + 'n': n, + 'target': K, + 'linear': {'index': li, 'comparisons': lc, 'time': lt}, + 'binary': {'index': bi, 'comparisons': bc, 'time': bt}, + 'faster': 'linear' if lt < bt else 'binary' + } + + os.makedirs('assets', exist_ok=True) + with open('assets/results_easy.json', 'w', encoding='utf-8') as f: + json.dump(results, f, indent=2, ensure_ascii=False) + + metrics = { + 'linear': {'time': results['linear']['time'], 'comparisons': results['linear']['comparisons'], 'n': n}, + 'binary': {'time': results['binary']['time'], 'comparisons': results['binary']['comparisons'], 'n': n} + } + draw_radar(metrics, 'assets/radar_easy.png') + + print('Linear:', results['linear']) + print('Binary:', results['binary']) + print('Faster:', results['faster']) + +if __name__ == '__main__': + main() diff --git a/weeks/week-18/solutions/36/6/caesar_cipher-easy-36.py b/weeks/week-18/solutions/36/6/caesar_cipher-easy-36.py new file mode 100644 index 000000000..479479c99 --- /dev/null +++ b/weeks/week-18/solutions/36/6/caesar_cipher-easy-36.py @@ -0,0 +1,39 @@ +""" +簡易版凱薩密碼程式 + +這個版本使用固定的 7 位移量,適合用來理解基本的字母輪轉邏輯。 +""" + +def shift_char_easy(ch: str, shift: int = 7) -> str: + """將單一字元按照凱薩移位加密。""" + if 'A' <= ch <= 'Z': + base = ord('A') + new_char = chr((ord(ch) - base + shift) % 26 + base) + return new_char + if 'a' <= ch <= 'z': + base = ord('a') + new_char = chr((ord(ch) - base + shift) % 26 + base) + return new_char + return ch + + +def encrypt_line_easy(line: str) -> str: + + result = '' + for ch in line: + result += shift_char_easy(ch) + return result + + +def main() -> None: + + try: + while True: + line = input() + print(encrypt_line_easy(line)) + except EOFError: + pass + + +if __name__ == '__main__': + main() diff --git a/weeks/week-18/solutions/36/6/caesar_cipher-easy.py b/weeks/week-18/solutions/36/6/caesar_cipher-easy.py new file mode 100644 index 000000000..9c26d55cd --- /dev/null +++ b/weeks/week-18/solutions/36/6/caesar_cipher-easy.py @@ -0,0 +1,50 @@ +""" +簡易版凱薩密碼(Caesar Cipher) + +說明:本版本使用 7 位元移位,並保留所有非英文字元。 + +輸入:可讀取多行標準輸入,逐行輸出加密結果。 + +使用方式: + python caesar_cipher-easy.py < input.txt +""" + + +def shift_char_easy(ch: str, shift: int = 7) -> str: + """將單一字元按照凱薩加密規則轉換。 + + - 大寫字母 A-Z 向後移動 shift 位;超過 Z 則從 A 循環。 + - 小寫字母 a-z 同理。 + - 其他字元(數字、標點、空白)保持原樣。 + """ + if 'A' <= ch <= 'Z': + base = ord('A') + new_char = chr((ord(ch) - base + shift) % 26 + base) + return new_char + if 'a' <= ch <= 'z': + base = ord('a') + new_char = chr((ord(ch) - base + shift) % 26 + base) + return new_char + return ch + + +def encrypt_line_easy(line: str) -> str: + """將一行文字中的每個字元進行加密並回傳結果。""" + result = '' + for ch in line: + result += shift_char_easy(ch) + return result + + +def main() -> None: + """從標準輸入讀取多行,逐行輸出加密後結果。""" + try: + while True: + line = input() + print(encrypt_line_easy(line)) + except EOFError: + pass + + +if __name__ == '__main__': + main() diff --git a/weeks/week-18/solutions/36/6/digit_root_base-easy-36.py b/weeks/week-18/solutions/36/6/digit_root_base-easy-36.py new file mode 100644 index 000000000..34ea5bb0a --- /dev/null +++ b/weeks/week-18/solutions/36/6/digit_root_base-easy-36.py @@ -0,0 +1,36 @@ +ALLOWED_BASES = {2,3,5,6,7,8,9,10,11,13,16} + +def digit_root_base_easy(value: int, base: int) -> int: + + if base not in ALLOWED_BASES: + raise ValueError("base not supported") + if value == 0: + return 0 + current = value + + while current >= base: + total = 0 + n = current + # 逐位取餘相加 + while n > 0: + total += n % base + n //= base + current = total + return current + + +if __name__ == '__main__': + import sys + if len(sys.argv) < 2: + print("Usage: python digit_root_base-easy-36.py ", file=sys.stderr) + sys.exit(2) + base = int(sys.argv[1]) + if base not in ALLOWED_BASES: + print(f"Error: base must be one of {sorted(ALLOWED_BASES)}", file=sys.stderr) + sys.exit(2) + for line in sys.stdin: + line = line.strip() + if not line: + continue + value = int(line) + print(digit_root_base_easy(value, base)) \ No newline at end of file diff --git a/weeks/week-18/solutions/36/6/digit_root_base-easy.py b/weeks/week-18/solutions/36/6/digit_root_base-easy.py new file mode 100644 index 000000000..e0cb88516 --- /dev/null +++ b/weeks/week-18/solutions/36/6/digit_root_base-easy.py @@ -0,0 +1,56 @@ +""" +簡易版:進位數字根(易懂版) + +說明:此檔案提供一個容易理解的實作,步驟直觀,適合初學者閱讀。 + +功能: +- `digit_root_base_easy(value, base)` 計算 value 在 base 下的數字根 +- 支援 base 範圍同主程式 + +使用方式(命令列測試): + python digit_root_base-easy.py 7 < input.txt + +""" + +ALLOWED_BASES = {2,3,5,6,7,8,9,10,11,13,16} + + +def digit_root_base_easy(value: int, base: int) -> int: + """直覺版實作說明: + + 1. 如果 value 為 0,回傳 0 + 2. 將 value 用 while 轉為 base 的各位,並加總 + 3. 若加總結果仍 >= base,重複步驟 2 + 4. 最後回傳結果(十進位數字) + """ + if base not in ALLOWED_BASES: + raise ValueError("base not supported") + if value == 0: + return 0 + current = value + + while current >= base: + total = 0 + n = current + # 逐位取餘相加 + while n > 0: + total += n % base + n //= base + current = total + return current + + if __name__ == '__main__': + import sys + if len(sys.argv) < 2: + print("Usage: python digit_root_base-easy.py ", file=sys.stderr) + sys.exit(2) + base = int(sys.argv[1]) + if base not in ALLOWED_BASES: + print(f"Error: base must be one of {sorted(ALLOWED_BASES)}", file=sys.stderr) + sys.exit(2) + for line in sys.stdin: + line = line.strip() + if not line: + continue + value = int(line) + print(digit_root_base_easy(value, base)) \ No newline at end of file diff --git a/weeks/week-18/solutions/36/6/sequence_filter-easy-36.py b/weeks/week-18/solutions/36/6/sequence_filter-easy-36.py new file mode 100644 index 000000000..83d05fcf0 --- /dev/null +++ b/weeks/week-18/solutions/36/6/sequence_filter-easy-36.py @@ -0,0 +1,63 @@ +""" +簡易版數列過濾程式 + +說明:先去除重複元素,再篩選可被 4 整除的數字,最後排序輸出。 +""" + +def process_sequence(numbers): + """處理數列:去重、篩選、排序。""" + seen_set = set() + unique_numbers = [] + + for number in numbers: + if number not in seen_set: + seen_set.add(number) + unique_numbers.append(number) + + print(f"去重後:{unique_numbers}") + + filtered_numbers = [] + for number in unique_numbers: + if number % 4 == 0: + filtered_numbers.append(number) + + print(f"篩選後(能被4整除):{filtered_numbers}") + + if len(filtered_numbers) == 0: + return "NONE" + + result = sorted(filtered_numbers) + print(f"排序後:{result}") + return result + + +def process_sequence_easy(numbers): + """簡易版本的包裝函式,直接呼叫 process_sequence。""" + return process_sequence(numbers) + + +def main_easy(): + """從標準輸入讀取數列,訊息化輸出中間步驟與最終結果。""" + while True: + n = int(input("輸入數列長度 n(0 表示結束):")) + + if n == 0: + print("程式結束") + break + + number_line = input(f"輸入 {n} 個整數(用空白分隔):") + numbers = list(map(int, number_line.split())) + + print(f"\n原始數列:{numbers}") + + result = process_sequence_easy(numbers) + + if result == "NONE": + print(f"最終結果:NONE\n") + else: + output_string = ' '.join(map(str, result)) + print(f"最終結果:{output_string}\n") + + +if __name__ == '__main__': + main_easy() \ No newline at end of file diff --git a/weeks/week-18/solutions/36/6/sequence_filter-easy.py b/weeks/week-18/solutions/36/6/sequence_filter-easy.py new file mode 100644 index 000000000..055be2006 --- /dev/null +++ b/weeks/week-18/solutions/36/6/sequence_filter-easy.py @@ -0,0 +1,101 @@ +""" +簡易版本:序列處理 +功能:去重 → 篩選能被4整除 → 排序 + +這個版本的特點: +1. 代碼簡潔易懂 +2. 邏輯清晰分步驟 +3. 變數名稱直觀 +4. 適合初學者理解 +""" + + +def process_sequence_easy(numbers): + """ + 簡易版:處理單個數列 + + 步驟說明: + 1. 去重(保留第一次出現的順序) + 2. 篩選能被4整除的數 + 3. 排序結果 + + 參數: + numbers (list): 整數列表 + + 返回值: + list: 排序後的結果列表 + str: "NONE"(若無符合條件的數) + """ + + # ==== 步驟 1:去重 ==== + # 使用一個集合記錄已見過的數字 + seen_set = set() + unique_numbers = [] + + # 遍歷原始列表,只保留第一次出現的數字 + for number in numbers: + if number not in seen_set: + seen_set.add(number) + unique_numbers.append(number) + + # 現在 unique_numbers 是去重後的序列 + print(f"去重後:{unique_numbers}") + + # ==== 步驟 2:篩選 ==== + # 創建新列表,只放入能被4整除的數字 + filtered_numbers = [] + + for number in unique_numbers: + if number % 4 == 0: # 判斷能否被4整除 + filtered_numbers.append(number) + + # 現在 filtered_numbers 只包含能被4整除的數字 + print(f"篩選後(能被4整除):{filtered_numbers}") + + # ==== 步驟 3:檢查結果 ==== + # 如果沒有符合條件的數字,返回 "NONE" + if len(filtered_numbers) == 0: + return "NONE" + + # ==== 步驟 4:排序 ==== + # 使用內建的 sorted() 函式排序(由小到大) + result = sorted(filtered_numbers) + + print(f"排序後:{result}") + + return result + + +def main_easy(): + """ + 簡易版主程式 + """ + + while True: + # 讀取第一行:數列的長度 + n = int(input("輸入數列長度 n(0 表示結束):")) + + # 如果 n = 0,表示輸入結束 + if n == 0: + print("程式結束") + break + + # 讀取第二行:n 個整數,用空白分隔 + number_line = input(f"輸入 {n} 個整數(用空白分隔):") + numbers = list(map(int, number_line.split())) + + print(f"\n原始數列:{numbers}") + + # 處理數列 + result = process_sequence_easy(numbers) + + # 輸出結果 + if result == "NONE": + print(f"最終結果:NONE\n") + else: + output_string = ' '.join(map(str, result)) + print(f"最終結果:{output_string}\n") + + +if __name__ == '__main__': + main_easy() diff --git a/weeks/week-18/solutions/36/assets/radar.png b/weeks/week-18/solutions/36/assets/radar.png new file mode 100644 index 000000000..10c408b8d Binary files /dev/null and b/weeks/week-18/solutions/36/assets/radar.png differ diff --git a/weeks/week-18/solutions/36/assets/radar_test.png b/weeks/week-18/solutions/36/assets/radar_test.png new file mode 100644 index 000000000..a3f8a28af Binary files /dev/null and b/weeks/week-18/solutions/36/assets/radar_test.png differ diff --git a/weeks/week-18/solutions/36/assets/results.json b/weeks/week-18/solutions/36/assets/results.json new file mode 100644 index 000000000..64439ee0f --- /dev/null +++ b/weeks/week-18/solutions/36/assets/results.json @@ -0,0 +1,16 @@ +{ + "n": 1000, + "student_suffix": 36, + "target": 136, + "linear": { + "index": 136, + "comparisons": 137, + "time": 3.7999999999982492e-06 + }, + "binary": { + "index": 136, + "comparisons": 10, + "time": 1.9999999999985307e-06 + }, + "faster": "binary" +} \ No newline at end of file