Pirate Ship I
You're the captain of a pirate ship and would like to calculate whether your trip was a success. You are given two parameters - gold
and pirates
.
The trip is a success iff there is at least as much gold as pirates. However, if gold + pirates > 100, then the trip is a failure, since the ship may sink. Return true
if the ship was a success and false
if it was a failure.
Input Note:
Boilerplate code is provided for Java. To solve this in another language, you just need to read in a list of number pairs from the standard input, where the first number is gold
and the second number is pirates
.
Challenge
For each test case, you will be given two numbers as input: gold and pirates. Return whether the trip success was true
or false
.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
David
Mar 2, 12:31 PMLOL had to go back to Booleans chapter.... people Booleans is different from booleans, careful when defining your boolean.
Jig
Jun 12, 2:05 PMI tries using only booleans but didn't work for all conditions, the following worked for me.
if (gold>=pirates &&gold+pirates <100){
return true;
}
else{
return false;
}
}
thales
Jul 15, 9:33 AMI had the following it worked.
my code
Suditu George
Jul 18, 6:58 AMmy code
L
Nov 22, 3:58 AMMy solution
return(!(gold+pirates > 100) && gold >= pirates);
Aadhish
Feb 16, 6:15 AMOnly this works.
Nouman Khalid
May 6, 12:54 PMreturn gold+pirates>100?false:gold>=pirates?true:false;
works for me
Hanlise
May 14, 10:35 AMdef function1(gold, pirates):
sum1=gold+pirates
if gold >= pirates and sum1 < 100:
return True
else:
return False
I use python
Roger
Aug 15, 11:21 AMfunction pirateShip(gold, pirates) {
let x = gold + pirates
if (x > 100) {
return 'ship sank'
} else if (gold >= pirates) {
return 'success'
} else {
return 'failed'
}
}
using js