Skip to content

Commit

Permalink
feat: reto mouredev#16 - go >> [M]
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-empty committed Jun 6, 2024
1 parent 63a55b3 commit 109d647
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Retos/Reto #16 - LA ESCALERA [Media]/go/qwik-zgheib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"fmt"
"strings"
)

type StairDrawer interface {
DrawStairs(steps int) string
}

type Stairs struct{}

func NewStairs() *Stairs {
return &Stairs{}
}

func (s *Stairs) DrawStairs(steps int) string {
if steps == 0 {
return "__"
}

var builder strings.Builder
if steps > 0 {
for i := steps; i > 0; i-- {
if i == steps {
builder.WriteString(strings.Repeat(" ", i))
builder.WriteString("_\n")
}
builder.WriteString(strings.Repeat(" ", i-1))
builder.WriteString("_|\n")

}
} else {
builder.WriteString("_\n")
for i := 0; i < -steps; i++ {
if i == 0 {
builder.WriteString(" ")
} else {
builder.WriteString(strings.Repeat(" ", i+1))
}
builder.WriteString("|_\n")
}
}
return builder.String()
}

func main() {
stairs := NewStairs()

testCases := []int{4, -4, 0}
for _, steps := range testCases {
fmt.Printf("Steps: %d\n", steps)
fmt.Println(stairs.DrawStairs(steps))
}
}

0 comments on commit 109d647

Please sign in to comment.