Advertisement
Spocoman

10. Diamond

Sep 26th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.24 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strings"
  6. )
  7.  
  8. func main() {
  9.     var n int
  10.     fmt.Scanln(&n)
  11.    
  12.    var inDashes, outDashes, border string
  13.  
  14.     for i := 0; i < n / 2 + (n % 2); i++ {
  15.         outDashes = strings.Repeat("-", (n - 1) / 2 - i)
  16.         border = "*"
  17.  
  18.         if i == 0 {
  19.             if n % 2 == 0 {
  20.                 border = "**"
  21.             }
  22.             fmt.Println(outDashes + border + outDashes)
  23.         } else {
  24.             inDashes = strings.Repeat("-", i * 2)
  25.             if n % 2 == 1 {
  26.                 inDashes = strings.Repeat("-", i * 2 - 1)
  27.             }
  28.             fmt.Println(outDashes + border + inDashes + border + outDashes)
  29.         }
  30.     }
  31.  
  32.     for i := n / 2 - (1 + (n - 1) % 2); i >= 0; i-- {
  33.         outDashes = strings.Repeat("-", (n - 1) / 2 - i)
  34.         border = "*"
  35.  
  36.         if i == 0 {
  37.             if n % 2 == 0 {
  38.                 border = "**"
  39.             }
  40.             fmt.Println(outDashes + border + outDashes)
  41.         } else {
  42.             inDashes = strings.Repeat("-", i * 2)
  43.             if (n % 2 == 1) {
  44.                 inDashes = strings.Repeat("-", i * 2 - 1)
  45.             }
  46.             fmt.Println(outDashes + border + inDashes + border + outDashes)
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement