Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37393
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2017-09-12 08:02 -0700 |
| References | (1 earlier) <284544a2-9e8a-4150-a048-c8eb30ddda6a@googlegroups.com> <e326c7af-2371-471d-894d-b4f4ccbbba67@googlegroups.com> <op4tp1$ai6$1@dont-email.me> <uhkerch59h8c5o3p5vqvl90r4vrlp1llt0@4ax.com> <8eef657b-eb9f-4a6e-88f7-6c2e0ed2303b@googlegroups.com> |
| Message-ID | <4e027f07-9b5b-4854-9b74-3611c90f2e09@googlegroups.com> (permalink) |
| Subject | Re: Is there already an easy fit algorithm? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Tuesday, September 12, 2017 at 10:32:39 AM UTC-4, Eric Douglas wrote:
> public boolean fitsOnTruck(final float truckCubes, final int pick) {
> if (pick == arr.length) {
> return false;
> }
> if (arr[pick] > truckCubes) {
if (pick == 0) { throw new Error("Item " + arr[pick] + " too big for container"); }
> return fitsOnTruck(truckCubes, pick + 1);
> } else if (arr[pick] < truckCubes) {
> if (fitsOnTruck(truckCubes - arr[pick], pick + 1) || pick == arr.length - 1) {
> retArr.add(arr[pick]);
> return true;
> } else {
> return fitsOnTruck(truckCubes, pick + 1);
> }
> } else {
> retArr.add(arr[pick]);
> return true;
> }
> }
>
Technically it should check for the error condition, though normally I'd think if you're checking any items that don't fit in your container alone you've got issues.
Of course at some point it also needs to do the loop to show totals for multiple containers.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-08 05:05 -0700
Is there already an easy fit algorithm? lewbloch@gmail.com - 2017-09-08 07:38 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-08 08:34 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-08 11:36 -0700
Re: Is there already an easy fit algorithm? Joshua Cranmer đ§ <Pidgeot18@verizon.invalid> - 2017-09-10 22:52 -0400
Re: Is there already an easy fit algorithm? Gene Wirchenko <genew@telus.net> - 2017-09-11 20:24 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-12 05:05 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-12 05:11 -0700
Re: Is there already an easy fit algorithm? lewbloch@gmail.com - 2017-09-12 10:31 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-12 10:52 -0700
Re: Is there already an easy fit algorithm? lewbloch@gmail.com - 2017-09-12 12:43 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-12 13:02 -0700
Re: Is there already an easy fit algorithm? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-09-12 17:08 -0400
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-13 05:21 -0700
Re: Is there already an easy fit algorithm? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-09-13 12:49 -0400
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-13 11:13 -0700
Re: Is there already an easy fit algorithm? lewbloch@gmail.com - 2017-09-13 14:24 -0700
Re: Is there already an easy fit algorithm? Arne VajhĂžj <arne@vajhoej.dk> - 2017-09-13 20:35 -0400
Re: Is there already an easy fit algorithm? lewbloch@gmail.com - 2017-09-14 11:26 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-14 11:53 -0700
Re: Is there already an easy fit algorithm? Martin Gregorie <martin@address-in-sig.invalid> - 2017-09-14 19:49 +0000
Re: Is there already an easy fit algorithm? lewbloch@gmail.com - 2017-09-14 14:38 -0700
Re: Is there already an easy fit algorithm? Arne VajhĂžj <arne@vajhoej.dk> - 2017-09-14 20:34 -0400
Re: Is there already an easy fit algorithm? Andreas Leitgeb <avl@logic.at> - 2017-09-15 09:22 +0000
Re: Is there already an easy fit algorithm? Arne VajhĂžj <arne@vajhoej.dk> - 2017-09-15 20:03 -0400
Re: Is there already an easy fit algorithm? Gene Wirchenko <genew@telus.net> - 2017-09-19 21:16 -0700
Re: Is there already an easy fit algorithm? Arne VajhĂžj <arne@vajhoej.dk> - 2017-09-20 08:58 -0400
Re: Is there already an easy fit algorithm? leif.roar@dimnakorr.com - 2017-09-18 04:14 -0500
Re: Is there already an easy fit algorithm? Martin Gregorie <martin@address-in-sig.invalid> - 2017-09-12 21:50 +0000
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-13 05:12 -0700
Re: Is there already an easy fit algorithm? Martin Gregorie <martin@address-in-sig.invalid> - 2017-09-13 13:07 +0000
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-13 06:33 -0700
Re: Is there already an easy fit algorithm? Martin Gregorie <martin@address-in-sig.invalid> - 2017-09-13 16:37 +0000
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-13 10:36 -0700
Re: Is there already an easy fit algorithm? Martin Gregorie <martin@address-in-sig.invalid> - 2017-09-13 18:54 +0000
Re: Is there already an easy fit algorithm? Gene Wirchenko <genew@telus.net> - 2017-09-19 21:21 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-12 07:32 -0700
Re: Is there already an easy fit algorithm? Eric Douglas <e.d.programmer@gmail.com> - 2017-09-12 08:02 -0700
Re: Is there already an easy fit algorithm? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-09-12 11:47 -0400
Re: Is there already an easy fit algorithm? Martin Gregorie <martin@address-in-sig.invalid> - 2017-09-15 10:27 +0000
csiph-web