The Lisp language has a family of functions
cadr, etc for accessing arrays. For each one, an
a defines taking the first item of an array, and a
d defines taking the rest.
For example, running
[[1,3,4],5,7] will return
[3,4] as the
a gets the first item (
[1,3,4]) and the
d removes the first item.
We've already had a challenge regarding running a
cadaddadadaddddaddddddr on a list, but what about the reverse?
Your challenge is to, given a string of the type above (starting with a
c, ending with a
r, with only
ad in the middle), and a single value, create an array such that running the string as a
cadaddadadaddddaddddddr on the array returns said value.
For example, given the input
cadar, 1 a possible output could be
[[0,]] since running
cadar on that gives 1.
This is code-golf, shortest wins!
These are possible outputs, all that matters is that your program returns an array which works for the condition.
car, 3 =>  cdddar, 5 => [0,0,0,5] cadadadadar, 4 => [[0,[0,[0,[0,]]]]] caaaaaaaaar, 2 => [[[[[[[[[]]]]]]]]]