#How do I do this?

21 messages · Page 1 of 1 (latest)

violet iris
#

It’s been 4 weeks of coding with C and I can’t even do this , hopefully someone can do it and explain it to me.

nimble falconBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#

@violet iris

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

plucky rune
#

!hw

nimble falconBOT
# plucky rune !hw
sbdswr /good orc is dead orc/
We Don't Do Your Homework

Welcome to Together C & C++ :wave:

We won't do your homework for you (#rules) but we are happy to help you learn and point you in the right direction.

Please send what you have so far and ask a specific question.

plucky rune
#

and photos of the screen are the most useless thing ever

violet iris
#

It’s not even a homework

#

There’s a club I joined today and they had a mini hackathon thing

#

And I didn’t know how to do this

#

The closest thing to this is howmeowrk

plucky rune
#

I mean this task is more on the math edge than programming per se, although such math tasks are popular in programming contests

#

if my mind serves me you need to have w = 2m + 2n where both m and n are natural, so w = 2(m + n), thus w itself has to be even, and additionally at least 4

#

because m and n need to be positive naturals, otherwise one of the children wouldn't get anything

violet iris
#

So like the only numbers that would work are 4 and 8 and 12 etc…

loud niche
torpid belfry
loud niche
# plucky rune if my mind serves me you need to have `w = 2m + 2n` where both m and n are natur...

if my mind serves me you need to have w = 2m + 2n where both m and n are natural
This doesn't make sense. You magically summon an identical second piece of watermelon slice for both the slices, so the result would be 2w = 2m + 2n => w = m + n which makes sense because the watermelon with weight w gets divided into two parts weighing m and n kilos.

Also interesting for @violet iris:
The solution really is very simple.
You need to realize that odd numbers won't work, so you can rule all of these out.
Then you look at the even numbers by just checking them one by one; you realize that for w = 2 you can't divide the watermelon into m and n with w = m + n and m, n > 0, so you know that for w = 2 it must be false.
You then look at w = 4 and realize that you can divide that into n = 2 = m.
You then look at w = 6 and see that n = 2, m = 4 works.
w = 8 => for example n = 2, m = 6.
w = 10 => for example n = 2, m = 8.
You realize that for every even number greater than 2 you can split that into n = 2 and m = w - n and since both w and n are even numbers (cause if w was odd we know it's false and we know n = 2) and the subtraction of two even numbers gives us an even number (which is also guaranteed to be positive in this case since we know that w > n).
To summarize it, we can really condense this into a nice little oneliner:

return (w > 2) * !(w & 1);

@plucky rune Aaaaand I just realized that you were saying exactly that and I just intially misread. Anyways, it's still a somewhat more in-depth explanation for OP so I figured it's useful

plucky rune
#

yes, indeed, that's exactly what I explained with simple math

#

¯_(ツ)_/¯

#

on the other hand "You need to realize that odd numbers won't work, so you can rule all of these out." isn't really explaining :P

#

there's also one smell here - !(w & 1) - compiler knows better how to optimize, you should write exactly what you have in mind instead of being too smart :P