The first function is faster because you only calculate the top number once. In the second function, you create all numbers from 2 to the square root plus one. The integers 20096056 are listed.
lists:seq(2, round(math:sqrt(Val)) % Creates a list from 2 to 20096056
Your problem is not suitable for a solution that creates all the search space in memory due to lack of space and performance.
In conclusion, the use of lists here is very unproductive.
As for naming conventions: when a function has a different arity (a different number of arguments), it usually calls it the same. Erlang does not consider it the same function, although functions with the same name and arity are considered equal.
find_factors(Val)-> find_factor_rec([], round(math:sqrt(Val)) + 1, Val, 2). find_factors(List, Max, _, NextValue) when NextValue > Max -> List; find_factors(List, Max, Value, NextValue) -> if (Value rem NextValue =:= 0) -> find_factors([NextValue|List], Max, Value, NextValue + 1); true -> find_factors(List, Max, Value, NextValue + 1) end.
source share