Created
December 31, 2018 16:40
-
-
Save LIQRGV/b70a547e5078cf0a9ff6cad3b80c44b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ez_pattern(n, current=1): | |
if n == current: | |
__ez_pattern_mid(n, current) | |
else: | |
__ez_pattern_top(current, n) | |
ez_pattern(n, current + 1) | |
__ez_pattern_bot(current, n) | |
def __get_mult(printed_char, n): | |
div_printed_char = printed_char // 4 | |
mod_printed_char = printed_char % 4 | |
return div_printed_char + (1 if mod_printed_char != 0 else 0) # can simplify to `div_printed_char + mod_printed_char != 0` | |
def __ez_pattern_mid(printed_char, n): | |
mult = __get_mult(printed_char, n) | |
printed_code_left = (["x", " ", "o", " "] * mult)[slice(printed_char)] | |
printed_code_right = (["x", " ", "o", " "] * mult)[slice(printed_char - 1)] | |
printed_code_right.reverse() | |
printed_code = printed_code_left + printed_code_right | |
print(''.join(printed_code)) | |
def __ez_pattern_top(printed_char, n): | |
mult = __get_mult(printed_char, n) | |
printed_code = (["x", " ", "o", " "] * mult)[slice(printed_char)] | |
printed_code.reverse() | |
print(" " * (n - 1), end='') | |
print(''.join(printed_code)) | |
def __ez_pattern_bot(printed_char, n): | |
mult = __get_mult(printed_char, n) | |
printed_code = (["x", " ", "o", " "] * mult)[slice(printed_char)] | |
print(" " * (n - printed_char), end='') | |
print(''.join(printed_code)) | |
ez_pattern(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment