Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Floyds-triangle/Go/floyds-triangle.go
Normal file
27
Task/Floyds-triangle/Go/floyds-triangle.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
floyd(5)
|
||||
floyd(14)
|
||||
}
|
||||
|
||||
func floyd(n int) {
|
||||
fmt.Printf("Floyd %d:\n", n)
|
||||
lowerLeftCorner := n*(n-1)/2 + 1
|
||||
lastInColumn := lowerLeftCorner
|
||||
lastInRow := 1
|
||||
for i, row := 1, 1; row <= n; i++ {
|
||||
w := len(fmt.Sprint(lastInColumn))
|
||||
if i < lastInRow {
|
||||
fmt.Printf("%*d ", w, i)
|
||||
lastInColumn++
|
||||
} else {
|
||||
fmt.Printf("%*d\n", w, i)
|
||||
row++
|
||||
lastInRow += row
|
||||
lastInColumn = lowerLeftCorner
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue