Advertisement
Guest User

Untitled

a guest
Aug 12th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.83 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math/rand"
  6.     "sort"
  7.     "time"
  8. )
  9.  
  10. const rowLim = 1000000000
  11.  
  12. func main() {
  13.     var startTime = time.Now() //Benchmark
  14.  
  15.     var groups [rowLim]int
  16.     var res [rowLim]int
  17.     //Fill the dataset with random values
  18.     for i := 0; i < rowLim; i++ {
  19.         groups[i] = rand.Intn(3)
  20.         res[i] = rand.Intn(3)
  21.     }
  22.     //Sort groups together
  23.     sort.Ints(groups[:])
  24.  
  25.     //Pre-Loop
  26.     var lastResult = -1
  27.     var lastGroup = -1
  28.     var currentCount = 0
  29.     var triples = 0
  30.  
  31.     //Logic
  32.     for x := 0; x < len(groups); x++ {
  33.         if res[x] == lastResult && groups[x] == lastGroup {
  34.             currentCount++
  35.             if currentCount >= 3 {
  36.                 triples++
  37.             }
  38.         } else {
  39.             currentCount = 1
  40.         }
  41.         lastResult = res[x]
  42.         lastGroup = groups[x]
  43.     }
  44.  
  45.     //Output
  46.     fmt.Println("Sets of Triples:", triples)
  47.     fmt.Println("Took:", time.Since(startTime))
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement