Author Topic: Sort Problem, Packing Fruit baskets  (Read 2825 times)

0 Members and 1 Guest are viewing this topic.

chlh_jd

  • Guest
Sort Problem, Packing Fruit baskets
« on: January 15, 2011, 11:28:59 PM »
  :angel:
 5 kinds of fruit followed by pears, apples, oranges, peaches, plums.
 The number of each fruit were 10,11,12,13,14;
 Minimum weight were 0.5,0.45,0.4,0.35,0.3 kg;
 Similar fruit weight were increased from the minimum weight at 0.05kg, respectively, such as pears weight (0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95);
 Each fruit were taken into 1 of 5 in the basket, the basket weight of 0;
 Basket order fruit varieties with the above order, asked the weight of Bahrain fruit basket after the former than the latter , such as (0.5 0.4 0.45 0.35 0.3).
 How can fastest get all the programs to pack baskets ?
« Last Edit: January 16, 2011, 08:51:34 AM by CAB »

chlh_jd

  • Guest
Re: Fruit baskets
« Reply #1 on: January 15, 2011, 11:55:36 PM »
Like this :
((0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5) (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45) (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4) (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35) (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35 0.3))
Returns :
((0.3 0.8 0.85 0.9 0.95) (0.3 0.75 0.8 0.9 0.95) (0.3 0.75 0.8 0.85 0.95) (0.3 0.75 0.8 0.85 0.9) (0.3 0.75 0.85 0.9 0.95) (0.3 0.7 0.75 0.9 0.95) (0.3 0.7 0.75 0.85 0.95)...)

I wrote a relatively poor function, you help me ah  :angel:

Code: [Select]
;;;(get-Ndim-IA-lst ret filter)
;;The filiter
(defun filter (a1 a2)
  (< a1 a2)
)
;;Main Fun
(defun get-Ndim-IA-lst (l fi / a b c d e i)
  (if (< (length l) 2)
    l
    (progn
      (setq a nil
   i 1
      )
      (while (setq b (nth i l))
(if (null a)
 (setq a (car l))
)
(setq e nil)
(foreach c b
 (foreach d a
   (if (fi (if (eq (type c) 'list)
 (car c)
 c
)
(if (eq (type d) 'list)
 (car d)
 d
)
)
     (setq e
    (cons
      (if (and (/= (type c) 'list) (= (type d) 'list))
(cons c d)
(if (and (/= (type c) 'list) (/= (type d) 'list))
  (list c d)
  (append c d)
)
      )
      e
    )
     )
   )
 )
)
(setq a e)
(setq i (1+ i))
      )
      a
    )
  )
)
« Last Edit: February 11, 2011, 04:39:42 AM by chlh_jd »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Fruit baskets
« Reply #2 on: January 16, 2011, 08:49:04 AM »
This sounds a bit like a homework problem.   :evil:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Fruit baskets
« Reply #3 on: January 16, 2011, 08:51:33 AM »
This sounds a bit like a homework problem.   :evil:

x2

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Sort Problem, Packing Fruit baskets
« Reply #4 on: January 16, 2011, 10:30:06 AM »
Sounds like a lot of rotten fruit.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sort Problem, Packing Fruit baskets
« Reply #5 on: January 16, 2011, 03:30:56 PM »

I'd like to help but I can't understand the problem ... sorry.


off topic:
what type of apples do you have ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

chlh_jd

  • Guest
Re: Sort Problem, Packing Fruit baskets
« Reply #6 on: January 16, 2011, 11:26:11 PM »
Thanks CAB for changing the title .
Thanks ALL for attention.
I come from China, I'm so  sorry that my English is so poor .
I use it in my programe for Structural optimization of frame column section .

Suppose there are two sections to meet the requirements, they are
Code: [Select]
;;( (1st Floor Sec) (2nd F Sec) (3rd F Sec))
;; ((width hight) ...)
 (setq lst1  '((0.6 0.8)) (0.45 0.75)) (0.45 0.75))
  lst2 '((0.6 0.8) (0.6 0.6) (0.6 0.6)))
;;use the given fun to get  the comb list for mainfun
(defun get-2dim-cvoia-lst
 (l1 l2 off / m1 m2 m lst get-CVOIA-lst)
  (defun get-CVOIA-lst
(val1 val2 off1 val3 val4 off2 / lst1 lst2 lst get-CVO-lst)
    (defun get-CVO-lst (v1 v2 off / lst mid)
      (setq lst (list v1)
   mid v1
      )
      (repeat (fix (/ (- v2 v1) off))
(setq lst (cons (setq mid (+ mid off)) lst))
      )
      (reverse lst)
    )
    (setq lst1 (get-CVO-lst val1 val2 off1)
 lst2 (get-CVO-lst val3 val4 off2)
    )
    (setq lst nil)
    (foreach a lst1
      (foreach b lst2
(setq lst (cons (list a b) lst))
      )
    )
    (reverse lst)
  )
  (setq i 0)
  (repeat (length l1)
    (setq m1 (nth i l1)
 m2 (nth i l2)
    )
    (setq m
  (get-cvoia-lst
    (min (car m1) (car m2))
    (max (car m1) (car m2))
    off
    (min (cadr m1) (cadr m2))
    (max (cadr m1) (cadr m2))
    off
  )
    )
    (setq i   (1+ i)
 lst (append lst (list m))
    )
  )
)
Next, I need to get all combinations which section size between the two Groups and the up floor is less than or equal the down floor .
Like this
Code: [Select]
(setq ret  (get-2dim-cvoia-lst lst1 lst2 0.05))
I use this (get-Ndim-IA-lst ret filiterfun) list to optimize the frame colu sec .
« Last Edit: January 16, 2011, 11:29:12 PM by chlh_jd »

pBe

  • Bull Frog
  • Posts: 402
Re: Sort Problem, Packing Fruit baskets
« Reply #7 on: January 17, 2011, 02:28:46 AM »

I'd like to help but I can't understand the problem ... sorry.

So it wasnt just me  :-)



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sort Problem, Packing Fruit baskets
« Reply #8 on: January 17, 2011, 03:59:33 AM »
My calculations show that
2 pears,  
3 apples,
5 oranges,
2 peaches,
6 plums

placed under the lower left ( south - west corner) column base plate will produce excellent fruit juice.

 :angel:

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

chlh_jd

  • Guest
Re: Sort Problem, Packing Fruit baskets
« Reply #9 on: January 17, 2011, 05:23:24 AM »
I'm so sorry for my poor Einglish . :-(
Pack fruit baskets just metaphor, in fact, It's a Sort and comb problem.
Assuming three baskets were 3 kinds of fruit with ABC, Each volume is n1, n2, n3,
All from the inside out a (Ai, Bj, Ck), requires fruit Weight Ai <= Bj <= Ck;
 find all the possible options .
It can also be see as order-packing problem .

« Last Edit: January 17, 2011, 05:29:14 AM by chlh_jd »

chlh_jd

  • Guest
Re: Sort Problem, Packing Fruit baskets
« Reply #10 on: February 25, 2011, 01:59:10 AM »
Hi All
here's a recursive way , it improve the 'eff so much :
Code: [Select]
(defun ss-getIAlst (l fi / foo f1 f2)
  (defun f1 (c d / ll)
    (foreach x c
      (foreach y d
(if (fi y x)
    (setq ll (cons (list y x) ll))
  )
      )
    )
    ll
  )
  (defun f2 (c d / ll)
    (foreach x c
      (foreach y d
(if (fi y (car x))
    (setq ll (cons (cons y x) ll))
  )
      )
    )
    ll
  )
  (defun foo (a l / b)
    (cond ((and a (null l))
   a
  )
  ((and (null a) (null (cdr l)))
   l
  )
  ((and (null a) (cdr l))
   (setq a (car l)
b (cadr l)
l (cddr l)
   )
   (setq a (f1 a b))
   (if l
     (foo a l)
     a
   )
  )
  (t
   (setq b (car l)
l (cdr l)
   )
   (setq a (f2 a b))
   (if l
     (foo a l)
     a
   )
  )
    )
  )
  (foo nil l)
)
test list
Code: [Select]
(setq l '((0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5)
  (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45)
  (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4)
  (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35)
  (0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35
   0.3)
)
)
test fun
Code: [Select]
(ss-getIAlst l <)

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Sort Problem, Packing Fruit baskets
« Reply #11 on: February 25, 2011, 08:11:20 AM »
If Greg eats a basket of fruit in the woods and Maverick is not around, does anybody care?   :lol:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io