commit 23e4ceb168c31a200a1b79eb7195122607f7f0f2 Author: louiscklaw Date: Sat Feb 1 02:01:47 2025 +0800 update, diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d54c38a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,31 @@ +*.mp4 filter=lfs diff=lfs merge=lfs +*.zip filter=lfs diff=lfs merge=lfs +*.7z filter=lfs diff=lfs merge=lfs +*.tar.gz filter=lfs diff=lfs merge=lfs +*.jpg filter=lfs diff=lfs merge=lfs +*.png filter=lfs diff=lfs merge=lfs +*.avif filter=lfs diff=lfs merge=lfs +*.webm filter=lfs diff=lfs merge=lfs +*.mkv filter=lfs diff=lfs merge=lfs + +# Documents +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain + +*.gif filter=lfs diff=lfs merge=lfs +*.GIF filter=lfs diff=lfs merge=lfs +*.bmp filter=lfs diff=lfs merge=lfs +*.BMP filter=lfs diff=lfs merge=lfs +*.tiff filter=lfs diff=lfs merge=lfs +*.TIFF filter=lfs diff=lfs merge=lfs +*.wav filter=lfs diff=lfs merge=lfs +*.WAV filter=lfs diff=lfs merge=lfs +*.log filter=lfs diff=lfs merge=lfs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67a5a14 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/~*.* \ No newline at end of file diff --git a/gitUpdate.bat b/gitUpdate.bat new file mode 100644 index 0000000..1efde65 --- /dev/null +++ b/gitUpdate.bat @@ -0,0 +1,7 @@ +git status . + +@pause + +git add . +git commit -m"update hck717," +start git push \ No newline at end of file diff --git a/gitUpdate.sh b/gitUpdate.sh new file mode 100755 index 0000000..c96734f --- /dev/null +++ b/gitUpdate.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -ex + +git config --global http.version HTTP/1.1 +git config --global lfs.allowincompletepush true +git config --global lfs.locksverify true +git config --global http.postBuffer 5368709120 + +git add . + +git commit -m 'update,' + +git push + +echo "done" diff --git a/q1.md b/q1.md new file mode 100644 index 0000000..9faaf9c --- /dev/null +++ b/q1.md @@ -0,0 +1,34 @@ +A peak in a 1D list of values is a value that is not smaller than its neighbours. Assume all values are natural numbers. + +For example, consider the following list of values +a = [1, 6, 7, 4, 3, 2, 1, 4, 5, 6] + +Here, 7 is a peak and 6 is a peak. + +Write a python program that uses recursion to find a peak (not all, just one peak) given a list of values. +Your function should return the list index of the peak. +To do so you must implement the following recursive algorithm that uses the same idea as binary search (i.e., divide and conquer). + •Recursively look at position n//2 + •if a[n//2] < a[n//2 - 1] then only look at left half 0 … n//2-1 to look for a peak + •else if a[n//2] < a[n//2 + 1] then only look at right half n//2+1 … n-1 to look for a peak + •else n//2 position is a peak + +Note that although there are two peaks in the given example, this method will only find peak 7 at index 2. Your program must follow this behaviour. + +Input specification: + • +A line with the numbers separated by space + +Output specification: + • +The index of the peak + +Sample testcases (The bolded text are user input) + +Case 1: +1 6 7 4 3 2 1 4 5 6 +2 + +Case 2: +1 10 2 +1 \ No newline at end of file diff --git a/q2.md b/q2.md new file mode 100644 index 0000000..7c05e3b --- /dev/null +++ b/q2.md @@ -0,0 +1,48 @@ +A peak in a 2D list of values is a value that is not smaller than its 4 neighbours. Assume all values are natural numbers. + +For example, consider the following list of values +a = [[10, 8, 10, 10], + [14, 13, 12, 11], + [15, 9, 11, 21], + [16, 17, 19, 20]] + +Here, 21 is the only peak. + +Write a python program that uses recursion to find a peak (not all, just one peak) given a list of 2D values (m columns, n rows). +Your function should return the list index as a tuple of the peak. +To do so you must implement the following recursive algorithm that uses the same idea as binary search (i.e., divide and conquer). + • Pick middle column j = m//2 + • Find global max on column j at (i, j), if there are multiple global max, pick the smallest possible i + • Compare (i, j-1), (i, j), (i, j+1) + • Pick left columns if (i, j-1) > (i, j) + ◦ Similar for right + • (i, j) is a 2D-peak if neither conditions holds + • Solve the new problem with half the number of columns + • When you have a single column, find global max and you are done (again, if there are multiple global max, pick the smallest possible index) + +Similar to Q4, this method will always find a specific peak among all the others that may exist in the list of 2D values. Your program must follow this behaviour. + +Input specification: + • n lines and m columns of numbers separated by space + • follow by an empty line input to determine the end of the input + +Output specification: + • The index as a tuple of the peak + +Sample testcases (The bolded text are user input, including the blank line) + +Case 1: +10 8 10 10 +14 13 12 11 +15 9 11 21 +16 17 19 20 + +(2, 3) + +Case 2: +1 2 3 +4 5 6 +7 8 9 +10 11 12 + +(3, 2) \ No newline at end of file