How to resolve the algorithm Cartesian product of two or more lists step by step in the Ring 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 Ring 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 Ring programming language

Source code in the ring programming language

# Project : Cartesian product of two or more lists

list1 = [[1,2],[3,4]]
list2 = [[3,4],[1,2]]
cartesian(list1)
cartesian(list2)

func cartesian(list1)
     for n = 1 to len(list1[1])
         for m = 1 to len(list1[2])
             see "(" + list1[1][n] + ", " + list1[2][m] + ")" + nl
         next
      next
      see nl

  

You may also check:How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the Go programming language
You may also check:How to resolve the algorithm AKS test for primes step by step in the Idris programming language
You may also check:How to resolve the algorithm The Name Game step by step in the Nim programming language
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the VAX Assembly programming language
You may also check:How to resolve the algorithm Combinations and permutations step by step in the zig programming language