help me and practice. | Sololearn: Learn to code for FREE!

+1

help me and practice.

You have 25 vouchers for hotel A and 20 vouchers for hotel B. What is the maximal number of vouchers for hotel C that you can use if you are not allowed to spend two consecutive nights in the same hotel (and if you have no other place to sleep)? implement a code for this problem.

3/2/2019 2:07:25 PM

Ahmad Ali

30 Answers

New Answer

+5

I tried different combinations: https://code.sololearn.com/c2SIcSnLW1bG/?ref=app

+6

thank you guys Denise Roßberg David Carroll Diego we all learned something new, this kind of things is very good to sharp your experiences. happy coding ¡¡

+6

Indeed... Engaging with and learning from intelligent people from around the world is one of several reasons I'm a big fan of the SoloLearn community.

+5

you are right so it's 45+1 which is the last c that you can put it alone. a+b+c+1 => c = a+b+1

+4

Sham XR You didn't mentioned that you also need the max number of nights. And I think it is not nessecary to try different solutions. If you know that you are not allowed to sleep two nights in the same hotel, the maximum is to sleep every second time in the same hotel. So sleep every second night in hotel C.

+4

I am also not familiar with the phrase. but voucher is a paid gift, so i pay for your gift and take this voucher (which is a paper proof that I have paid) and i give the voucher to you and you collect your gift. Denise Roßberg David Carroll

+4

David Carroll In germany you can buy a voucher --> for supermarket, amazon or what ever. Then you can give it to a friend as a gift and he can use it to pay without money (because it is already paid). So I think a voucher for a hotel means reservation + the room is paid.

+4

Denise Roßberg Ah... I've learned something new here. The closest thing I can relate this to is a gift certificate. When searching online, I see all search results refer to hotels in the UK or Europe. The usage of the word voucher is less common in the USA. However, I'm not sure why.

+3

So you have to sleep in hotel C how often you can until you have no vouchers for a and b? edit: spend a night in c, next in a --> caca...25 vouchers needed for c no vouchers for a, choose hotel b --> cbcb... --> 20 vouchers needed c = 45 I am not sure if I unterstand this challenge. ;)

+3

Sham XR Please insert your code in the question. You know the rules. Now it looks like a challenge and not a programming related question.

+3

Denise Roßberg You can spend an extra night in C at the end making it 46.

+3

Diego Thx. But I'm not sure if it would be the max.

+3

An easier example: A = 5 B = 6 CACACACACAC --> 5 nights in A, 6 in C --> last night in C, start with B BCBCBCBCBCBC --> 6 nights in B, 6 nights in C 6+6 = 12 So I think you have to check if the given vouchers are odd or even and check where you sleep in the last night.

+3

Sham XR Do you know the answer? Because I'm not sure about my way to solve the problem.

+3

The specific wording in problems like these are extremely important. It seems as though this problem is paraphrased and may even be using some phrasing that isn't translating well. One part that isn't clear is: "(and if you have no other place to sleep)?" Also, what does "maximal number of vouchers for hotel C" mean? I'm not familiar with the usage of voucher in this context.

+3

David Carroll Funny. I had the thought "and what if your translation for youcher is wrong and we are all talking about something different?" ;) I used google translate: voucher = Gutschein but I don't know if voucher has the same meaning of the german Gutschein.

+3

Denise Roßberg I believe Gutschein is the correct translation. However, I'm unfamiliar with associating vouchers with staying in a hotel. Now that I'm thinking about it, the word that makes sense is "reservation" which I believe is "Reservierung."

+3

Let's end this for once and for all. https://www.quora.com/You-have-25-vouchers-for-hotel-A-and-20-vouchers-for-hotel-B-What-is-the-maximal-number-of-vouchers-for-hotel-C-that-you-can-use-if-you-are-not-allowed-to-spend-two-consecutive-nights-in-the-same-hotel-and-if-you-have-no-other-place-to-sleep

+3

Sham XR It is a little bit funny that we start with a coding/math riddle and learned a lot about communication between different people from different countries.

+2

46. Please show us your attempt.