+ 1
Argentina code coach challenge
There is a challenge in sololearn called argentina challenge. I've tried solving it using java and got 4 answers right. This is link to challenge https://www.sololearn.com/coach/23?ref=app I've refered to this question https://www.sololearn.com/Discuss/2146013/argentina/ And HonFu's answer pretty much explains what going on. I used long datatype and got it right but my question is why is Sololearn testing for overflow condition? The problems states reference from price of a hat, is it a good practice to assume it can be worth billions?
15 Respostas
+ 6
Chirag Mehta
Maybe in a real program you would use double.
But large numbers are not so unrealistic.
From google: 22.5 peso = 1 USD
Well, maybe for a hat shop, but if you consider other products (cars, houses ...), that's possible.
+ 5
I used integer in my java solution and had no problems.
+ 5
You have to use long because of *50.
This is my condition:
if(peso * 0.02 < dollar){
That's why I can use integer.
+ 4
Jayakrishna🇮🇳 Right, but for some reason it makes no difference. I tested it. The problem is really int vs. long.
+ 3
Chirag Mehta
Overflow means, that integer can store max value is 2147483647. If your result for dollar*50 exceed this value then you get wrong result. For ex: if value is this max value +5, then you get result is -2,147,483,644(-ve wrong value). Here wrong result is because overflow int range..
So in the problem dollor*50 may exceed integer range..
If you don't understand it clear then see from the link you added, there a mod (@Dennis) explanation clearly tells what is overflow...
"Why checking these in question? " purpose is only your program should work for any range value..
+ 3
Chirag Mehta sry i don't understand your question clearly, but adding this
Overflow is not tested. It happening. And purpose of large inputs (and outputs) is only that your program shloud able to work for any range values with correct values..
(think If hat is gold hat..?)
+ 2
Code coach links are private. We can't see your try from link.. Save in code bits and share link if is not solved fully...
Are you mean, why over flow? Or long also overflowing..?
+ 2
Jayakrishna🇮🇳
I understand what is meant by overflow.
I don't get why overflow is being tested here
+ 1
Broken link
+ 1
It seems to work for me, which one are you not able to use?
+ 1
Denise Roßberg Jayakrishna🇮🇳
I didn't know if the link was private, alternative: challenge could be seen in solutions column of my profile.
I ve written following code and case 5 doesn't work.
https://code.sololearn.com/cU293KAT0yKZ/?ref=app
Here are screenshots
https://drive.google.com/file/d/16ZAXChD7znV3Udke2v9oqWAQEFj6tepM/view?usp=drivesdk
https://drive.google.com/file/d/16VfJzemEDpgVWv6wHmTrIZ-xpyyRFOCL/view?usp=drivesdk
+ 1
Check about description again..
It should > only, instead of >=.
Chirag Mehta
I think java don't produce overflow here..
Otherwise take p/50>d
+ 1
Jayakrishna🇮🇳
I added that later on, its not the problem. I was just checking if equality could solve the problem. It doesn't.
+ 1
Denise Roßberg
My question is why are we testing these large numbers at first place. I mean we are talking about price of a hat.
I'm just a beginner and I want to ask if it is good practice to assume the values could be rather large.
Although it doesn't really change a lot here.
0
Thanks