Last active
August 7, 2018 15:31
-
-
Save MilyMilo/10e5b600b38126f49b7b3589f64d2e95 to your computer and use it in GitHub Desktop.
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 characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
var ( | |
tileWidth int | |
tileHeight int | |
horizontalTiles int | |
verticalTiles int | |
signOne string | |
signTwo string | |
) | |
func main() { | |
fmt.Scanf("%d %d %d %d %s %s", &tileWidth, &tileHeight, &horizontalTiles, &verticalTiles, &signOne, &signTwo) | |
if !isValid(tileHeight) || !isValid(tileWidth) || !isValid(verticalTiles) || !isValid(horizontalTiles) { | |
os.Exit(0) | |
} | |
if len(signOne) > 1 || len(signTwo) > 1 { | |
os.Exit(0) | |
} | |
// THIS SHIT NEEDS SOME SERIOUS REFACTORING. | |
// Instead of using modulos and values I decided o go for some shady sign switching | |
// TODO: Refactor -> determine sign for modulo/division | |
// Or maybe just stop toggling and set them | |
useSign := signOne | |
// which row of the tiles is it | |
for verticalTile := 0; verticalTile < verticalTiles; verticalTile++ { | |
tileStartSign := useSign | |
// which row of the tile is it | |
for row := 0; row < tileHeight; row++ { | |
rowStartSign := useSign | |
// which tile it is in a row | |
for horizontalTile := 0; horizontalTile < horizontalTiles; horizontalTile++ { | |
// print one row of one tile | |
for col := 0; col < tileWidth; col++ { | |
fmt.Print(useSign) | |
} | |
// Done printing one row of one tile, toggle signs | |
useSign = toggleSign(useSign, signOne, signTwo) | |
} | |
fmt.Print("\n") | |
// Done printing the whole row, reset sign to initial | |
// workaround for uneven no. horizontal tiles | |
useSign = rowStartSign | |
} | |
// Done printing the whole tile, change sign | |
if useSign == tileStartSign { | |
useSign = toggleSign(useSign, signOne, signTwo) | |
} | |
} | |
} | |
func toggleSign(useSign, signOne, signTwo string) string { | |
if useSign == signOne { | |
useSign = signTwo | |
} else { | |
useSign = signOne | |
} | |
return useSign | |
} | |
func isValid(value int) bool { | |
return value >= 1 && value <= 15 | |
} |
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 characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
var ( | |
width int | |
height int | |
kick int | |
) | |
func main() { | |
fmt.Scanf("%d %d %d", &width, &height, &kick) | |
if width < 0 || height < 0 || kick < -100 { | |
os.Exit(0) | |
} | |
if width > 100 || height > 100 || kick > 100 { | |
os.Exit(0) | |
} | |
switch { | |
case kick >= 0: | |
for i := 0; i < height; i++ { | |
for space := 0; space < i*kick; space++ { | |
fmt.Print(" ") | |
} | |
for char := 0; char < width; char++ { | |
fmt.Print("*") | |
} | |
for space := 0; space < (height-i)*kick; space++ { | |
fmt.Print(" ") | |
} | |
fmt.Print("\n") | |
} | |
case kick < 0: | |
for i := 0; i < height; i++ { | |
for space := 0; space < (height-i)*abs(kick); space++ { | |
fmt.Print(" ") | |
} | |
for char := 0; char < width; char++ { | |
fmt.Print("*") | |
} | |
for space := 0; space < i*kick; space++ { | |
fmt.Print(" ") | |
} | |
fmt.Print("\n") | |
} | |
} | |
} | |
func abs(x int) int { | |
if x < 0 { | |
return -x | |
} | |
return x | |
} |
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 characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
var ( | |
size int | |
armor string | |
) | |
func main() { | |
fmt.Scanf("%d %s", &size, &armor) | |
if size < 1 || size > 75 { | |
os.Exit(0) | |
} | |
if len(armor) > 1 { | |
os.Exit(0) | |
} | |
if armor == "Y" { | |
drawRocketWithArmor() | |
return | |
} | |
if armor == "N" { | |
drawRocketWithoutArmor() | |
return | |
} | |
os.Exit(0) | |
} | |
func drawRocketWithoutArmor() { | |
for row := 1; row <= size; row++ { | |
for module := 0; module < size; module++ { | |
for i := 0; i < row; i++ { | |
fmt.Print("*") | |
} | |
for i := 0; i < size-row; i++ { | |
fmt.Print(" ") | |
} | |
} | |
fmt.Print("\n") | |
} | |
for row := size - 1; row > 0; row-- { | |
for module := 0; module < size; module++ { | |
for i := 0; i < row; i++ { | |
fmt.Print("*") | |
} | |
for i := 0; i < size-row; i++ { | |
fmt.Print(" ") | |
} | |
} | |
fmt.Print("\n") | |
} | |
} | |
func drawRocketWithArmor() { | |
for row := 1; row <= size; row++ { | |
for module := 1; module <= size; module++ { | |
for i := 0; i < row; i++ { | |
if module == 1 && i == 0 { | |
fmt.Print(">") | |
continue | |
} | |
if module == size && i == size-1 { | |
fmt.Print(">") | |
continue | |
} | |
if i == row-1 && row != size { | |
fmt.Print("\\") | |
continue | |
} | |
fmt.Print("*") | |
} | |
for i := 0; i < size-row; i++ { | |
fmt.Print(" ") | |
} | |
} | |
fmt.Print("\n") | |
} | |
for row := size - 1; row > 0; row-- { | |
for module := 1; module <= size; module++ { | |
for i := 0; i < row; i++ { | |
if module == 1 && i == 0 { | |
fmt.Print(">") | |
continue | |
} | |
if i == row-1 { | |
fmt.Print("/") | |
continue | |
} | |
fmt.Print("*") | |
} | |
for i := 0; i < size-row; i++ { | |
fmt.Print(" ") | |
} | |
} | |
fmt.Print("\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment