• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. How to print all possible combinations from an input list...

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 143
  • Views 6489
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to print all possible combinations from an input list.

MorrisDH
MorrisDH over 2 years ago

example input list: p1, p2, etc represent cdf parameter names. The associated list represent the parameter values.


((p1 ("179n" "181n")) (p2 ("45")) (p3 ("70n" "72n")) (p4 ("89n" "91n")) (p5 ("89n" "91n")) (p6 ("3.59u" "3.61u")))

desired output would be all possible combination - there would 32 possible combinations - only first four shown below. The blank line is for clarity but is not required.


p1 "179n"
p2 "45"
p3 "70n"
p4 "89n"
p5 "89n"
p6 "3.59u"

p1 "179n"
p2 "45"
p3 "70n"
p4 "89n"
p5 "89n"
p6 "3.61u"

p1 "179n"
p2 "45"
p3 "70n"
p4 "89n"
p5 "91n"
p6 "3.59u"

p1 "179n"
p2 "45"
p3 "70n"
p4 "89n"
p5 "91n"
p6 "3.61u"

etc

Hope my question is clear.

  • Cancel
Parents
  • MorrisDH
    MorrisDH over 2 years ago

    I got this to work for a list that has 9 cdf parameters defined. I named the input list "tests"

        foreach(test tests
          cellName = car(test)
          printf("Testing %s\n" cellName)
          test = cdr(test)
          testValues = list()
          foreach(param test
            param = parseString(param " ")
            param = list(stringToSymbol(car(param)) parseString(cadr(param) ":"))
            testValues = append1(testValues param)
          ) ; foreach
          ;println(testValues)
          foreach(i0 cadr(nth(0 testValues))
          foreach(i1 cadr(nth(1 testValues))
          foreach(i2 cadr(nth(2 testValues))
          foreach(i3 cadr(nth(3 testValues))
          foreach(i4 cadr(nth(4 testValues))
          foreach(i5 cadr(nth(5 testValues))
          foreach(i6 cadr(nth(6 testValues))
          foreach(i7 cadr(nth(7 testValues))
          foreach(i8 cadr(nth(8 testValues))
            printf("dbCreateParamInstByMasterName(cvId \"myLib" \"%s\" \"layout\" nil 0:0 \"R0\" 1\nlist(" cellName)
            printf("%L %L\n" car(nth(0 testValues)) i0)
            printf("%L %L\n" car(nth(1 testValues)) i1)
            printf("%L %L\n" car(nth(2 testValues)) i2)
            printf("%L %L\n" car(nth(3 testValues)) i3)
            printf("%L %L\n" car(nth(4 testValues)) i4)
            printf("%L %L\n" car(nth(5 testValues)) i5)
            printf("%L %L\n" car(nth(6 testValues)) i6)
            printf("%L %L\n" car(nth(7 testValues)) i7)
            printf("%L %L)\n)\n" car(nth(8 testValues)) i8)
          )))))))))

    It's ugly and it is required to know the number of parameters in advance.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AaronSymko
    AaronSymko over 2 years ago in reply to MorrisDH

    Here's a solution that uses recursion:


    procedure( permuteParams(paramList @optional retVal)
      if(length(paramList) == 0 then
         foreach(i retVal
           printf("%s %L\n" car(i) cadr(i))
         ); foreach
         printf("\n")
      else
        let((entry pname plist)
          entry = car(paramList)
          paramList = cdr(paramList)
          pname = car(entry)
          plist = cadr(entry)
          foreach(value plist
            retVal = append1(retVal list(pname value)) ;; push
            permuteParams(paramList retVal)              ;; recurse
            retVal = reverse(cdr(reverse(retVal)))          ;; pop
          ); foreach
        ); let
      ); if
    ); procedure

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to AaronSymko

    I was thinking about this overnight, and indeed a recursive solution is a good way of implementing this. Mine is more efficient (uses less memory and is faster. because it's not using append and reverse throughout), and also returns a list of all the results for convenience:

    procedure(CCFgenerateParamPermutations(assocList @optional cumulative results)
      if(assocList then
        let(((paramName caar(assocList)))
          foreach(value cadar(assocList)
            results=CCFgenerateParamPermutations(
              cdr(assocList)
              cons(list(paramName value) cumulative)
              results
            )
          )
        )
      else
        results=cons(cumulative results)
      )
      results
    )
    

    Then you can do:

    allPerms=CCFgenerateParamPermutations(data)

    where data is your input assoc list.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MorrisDH
    MorrisDH over 2 years ago in reply to Andrew Beckett

    Hi Andrew,

    This works very well

    Thanks,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • MorrisDH
    MorrisDH over 2 years ago in reply to Andrew Beckett

    Hi Andrew,

    This works very well

    Thanks,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information