Dear Team,
Below are two functions. And i am beginner in ELIXIR
a) The first one uses Enum_reduce_while
b) the second function uses Enum_reduce
I am observing the following
a) in the first function teh count goes from 0 , 1 , 2, 3 and gets reset (Basically for each row, the count gets reset) when i see the values using print. I was expecting the count to keep incrementing.
b) However in the 2nd function the count keeps incremeting (which is expected). The only difference is that the first one is reduce_while.
Questions
a) We may say that the 2nd Enum’s return is not assigned in Enum_reduce_while. But that’s the same i have done in the next function.
Why is this so and what am i missing?
Sincerely,
Arvind
def is_power_pattern_present_in_grid(grid,pattern,max_row,max_col) when length(pattern) <= max_row*max_col do
count = 0
result = 0
{chk, chk1} =
Enum.reduce_while(0…max_row-1, {result,count}, fn row,{result,count} →
Enum.reduce_while(0…max_col-1, {result,count}, fn col,{result,count} →
IO.puts(“looping throughat #{inspect(row)}, #{inspect(col)},#{inspect(count)}”)
count = count + 1
result = 0
{:cont,{result,count}}
end)
{:cont,{result,count}}
end)
end
def is_power1_pattern_present_in_grid(grid,pattern,max_row,max_col) when length(pattern) <= max_row*max_col do
count = 0
result = 0
{chk, chk1} =
Enum.reduce(0…max_row-1, {result,count}, fn row,{result,count} →
Enum.reduce(0…max_col-1, {result,count}, fn col,{result,count} →
IO.puts(“looping throughat #{inspect(row)}, #{inspect(col)},#{inspect(count)}”)
count = count + 1
result = 0
{result,count}
end)
end)
end