Author Topic: (Challenge) Summation  (Read 14310 times)

0 Members and 1 Guest are viewing this topic.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: (Challenge) Summation
« Reply #30 on: January 17, 2007, 04:29:47 PM »
Quote
Ditto^

What does it mean ???

My English is poor.
Speaking English as a French Frog

LE

  • Guest
Re: (Challenge) Summation
« Reply #31 on: January 17, 2007, 04:32:40 PM »
Quote
Ditto^

What does it mean ???

My English is poor.

I think it is "idem" in French

(means that I think the same as your comment) :)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: (Challenge) Summation
« Reply #32 on: January 17, 2007, 04:34:33 PM »
OK ,Thanks  :-)
Speaking English as a French Frog

LE

  • Guest
Re: (Challenge) Summation
« Reply #33 on: January 18, 2007, 12:53:49 AM »
Note:
I'll start a new topic in the ARX forum, in case some of the masters in arx, end up adding some more solutions...


Just for fun, here is a function in C++/ARX

Here is:

http://www.theswamp.org/index.php?topic=14600.msg176186#msg176186
« Last Edit: January 18, 2007, 10:02:08 PM by LE »

fools

  • Newt
  • Posts: 72
  • China
Re: (Challenge) Summation
« Reply #34 on: March 02, 2007, 03:25:06 AM »
I always use sort+combination like this below codes
Code: [Select]
(DEFUN Sort&Comb (lst func / tmplst)
  (SETQ tmplst nil)
  (FOREACH item (VL-SORT lst
(FUNCTION (LAMBDA (p1 p2) (< (CAR p1) (CAR p2))))
)
    (IF (AND tmplst (EQUAL (CAAR tmplst) (CAR item)))
      (SETQ tmplst (SUBST (LIST (CAR item)
(APPLY func (LIST (CADR item) (CADAR tmplst)))
  )
  (CAR tmplst)
  tmplst
   )
      )
      (SETQ tmplst (CONS item tmplst))
    )
  )
  tmplst
)

Code: [Select]
(setq aaa '(("one" 1) ("two" 2) ("three" 3)
              ("one" 4) ("two" 5) ("three" 6)
              ("one" 7) ("two" 8) ("three" 9)
              )
)

(Sort&Comb aaa '+)
;;return (("two" 15) ("three" 18) ("one" 12))

(Sort&Comb aaa '*)
;;return (("two" 80) ("three" 162) ("one" 28))

(Sort&Comb aaa (FUNCTION (LAMBDA (P1 P2) (IF (ATOM P2) (LIST P1 P2) (CONS P1 P2)))))
;;return (("two" (8 5 2)) ("three" (9 6 3)) ("one" (7 4 1)))
« Last Edit: March 02, 2007, 03:38:42 AM by fools »
Good good study , day day up . Sorry about my Chinglish .

fools

  • Newt
  • Posts: 72
  • China
Re: (Challenge) Summation
« Reply #35 on: March 02, 2007, 03:47:34 AM »
Also can like this
Code: [Select]
(DEFUN Sort&Comb (lst SortFunc CombFunc / tmplst)
  (SETQ tmplst nil)
  (FOREACH item (VL-SORT lst SortFunc)
    (IF (AND tmplst (EQUAL (CAAR tmplst) (CAR item)))
      (SETQ tmplst (SUBST (LIST (CAR item)
(APPLY CombFunc (LIST (CADR item) (CADAR tmplst)))
  )
  (CAR tmplst)
  tmplst
   )
      )
      (SETQ tmplst (CONS item tmplst))
    )
  )
  tmplst
)
Code: [Select]
(SORT&COMB AAA (FUNCTION (LAMBDA (p1 p2) (< (CAR p1) (CAR p2)))) '+)
;;ruturn (("two" 15) ("three" 18) ("one" 12))
Good good study , day day up . Sorry about my Chinglish .