How to resolve the algorithm Cartesian product of two or more lists step by step in the 11l programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Cartesian product of two or more lists step by step in the 11l programming language
Table of Contents
Problem Statement
Show one or more idiomatic ways of generating the Cartesian product of two arbitrary lists in your language. Demonstrate that your function/method correctly returns: and, in contrast: Also demonstrate, using your function/method, that the product of an empty list with any other list is empty. For extra credit, show or write a function returning the n-ary product of an arbitrary number of lists, each of arbitrary length. Your function might, for example, accept a single argument which is itself a list of lists, and return the n-ary product of those lists. Use your n-ary Cartesian product function to show the following products:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Cartesian product of two or more lists step by step in the 11l programming language
Source code in the 11l programming language
F cart_prod(a, b)
V p = [(0, 0)] * (a.len * b.len)
V i = 0
L(aa) a
L(bb) b
p[i++] = (aa, bb)
R p
print(cart_prod([1, 2], [3, 4]))
print(cart_prod([3, 4], [1, 2]))
[Int] empty_array
print(cart_prod([1, 2], empty_array))
print(cart_prod(empty_array, [1, 2]))
F cart_prod(a, b)
R multiloop(a, b, (aa, bb) -> (aa, bb))
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Sparkling programming language
You may also check:How to resolve the algorithm JSON step by step in the Perl programming language
You may also check:How to resolve the algorithm Delete a file step by step in the E programming language
You may also check:How to resolve the algorithm Polynomial regression step by step in the Python programming language
You may also check:How to resolve the algorithm Symmetric difference step by step in the PHP programming language