Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.67 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func solve(slice [] int) [] int  {
  6.    
  7.     lx := make([]int, len(slice))
  8.     rx := make([]int, len(slice))
  9.  
  10.     for index := 0 ; index < len(slice) ; index++ {
  11.  
  12.         if index == 0 {
  13.  
  14.             lx[index] = 1
  15.  
  16.         } else {
  17.  
  18.             lx[index] = slice[index] * lx[index-1]
  19.         }
  20.     }
  21.  
  22.     for index := 0 ; index < len(slice) ; index++ {
  23.  
  24.         if index == 0 {
  25.             rx[(len(slice)-1)] = 1
  26.  
  27.         } else {
  28.             rx[(len(slice)-1)-index] = rx[(len(slice))-index] * slice[(len(slice)-1)-index]
  29.         }
  30.     }  
  31.  
  32.     for i,_ := range(slice){
  33.         slice[i] = lx[i] * rx[i]
  34.     }
  35.  
  36.     return slice
  37. }
  38.  
  39. func main(){
  40.  
  41.     p := [] int {3,2,1}
  42.     k := solve(p)
  43.     for _,el := range(k){
  44.         fmt.Println(el)
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement