Pirate Ship II
You're the captain of a pirate ship and would like to calculate the state of the ship. There are two parameters - gold
and pirates
.
If there's less gold than pirates, that's always bad. If there's at least as much gold as pirates, that's good (even though the gold cannot be divided equally). If the gold can be divided by the pirates equally, that's great. However, if gold + pirates > 100, that's always bad since the ship may sink. Return an int
corresponding to the state of the ship, according to the following:
- 0 - Bad
- 1 - Good
- 2 - Great
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
What is the State of the Ship?
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Michael
Sep 8, 9:59 AMplease fix If there's at least as much gold as pirates, that's good. it should if the gold is greater but cannot divided equal to pirates
Dino Šišić
Feb 22, 3:17 PMif someone is having trouble with inconpatible types (boolean/integer) pay attention to:
public static boolean doStuff(int gold, int pirates)
Hope it helps :)
saeed
Mar 30, 7:14 AMI am having big trouble with inconpatible types (boolean/integer);
even when I replace cheet answer...?!!?!
Main.java:7: error: incompatible types
return 0;
^
required: boolean
found: int
Learneroo
Mar 30, 11:45 AM@saeed, the header of your method should say
static int doStuff
, notstatic boolean doStuff
Peter Fekete
Apr 15, 8:38 AM"If there's at least as much gold as pirates, that's good (even though the gold cannot be divided equally)" this would produce 1 at the input 10 10
Islam Elzohary
Dec 22, 5:26 AMmy code
https://www.learneroo.com/modules/20/nodes/146#&togetherjs=FcxFnlbpqR
Islam Elzohary
Dec 22, 5:26 AMmy code
Aadhish
Feb 16, 6:20 AMNouman Khalid
May 6, 1:03 PMreturn (gold100)?0:gold%pirates==0?2:1;
if you want to do it in one line
Hanlise
May 6, 7:24 AMdef function1(gold, pirate):
sum1=gold+pirate
if sum1 < 100: #True
if gold > pirate and not gold % pirate == 0:
return 1
if gold % pirate == 0:
return 2
else:
return 0
else:
return 0
using python
Rajat
Aug 15, 4:55 AMgold = int(input("enter the value"))
pirates = int(input("enter the value"))
sum1 = gold+ pirates
if gold > pirates and not gold % pirates == 0:
return 1
elif gold % pirates == 0: