Skip to main content
deleted 15 characters in body
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 5252 49 bytes

map(\x->head$[-1|x<2]++[d|d<-[x-1,x>last$[d|d<-2[1..]x-1],mod x d<1]d<1]++[-1|x<2]) 

Try it online!

map -- for each element in the input array \x-> -- apply the lambda function headlast -- pick the firstlast element of the following list [[d|d<-1|x<2]++[1..x-1] -- all d --from 1 to x-1 if   x<2, followed by  [d|d<-[x-1 ,mod x-2..] d<1]  -- all d from x-1where downd todivides negativex infinity ++[-1|x<2] ,mod x d<1]  --  wherefollowed dby divides-1 xif x<2 

Haskell, 52 bytes

map(\x->head$[-1|x<2]++[d|d<-[x-1,x-2..],mod x d<1]) 

Try it online!

map -- for each element in the input array \x-> -- apply the lambda function head -- pick the first element of the following list [-1|x<2]++ -- -1 if x<2, followed by  [d|d<-[x-1,x-2..] -- all d from x-1 down to negative infinity ,mod x d<1]  --  where d divides x 

Haskell, 52 49 bytes

map(\x->last$[d|d<-[1..x-1],mod x d<1]++[-1|x<2]) 

Try it online!

map -- for each element in the input array \x-> -- apply the lambda function last -- pick the last element of the following list [d|d<-[1..x-1] -- all d from 1 to x-1     ,mod x d<1]  -- where d divides x ++[-1|x<2] -- followed by -1 if x<2 
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 52 bytes

map(\x->head$[-1|x<2]++[d|d<-[x-1,x-2..],mod x d<1]) 

Try it online!

map -- for each element in the input array \x-> -- apply the lambda function head -- pick the first element of the following list [-1|x<2]++ -- -1 if x<2, followed by [d|d<-[x-1,x-2..] -- all d from x-1 down to negative infinity ,mod x d<1] -- where d divides x