DEV Community

Discussion on: Daily Challenge #278 - Find all non-consecutive numbers

Collapse
 
n8chz profile image
Lorraine Lee

SWI Prolog again

nonconsecutive(List, NC) :-
  findall(
    X,
    (
      nextto(A, B, List),
      \+ succ(A, B),
      nth0(Index, List, B),
      X = Index-B
    ),
    NC).
Collapse
 
n8chz profile image
Lorraine Lee

Ruby

def nonconsecutive(a)
  a.each_with_index.drop(1).to_h.invert.select{|k, v| v-a[k-1] != 1}
end