• 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. Allegro X PCB Editor
  3. Check for lowest value and make a list

Stats

  • Replies 7
  • Subscribers 161
  • Views 14843
  • Members are here 0
More Content

Check for lowest value and make a list

Javinder
Javinder over 16 years ago

My problem is that I have a long list of lists that I would pick out the some of the lists depending of some criteria.

Example: I would like to pick out the lowest value in the 2th coulumn for each value in the first column.

(("BOTTOM" 650)
    ("BOTTOM" 650)
    ("BOTTOM" 650)
    ("BOTTOM" 750)
    ("BOTTOM" 650)
    ("BOTTOM" 450)
    ("BOTTOM" 650)
    ("BOTTOM" 650)
    ("TOP" 500)
    ("TOP" 500)
    ("TOP" 450)
    ("TOP" 350)
    ("TOP" 500)
    ("TOP" 500)
    ("TOP" 500) )

 Can any one give me some example code snippets

  • Sign in to reply
  • Cancel
  • Anton
    Anton over 16 years ago

     Hello,

    You can try something like:

    prog((longList min items)

    longList=_your_long_list_of_lists_

    min=nil items=nil

    foreach(i longList unless(member(car(i) items) items=cons(car(i) items)))

    foreach(i items min=cons(car(sort(setof(r longList car(r)==i) lambda((a b) greaterp(cadr(b) cadr(a))))) min))

    return(min)) 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • redwire
    redwire over 16 years ago

     Are you a recent winner of the obfuscated code contest? :) Sorry, I couldn't resist. I do C but SKILL is ...well...wow!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • eDave
    eDave over 16 years ago

    While there are prizes for obfuscated code: 

    mapcar(lambda((layer), assoc(layer, sort(copy(myList), lambda((a b) cadr(a) < cadr(b))) )), unique(mapcar('car, myList)))

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • pcbgeorge
    pcbgeorge over 16 years ago
    Don't think of it as C.  That is bound to cause "Wows".  Think of it as Lisp, a language that was originally designed to minimize variables.
    Think of Anton's prog in all it's "functional language" glory, as it's supposed to be written...
    (prog (longList min items) (setq min nil) (setq items nil) (setq longList _your_long_list_of_lists_) (foreach i longList (unless (member (car i) items) (setq items (cons (car i) items)))) (foreach i items (setq min (cons (car (sort (setof r longList (equal (car r) i)) (lambda (a b) (greaterp (cadr b) (cadr a))))) min))) (return min))
    Heck, if you have a development license you can turn any of your code into this using the "compress "statement.  Down with imperative languages and messing around with functional languages so they can "look" imperative <|:)
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • redwire
    redwire over 16 years ago

     Ok....I am wiping the gray matter off the screen.  A big splat just hit. What the HECK does that code do??? :)

    Is it equivalent to the following?  (note: not mine, one entry from "hoyle" who ever you are)

     

    char*O=" <60>!?\\\n"_ doubIe[010]_ int0,int1 _ Iong=0 _ inIine(int eIse){int
    O1O=!O _ l=!O;for(;O1O<010;++O1O)l+=(O1O[doubIe]*pow(eIse,O1O));return l;}int
    main(int booI,char*eIse[){int I=1,x=-*O;if(eIse){for(;I<010+1;I++)I[doubIe-1]
    =booI>I?atof(I[eIse]):!O switch(*O)x++)abs(inIine(x))>Iong&&(Iong=abs(inIine(x
    )));int1=Iong;main(-*O>>1,0);}else{if(booI<*O>>1){int0=int1;int1=int0-2*Iong/0
    [O]switch(5[O]))putchar(x-*O?(int0>=inIine(x)&&do(1,x)do(0,true)do(0,false)
    case(2,1)do(1,true)do(0,false)6[O]case(-3,6)do(0,false)6[O]-3[O]:do(1,false)
    case(5,4)x?booI?0:6[O]:7[O])+*O:8[O]),x++;main(++booI,0);}}}

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
>
Cadence Guidelines

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