And final solution, which as admittedly very verbose.
defmoduleMakeArrayConsecutivedo# statues = [6, 2, 3, 8]# makeArrayConsecutive2(statues) = 3defmakeArrayConsecutive2(statues)docasecheck_singleton_or_double(statues)do0->0[x,y]->y-x-1list->list|>Enum.sort()|>number_of_holes()|>return_difference()endend# I rename the function and added a second case when the list has two items.defpcheck_singleton_or_double(xs)docasexsdo[x]->0[x,y]->Enum.sort([x,y])list->listendenddefpreturn_difference({x,y})doyenddefpnumber_of_holes(sorted_list)doEnum.reduce(sorted_list,{0,0},fn(x,acc)->caseaccdo{0,0}->{x,0}|>IO.inspect(){number,difference}->ifx-number<=1do{x,difference}|>IO.inspect()else{x,difference+(x-number-1)}|>IO.inspect()endendend)endend
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
And final solution, which as admittedly very verbose.