Erlang Ladder
-module(ladder).
-export([ladder/2]).
%% Erlang integers are arbitrary precision, so unlike the PHP version we
%% don't need to mask the running Fibonacci total against max(B) on every
%% step to dodge overflow; masking once at the end with each B(i) is enough.
ladder(A, B) ->
MaxA = lists:max(A),
Fib = build_fib(MaxA),
[array:get(Ai + 1, Fib) band ((1 bsl Bi) - 1) || {Ai, Bi} <- lists:zip(A, B)].
build_fib(Limit) ->
Arr0 = array:set(1, 1, array:set(0, 0, array:new(Limit + 2))),
build_fib(2, Limit + 1, Arr0).
build_fib(I, Limit, Arr) when I > Limit ->
Arr;
build_fib(I, Limit, Arr) ->
V = array:get(I - 1, Arr) + array:get(I - 2, Arr),
build_fib(I + 1, Limit, array:set(I, V, Arr)).
This precomputes climb counts once and applies the modulo per query, which avoids recalculating the same paths over and over.