Advertisement
Guest User

Untitled

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