Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
+ 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.

2nd Mar 2019, 2:07 PM
30 Réponses
+ 5
I tried different combinations: https://code.sololearn.com/c2SIcSnLW1bG/?ref=app
2nd Mar 2019, 4:48 PM
Denise Roßberg
+ 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 ¡¡
2nd Mar 2019, 6:06 PM
+ 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.
3rd Mar 2019, 12:05 AM
David Carroll
+ 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
2nd Mar 2019, 4:40 PM
+ 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.
2nd Mar 2019, 3:52 PM
Denise Roßberg
+ 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
2nd Mar 2019, 4:37 PM
+ 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.
2nd Mar 2019, 4:57 PM
Denise Roßberg
+ 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.
2nd Mar 2019, 6:01 PM
David Carroll
+ 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. ;)
2nd Mar 2019, 2:45 PM
Denise Roßberg
+ 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.
2nd Mar 2019, 2:52 PM
Denise Roßberg
+ 3
Denise Roßberg You can spend an extra night in C at the end making it 46.
2nd Mar 2019, 2:54 PM
Diego
+ 3
Diego Thx. But I'm not sure if it would be the max.
2nd Mar 2019, 2:56 PM
Denise Roßberg
+ 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.
2nd Mar 2019, 3:31 PM
Denise Roßberg
+ 3
Sham XR Do you know the answer? Because I'm not sure about my way to solve the problem.
2nd Mar 2019, 3:33 PM
Denise Roßberg
+ 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.
2nd Mar 2019, 4:05 PM
David Carroll
+ 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.
2nd Mar 2019, 4:12 PM
Denise Roßberg
+ 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."
2nd Mar 2019, 4:23 PM
David Carroll
2nd Mar 2019, 4:34 PM
Diego
+ 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.
2nd Mar 2019, 6:51 PM
Denise Roßberg
+ 2