Question: FOR GO PROGRAMMING package main import ( fmt math / rand time ) func main ( ) { / / Seed the

FOR GO PROGRAMMING
package main
import (
"fmt"
"math/rand"
"time"
)
func main(){
// Seed the random number generator
rand.Seed(time.Now().Unix())
// Generate 20 random die tosses
const numTosses =20
tosses := make([]int, numTosses)
for i :=0; i < numTosses; i++{
tosses[i]= rand.Intn(6)+1// Simulate a die toss (1-6)
}
// Print the die values with runs marked
inRun := false
lastToss :=0
for i, toss := range tosses {
if i >0 && toss == lastToss {
if !inRun {
fmt.Print("(")
inRun = true
}
} else {
if inRun {
fmt.Print(lastToss,")")
inRun = false
}
}
fmt.Print(toss,"")
lastToss = toss
}
// Check if a run was still ongoing at the end
if inRun {
fmt.Print(lastToss,")")
}
fmt.Println()
} output 6(66)13246323563(33)436256
Should be (666)1324632356(333)436256

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!