### Author Topic: Important life algorithms  (Read 17982 times)

0 Members and 1 Guest are viewing this topic.

#### lkj

• LV6 Super Member (Next: 500)
• Posts: 485
• Rating: +58/-1
##### Re: Important life algorithms
« Reply #30 on: December 24, 2014, 06:56:34 pm »
Code: [Select]
while(oreo)    oreo--;
Looking though this again, you could optimize:
Code: [Select]
while(oreo--);
I think the compiler does that for you.

In both cases the outcome is:
while:
branch if oreo is zero: endwhile
oreo --
branch to while
endwhile:

If we're talking about C/C++, I'm pretty sure they aren't equivalent: the first version only decrements oreo to 0, the second one to -1.

#### harold

• LV5 Advanced (Next: 300)
• Posts: 226
• Rating: +41/-3
##### Re: Important life algorithms
« Reply #31 on: December 24, 2014, 07:20:13 pm »
Most other languages too, but you can fix it:
Code: [Select]
while(--oreo);'
You're in trouble if you start with zero though.
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

#### bb010g

• LV6 Super Member (Next: 500)
• Posts: 428
• Rating: +22/-1
• I do stuff
##### Re: Important life algorithms
« Reply #32 on: December 29, 2014, 01:09:12 am »
Most other languages too, but you can fix it:
Code: [Select]
while(--oreo);'
You're in trouble if you start with zero though.
Derp. Thanks for the fix.
Arch Linux user
Haskell newbie | Warming up to Lua | Being dragged into C++
Calculators: HP 50g, HP 35s, Casio Prizm, TI-Nspire CX CAS, HP 28s, HP Prime, Mathematica 9 (if that counts)
π: 3.14...; l: 108; i: 105; e: 101; l+i+e: 314
THE CAKE IS A LIE IS A PIE

#### c4ooo

• LV5 Advanced (Next: 300)
• Posts: 252
• Rating: +10/-1
• The impossible chemical compound.
##### Re: Important life algorithms
« Reply #33 on: July 26, 2015, 10:37:22 pm »
Today I learnt something : life is made of algorithms. I discovered one today, being a student in my own appartment :

Code: [Select]
while(oreo)    oreo--;
Did you discover things like this ?
Sorry for necro posting, but i felt like this needed a OOP update and a small reality check:
Code: [Select]
package Matrix.AIs.Matrefeytontias;public class Matrefeytontias {    private OreoBox oreoBox;    public static OreoStore oreoStore;    public static void main(String... args) {        oreoStore = new OreoStore();        Matrefeytontias matrefeytontias = new Matrefeytontias();        matrefeytontias.live();    }    private void live() {        while (oreoStore.hasOreos()) {            buyOreos();            while (oreoBox.hasOreos()) {                oreoBox.eatOreos();            }        }        //die    }    private void buyOreos() {        oreoBox = oreoStore.buyBox();    }    static class OreoStore {        int boxes;        OreoStore() {            boxes = 100;        }        OreoBox buyBox() {            boxes--;            return new OreoBox();        }        boolean hasOreos() {            return boxes != 0;        }    }    static class OreoBox {        int numberOfOreos;        OreoBox() {            numberOfOreos = 50; //Correct me here please        }        void eatOreos() {            numberOfOreos--;        }        boolean hasOreos() {            return numberOfOreos != 0;        }    }}
« Last Edit: July 26, 2015, 11:04:02 pm by c4ooo »
-German Kuznetsov
The impossible chemical compound.

#### Eeems

• Mr. Dictator
• LV13 Extreme Addict (Next: 9001)
• Posts: 6234
• Rating: +318/-36
• little oof
##### Re: Important life algorithms
« Reply #34 on: July 27, 2015, 05:20:07 pm »
Hmm, seems like too much work to just eat Oreos.
/e

#### c4ooo

• LV5 Advanced (Next: 300)
• Posts: 252
• Rating: +10/-1
• The impossible chemical compound.
##### Re: Important life algorithms
« Reply #35 on: July 28, 2015, 01:34:15 am »
Hmm, seems like too much work to just eat Oreos.
That was sort of the point, to laugh at OOP
Also I am somewhat jealous that @Matrefeytontias has an Oreo store inside of him.
However I am a little freaked out that he has an Oreo box inside of him.
-German Kuznetsov
The impossible chemical compound.

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: Important life algorithms
« Reply #36 on: July 28, 2015, 03:10:46 am »
Don't stick inadequate things in me please.

What ? Did I say something wrong ?