diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 48d1bde..e1ba390 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -30,10 +30,11 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Test with pytest run: | - pytest --continue-on-collection-errors + git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* + git diff origin/main HEAD --name-only -- practice | xargs dirname | sort | uniq | xargs pytest - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics \ No newline at end of file diff --git a/practice/diamond/diamond.py b/practice/diamond/diamond.py index 14f2850..4b6bb0e 100644 --- a/practice/diamond/diamond.py +++ b/practice/diamond/diamond.py @@ -1,2 +1,25 @@ def rows(letter): - pass + rows = [] + size = 2 * (ord(letter) - ord('A')) + 1 # size of the diamond + + for i in range(size): # iterate over the rows + row = ' ' * abs(size // 2 - i) # spaces before the first letter + row += chr(ord('A') + min(i, size - i - 1)) # first letter + + if i != 0 and i != size - 1: # middle row + row += ' ' * (2 * min(i, size - i - 1) - 1) # spaces between the letters + row += chr(ord('A') + min(i, size - i - 1)) # second letter + + row += ' ' * abs(size // 2 - i) # spaces after the second letter + rows.append(row) # add the row to the list + + return rows + +pass + +# My Understanding of the pattern ---> +# It starts with the letter 'A' at the top and goes up to the input letter, then back down to 'A'. +# Each row of the diamond has two same letters, except for the first and last rows which have one letter +# The letters are separated by spaces, and the number of spaces between the letters increases by two with each row +# from the top to the middle, then decreases by two with each row from the middle to the bottom. +