Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diamond #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 24 additions & 1 deletion practice/diamond/diamond.py
Original file line number Diff line number Diff line change
@@ -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.

Loading