Last active
September 22, 2021 12:22
Revisions
-
jerinisready renamed this gist
Sep 22, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jerinisready created this gist
Sep 22, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,113 @@ #### PATTERN PRINTING ``` C G C O N G C O D I N G C O D I D I N G C O D I N O D I N G C O D I N G C O D I N G C O D I N O D I N G C O D I D I N G C O D I N G C O N G C G ``` ##### Consider it as Boxes ``` C _ _ _ _ _| _ _ _ _ _ G C O _ _ _ _| _ _ _ _ N G C O D _ _ _| _ _ _ I N G C O D I _ _| _ _ D I N G C O D I N _| _ O D I N G C O D I N G| C O D I N G -----------|------------ C O D I N _| _ O D I N G C O D I _ _| _ _ D I N G C O D _ _ _| _ _ _ I N G C O _ _ _ _| _ _ _ _ N G C _ _ _ _ _| _ _ _ _ _ G ``` ##### SOLUTION Part 1. Consider Upper Segment First. ``` C G C O N G C O D I N G C O D I D I N G C O D I N O D I N G C O D I N G C O D I N G ``` ##### SOLUTION Part 2. Consider Upper Left Triangle First. ``` C C O C O D C O D I C O D I N C O D I N G ``` ##### SOLUTION Part 3. Consider Put enough spaces with upper left Triangle to make it a square. ``` C _ _ _ _ _ C O _ _ _ _ C O D _ _ _ C O D I _ _ C O D I N _ C O D I N G ``` ##### SOLUTION Part 4. Then repeat the same spaces to get it for upper right box. ``` C _ _ _ _ _ _ _ _ _ _ C O _ _ _ _ _ _ _ _ C O D _ _ _ _ _ _ C O D I _ _ _ _ C O D I N _ _ C O D I N G ``` ##### SOLUTION Part 5. Then add the corresponding letters. ``` C _ _ _ _ _ _ _ _ _ _ G C O _ _ _ _ _ _ _ _ N G C O D _ _ _ _ _ _ I N G C O D I _ _ _ _ D I N G C O D I N _ _ O D I N G C O D I N G C O D I N G ``` ##### SOLUTION Part 6. Let's try that for bottom portion. ``` C O D I N _ _ O D I N G C O D I _ _ _ _ D I N G C O D _ _ _ _ _ _ I N G C O _ _ _ _ _ _ _ _ N G C _ _ _ _ _ _ _ _ _ _ G ``` bhy This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ __author__ = "@jerinisready" __doc__ = """Pattern Printing Breakdown.""" def main(): word = "CODING" length = len(word) # Top Portion for i in range(1, length+1): # line - part one - character for j in range(0, i): char = word[j] print(char, end=' ') no_of_spaces = length - i # line - part two - spaces print("_ " * no_of_spaces, end="") # line - part three - spaces print("_ " * no_of_spaces, end="") # line - part four - character reverse. # range(start, stop, step) # range(12, 6, -1) # => [12, 11, 10, 9, 8 ,7] # i for j in range(i, 0, -1): char = word[-j] # a= 10; => -a => -10 print(char, end=" ") print() # Bottom Portion for i in range(length-1, 0): # line - part one - character for j in range(0, i): char = word[j] print(char, end=' ') no_of_spaces = length - i # line - part two - spaces print("_ " * no_of_spaces, end="") # line - part three - spaces print("_ " * no_of_spaces, end="") # line - part four - character reverse. # range(start, stop, step) # range(12, 6, -1) # => [12, 11, 10, 9, 8 ,7] # i for j in range(i, 0, -1): char = word[-j] # a= 10; => -a => -10 print(char, end=" ") print() if __name__ == "__main__": "Run Main Program" main() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ __author__ = "@jerinisready" __doc__ = """Pattern Printing Breakdown.""" def print_line(i, word, length): # line - part one - character for j in range(0, i): char = word[j] print(char, end=' ') no_of_spaces = length - i # line - part two - spaces print("_ " * no_of_spaces, end="") # line - part three - spaces print("_ " * no_of_spaces, end="") # line - part four - character reverse. # range(start, stop, step) # range(12, 6, -1) # => [12, 11, 10, 9, 8 ,7] # i for j in range(i, 0, -1): char = word[-j] # a= 10; => -a => -10 print(char, end=" ") print() def main(): word = "CODING" length = len(word) # Top Portion for i in range(1, length+1): print_line(i, word, length) for i in range(length-1, 0, -1): print_line(i, word, length) # DRY => Do not Repeat Yourself. if __name__ == "__main__": "Run Main Program" main() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ __author__ = "@jerinisready" __doc__ = """Pattern Printing Breakdown.""" def main(): word = "CODING" length = len(word) # 6 # Top Portion for i in (1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1): # line - part one - character for j in range(0, i): char = word[j] print(char, end=' ') no_of_spaces = length - i # line - part two - spaces print("_ " * no_of_spaces, end="") # line - part three - spaces print("_ " * no_of_spaces, end="") # line - part four - character reverse. # range(start, stop, step) # range(12, 6, -1) # => [12, 11, 10, 9, 8 ,7] # i for j in range(i, 0, -1): char = word[-j] # a= 10; => -a => -10 print(char, end=" ") print() if __name__ == "__main__": "Run Main Program" main() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ __author__ = "@jerinisready" __doc__ = """Pattern Printing Breakdown.""" def main(): word = "CODING" length = len(word) # 6 arr = [] for i in range(1, length+1): arr.append(i) for i in range(length-1, 1): arr.append(i) # Top Portion for i in arr: # line - part one - character for j in range(0, i): char = word[j] print(char, end=' ') no_of_spaces = length - i # line - part two - spaces print("_ " * no_of_spaces, end="") # line - part three - spaces print("_ " * no_of_spaces, end="") # line - part four - character reverse. # range(start, stop, step) # range(12, 6, -1) # => [12, 11, 10, 9, 8 ,7] # i for j in range(i, 0, -1): char = word[-j] # a= 10; => -a => -10 print(char, end=" ") print() if __name__ == "__main__": "Run Main Program" main() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ __author__ = "@jerinisready" __doc__ = """Pattern Printing Breakdown.""" def main(): word = "CODING" length = len(word) # 6 arr = [i for i in range(1, length+1)] + [i for i in range(length-1, 0, -1)] # Top Portion for i in arr: # line - part one - character for j in range(0, i): char = word[j] print(char, end=' ') no_of_spaces = length - i # line - part two - spaces print("_ " * no_of_spaces, end="") # line - part three - spaces print("_ " * no_of_spaces, end="") # line - part four - character reverse. # range(start, stop, step) # range(12, 6, -1) # => [12, 11, 10, 9, 8 ,7] # i for j in range(i, 0, -1): char = word[-j] # a= 10; => -a => -10 print(char, end=" ") print() if __name__ == "__main__": "Run Main Program" main() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ __author__ = "@jerinisready" __doc__ = """Pattern Printing Breakdown.""" """ Just For fun, I have triued to solve the mystery in minumum lines of code. using joins, splices etc. instead of using loops! #NB * in list is a python spread operator to spread range objects into a list and return the list. . """ def main(): word = "CODING" length = len(word) for i in [*range(1, length+1), *range(length-1, 0, -1)]: no_of_spaces = length - i _left_string = word[:i] left_string = " ".join(_left_string) spaces = " " * 2 * 2 * no_of_spaces _right_string = word[-i:] right_string = " ".join(_right_string) print(left_string, spaces, right_string) if __name__ == "__main__": "Run Main Program" main() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ ##### Part 01. for i th line, print '0'th to 'i'th characters one by one from variable `word` ``` for j in range(0, i): char = word[j] print(char, end=' ') ``` ##### Part 02. for length - i spaces. ``` print("_ " * no_of_spaces, end="") ``` ##### Part 03. for length - i spaces. ``` print("_ " * no_of_spaces, end="") ``` ##### Part 04. for i th line, print '-i'th to '-1'st characters one by one from variable `word` ``` for j in range(i, 0, -1): char = word[-j] print(char, end=" ") ```