Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39311

Re: Writing Java code while drunk and stoned take 2

Path csiph.com!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From nobody@example.org (Scott)
Newsgroups comp.lang.java.programmer
Subject Re: Writing Java code while drunk and stoned take 2
Date Thu, 27 Feb 2020 16:39:40 GMT
Organization XMission http://xmission.com/
Message-ID <5e57edbc.364432453@core> (permalink)
References <1747103f-c38a-411e-92de-a44a52d9c761@googlegroups.com>
Injection-Info news.xmission.com; posting-host="shell.xmission.com:2607:fa18:0:beef::4"; logging-data="30748"; mail-complaints-to="abuse@xmission.com"
X-Newsreader Forte Free Agent 1.21/32.243
Xref csiph.com comp.lang.java.programmer:39311

Show key headers only | View raw


On Thu, 27 Feb 2020 06:00:53 -0800 (PST), chad altenburg
<cdalten@gmail.com> wrote:

>I was drunk and stoned because my girlfriend had just dump me. And I needed=
> something to take my mind off the situation. So I attacked one problem tha=
>t I couldn't solve on coding bat. Here is a link to the problem..
>
>https://codingbat.com/prob/p180759
...
>The problem is that I have two loops. This is because I didn't know how to =
>attack the case when I have to search for a pattern at the *end* of the str=
>ing. If I use str.length(), I go out of bounds. So I ended up using a secon=
>d loop to handle the end of the string case.=20
>
>My gut feeling says this isn't right. But I have no idea how this could be =
>done in one loop.

You're close already. My solution omits the i++ clause from the for
statement - what you do with i during each iteration depends on
whether you found an instance of the pattern at str[i]. If you did,
you advance i by three to consume the pattern; if not, advance by one
to consume the non-matching character at that index. Append to
newString appropriately in either case. After the loop, anything left
in str is too short to match the pattern, so you just append it to
newString.

Two loops. My god, man, what would the neighbors say!?

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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