Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Last active December 21, 2016 01:50
Show Gist options
  • Save gitaficionado/b443e7a20af9b2004bbcfe7235cb07ff to your computer and use it in GitHub Desktop.
Save gitaficionado/b443e7a20af9b2004bbcfe7235cb07ff to your computer and use it in GitHub Desktop.
Partial solution for Mirror.java
Draws a scalable mirror
Goal (size 3):
#============#
| <><> |
| <>....<> |
|<>........<>|
|<>........<>|
| <>....<> |
| <><> |
#============#
Pseudocode:
draw # (12x =) #
for each of 3 lines
draw some spaces, <>, some dots, <>, some spaces
line spaces dots
1 4 0
2 2 4
3 0 8
for each of 3 lines
draw some spaces, <>, some dots, <>, some spaces
line spaces dots
1 0 8
2 2 4
3 4 0
draw # (12x =) #
*/
// Prints the expanding pattern of <> for the top half of the figure.
public static void topHalf() {
for (int line = 1; line <= 4; line++) {
System.out.print("|");
for (int space = 1; space <=
(line * -2 + 8)
; space++) {
System.out.print(" ");
}
System.out.print("<>");
for (int dot = 1; dot <=
(line * 4 - 4)
; dot++) {
System.out.print(".");
}
System.out.print("<>");
for (int space = 1; space <=
(line * -2 + 8)
; space++) {
System.out.print(" ");
}
System.out.println("|");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment