add new solutions
This commit is contained in:
parent
ee1868a10e
commit
2012261d3d
7 changed files with 205 additions and 0 deletions
23
solutions/7/q799/solution.go
Normal file
23
solutions/7/q799/solution.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package q799
|
||||
|
||||
func champagneTower(poured, query_row, query_glass int) float64 {
|
||||
buf := [100]float64{float64(poured)}
|
||||
for r := range query_row + 1 {
|
||||
var spill float64 = 0
|
||||
for c := range r + 1 {
|
||||
if r == query_row && c == query_glass {
|
||||
return max(buf[c], 1)
|
||||
}
|
||||
|
||||
if buf[c] > 1 {
|
||||
buf[c] = (buf[c] - 1) / 2
|
||||
buf[c], spill = buf[c]+spill, buf[c]
|
||||
} else {
|
||||
buf[c], spill = spill, 0
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var _ = champagneTower
|
||||
Loading…
Add table
Add a link
Reference in a new issue