Attack your opponents

If you find a ball on the map, you can throw it at your opponent. Each ball has a coding challenge attached to it. You can only throw the ball if you provide the correct answer to the challenge. If you hit your opponent (target) then you gain 1 point while your opponent loses 1. If your opponent also provide the correct answer to the same challenge, then the ball bounces back and hits you. In order to win, you should try to solve as many challenges as possible. You can develop more advanced strategy such as remembering which opponent has solved which challenge, so that you don't attempt to attack with another ball with the same challenge attached.

Refer to Create your first Python CodeVille Program and Create your first Java CodeVille Program for complete code samples.

In order to complete the challenges, define a new class first:

Python

class Solutions:
    def __init__(self):
        pass

Java

public class Solutions {
}

It's important for this class to be public. To create a new class in IntelliJ, click "File" menu, then "New" => "Java Class".

Then create an object and pass to the game object:

Python

game = CodeVille(Solutions())

Java

CodeVille c = new CodeVille(new Solutions());

To complete each challenge, you need to add a new function to your class. The function name is constructed from the description field, and it has to accept a list of arguments matching the arguments field. In Python, the arguments and return value can be number, string or array of them. In Java, they can be int, double, String or array of them. Here are examples for the above two challenges:

Python

class Solutions:
    def __init__(self):
        pass

    def find_smaller(a, b):
        # return smaller value
        pass

    def find_max(numbers):
        # find the largest in a list
        pass

Java

public class Solutions {
    int findSmaller(int a, int b) {
        // return smaller of a and b
    }

    int findMax(double[] numbers) {
        // return the largest in array
    }
}

The program output will tell you if you are missing any functions.

Warning: method not defined: find_largest(self, list)

Challenges:

Problem Description Python Java
Add even numbers Add only even numbers in a list add_even_numbers addEvenNumbers
Add list Add a list of numbers add_list addList
Add to n Add numbers from 1 to n add_to_n addToN
Add two Add two numbers add_two addTwo
Check if exist Check if a number exists in a list check_if_exist checkIfExist
Divide big by small Given two numbers, divide the big number by small number divide_big_by_small divideBigBySmall
Fibonacci Calculate the first n Fibonacci numbers fibonacci fibonacci
Find larger Find the larger one of two numbers find_larger findLarger
Find max Find maximum number in a list find_max findMax
Find min Find minimum number in a list find_min findMin
Number digits Return all digits of a number. E.g. 945 => [9, 4, 5] number_digits numberDigits
Prime after N Find the first prime number which is larger than N prime_after_n primeAfterN
Is leap year Check if a year is leap year is_leap_year isLeapYear
Reverse number Reverse all digits in a number. e.g. 697 => 796 reverse_number reverseNumber

results matching ""

    No results matching ""