Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39346
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Writing Java code while drunk and stoned take 2 |
| Date | 2020-03-06 17:47 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <r3tur0$1to$1@dont-email.me> (permalink) |
| References | (7 earlier) <e195936c-970c-4025-a62e-f51be779d88b@googlegroups.com> <71d76d2f-f3f1-4f84-b74b-0a871289b509@googlegroups.com> <47e1894f-0349-4d5a-87e0-a6bca3e8aa9b@googlegroups.com> <7dd0aadc-2fdc-4eee-9bfd-fae490d4725b@googlegroups.com> <9e086d27-ba88-42d1-83ae-1ee2b9cfa2bd@googlegroups.com> |
On 2020-03-06 14:49, C.D. Altenburg, Ph.D, wrote:
> public boolean groupSum(int start, int[] nums, int target) {
> // Base case: if there are no numbers left, then there is a
> // solution only if target is 0.
> if (start >= nums.length) return (target == 0);
>
> // Key idea: nums[start] is chosen or it is not.
> // Deal with nums[start], letting recursion
> // deal with all the rest of the array.
>
> // Recursive call trying the case that nums[start] is chosen --
> // subtract it from target in the call.
> if (groupSum(start + 1, nums, target - nums[start])) return true;
>
> // Recursive call trying the case that nums[start] is not chosen.
> if (groupSum(start + 1, nums, target)) return true;
>
> // If neither of the above worked, it's not possible.
> return false;
> }
Pretty.
> Dumbass.
Ugly.
--
DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Writing Java code while drunk and stoned take 2 chad altenburg <cdalten@gmail.com> - 2020-02-27 06:00 -0800
Re: Writing Java code while drunk and stoned take 2 nobody@example.org (Scott) - 2020-02-27 16:39 +0000
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-02-27 09:05 -0800
Re: Writing Java code while drunk and stoned take 2 Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-02-27 19:04 +0100
Re: Writing Java code while drunk and stoned take 2 Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-02-27 19:05 +0100
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-02-27 10:25 -0800
Re: Writing Java code while drunk and stoned take 2 Arne Vajhøj <arne@vajhoej.dk> - 2020-02-27 18:41 -0500
Re: Writing Java code while drunk and stoned take 2 Joerg Meier <joergmmeier@arcor.de> - 2020-03-01 22:50 +0100
Re: Writing Java code while drunk and stoned take 2 Arne Vajhøj <arne@vajhoej.dk> - 2020-03-01 19:53 -0500
Re: Writing Java code while drunk and stoned take 2 chad altenburg <cdalten@gmail.com> - 2020-03-03 04:54 -0800
Re: Writing Java code while drunk and stoned take 2 Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-03-03 14:20 +0100
Re: Writing Java code while drunk and stoned take 2 Joerg Meier <joergmmeier@arcor.de> - 2020-03-03 15:00 +0100
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-03-03 08:19 -0800
Re: Writing Java code while drunk and stoned take 2 chad altenburg <cdalten@gmail.com> - 2020-03-04 05:53 -0800
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-03-04 09:59 -0800
Re: Writing Java code while drunk and stoned take 2 chad altenburg <cdalten@gmail.com> - 2020-03-05 05:53 -0800
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-03-05 09:29 -0800
Re: Writing Java code while drunk and stoned take 2 "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-06 05:49 -0800
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-03-06 07:00 -0800
Re: Writing Java code while drunk and stoned take 2 "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-07 05:40 -0800
Re: Writing Java code while drunk and stoned take 2 Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-03-06 17:47 +0100
Re: Writing Java code while drunk and stoned take 2 "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-07 05:42 -0800
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-03-06 09:03 -0800
Re: Writing Java code while drunk and stoned take 2 chad altenburg <cdalten@gmail.com> - 2020-03-05 07:22 -0800
Re: Writing Java code while drunk and stoned take 2 Eric Douglas <e.d.programmer@gmail.com> - 2020-03-05 07:48 -0800
Re: Writing Java code while drunk and stoned take 2 "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-06 05:50 -0800
Re: Writing Java code while drunk and stoned take 2 "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-06 05:52 -0800
csiph-web