Long stairs: Difference between revisions
Content added Content deleted
No edit summary |
(Added Go) |
||
Line 287: | Line 287: | ||
190 PRINT TIMET/10000 |
190 PRINT TIMET/10000 |
||
200 PRINT STEPST/10000</lang> |
200 PRINT STEPST/10000</lang> |
||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
<lang go>package main |
|||
import ( |
|||
"fmt" |
|||
"math/rand" |
|||
"time" |
|||
) |
|||
func main() { |
|||
rand.Seed(time.Now().UnixNano()) |
|||
totalSecs := 0 |
|||
totalSteps := 0 |
|||
fmt.Println("Seconds steps behind steps ahead") |
|||
fmt.Println("------- ------------ -----------") |
|||
for trial := 1; trial < 10000; trial++ { |
|||
sbeh := 0 |
|||
slen := 100 |
|||
secs := 0 |
|||
for sbeh < slen { |
|||
sbeh++ |
|||
for wiz := 1; wiz < 6; wiz++ { |
|||
if rand.Intn(slen) < sbeh { |
|||
sbeh++ |
|||
} |
|||
slen++ |
|||
} |
|||
secs++ |
|||
if trial == 1 && secs > 599 && secs < 610 { |
|||
fmt.Printf("%d %d %d\n", secs, sbeh, slen-sbeh) |
|||
} |
|||
} |
|||
totalSecs += secs |
|||
totalSteps += slen |
|||
} |
|||
fmt.Println("\nAverage secs taken:", float64(totalSecs)/10000) |
|||
fmt.Println("Average final length of staircase:", float64(totalSteps)/10000) |
|||
}</lang> |
|||
{{out}} |
|||
Sample run: |
|||
<pre> |
|||
Seconds steps behind steps ahead |
|||
------- ------------ ----------- |
|||
600 2138 962 |
|||
601 2143 962 |
|||
602 2148 962 |
|||
603 2153 962 |
|||
604 2159 961 |
|||
605 2163 962 |
|||
606 2167 963 |
|||
607 2172 963 |
|||
608 2177 963 |
|||
609 2183 962 |
|||
Average secs taken: 2917.9058 |
|||
Average final length of staircase: 14689.519 |
|||
</pre> |
|||
=={{header|jq}}== |
=={{header|jq}}== |