This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* * An array is defined to be complete if the conditions (a), (d) and (e) below hold. | |
* * a. The array contains even numbers | |
* * b. Let min be the smallest even number in the array. | |
* * c. Let max be the largest even number in the array. | |
* * d. min does not equal max | |
* * e. All numbers between min and max are in the array | |
* * | |
* * For example {-5, 6, 2, 3, 2, 4, 5, 11, 8, 7} is complete because |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* * An array is defined to be a Magic array if the sum of the primes in the array is equal to the first | |
* * element of the array. | |
* * | |
* * If there are no primes in the array, the first element must be 0. So {21, 3, 7, 9, 11 4, 6} is a Magic array | |
* * because 3, 7, 11 are the primes in the array and they sum to 21 which is the first element of the array. | |
* * | |
* * {13, 4, 4, 4, 4} is also a Magic array because the sum of the primes is 13 which is also the first element. | |
* * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* * An Evens number is an integer whose digits are all even. For example 2426 is an Evens number | |
* * but 3224 is not. | |
* * | |
* * Write a function named isEvens that returns 1 if its integer argument is an Evens number otherwise it | |
* * returns 0. | |
* * | |
* * The function signature is | |
* * int isEvens (int n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A balanced array is defined to be an array where for every value n in the array, -n also is in the | |
* * array. For example {-2, 3, 2, -3} is a balanced array. So is {-2, 2, 2, 2}. But {-5, 2, -2} is not because 5 | |
* * is not in the array. | |
* * | |
* * Write a function named isBalanced that returns 1 if its array argument is a balanced array. Otherwise | |
* * it returns 0. | |
* * | |
* * If you are programming in Java or C#, the function signature is | |
* * int isBalanced (int [ ] a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A twin prime is a prime number that differs from another prime number by 2. A Fine array is | |
* * defined to be an array in which every prime in the array has its twin in the array. So {4, 7, 9, 6, 5} is a | |
* * Fine array because 7 and 5 occurs. | |
* * | |
* * Note that {4, 9, 6, 33} is a Fine array since there are no primes. | |
* * On the other hand, {3, 8, 15} is not a Fine array since 3 appear in the array but its twin 5 is not in the array. | |
* * | |
* * Write a function named isFineArray that returns 1 if its array argument is a Fine array, otherwise it | |
* * returns 0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Write a function named isDigitSum that returns 1 if sum of all digits of the first argument is less | |
* * than the second argument and 0 otherwise. For example isDigitSum(32121,10 ) would return 1 | |
* * because 3+2+1+2+1 = 9 < 10. | |
* * | |
* * More examples: | |
* * isDigitSum(32121,9) returns 0, isDigitSum(13, 6) returns 1, isDigitSum(3, 3) returns 0 | |
* * | |
* * The function should return -1 if either argument is negative, so isDigitSum(-543, 3) returns -1. | |
* * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A normal number is defined to be one that has no odd factors, except for 1 and possibly itself. | |
* * Write a method named isNormal that returns 1 if its integer argument is normal, otherwise it returns 0. | |
* * | |
* * Examples: 1, 2, 3, 4, 5, 7, 8 are normal numbers. 6 and 9 are not normal numbers since 3 is an odd | |
* * factor. 10 is not a normal number since 5 is an odd factor. | |
* * | |
* * The function signature is | |
* * int isNormal(int n) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * An array is defined to be odd-valent if it meets the following two conditions: | |
* * a. It contains a value that occurs more than once | |
* * b. It contains an odd number | |
* * | |
* * For example {9, 3, 4, 9, 1} is odd-valent because 9 appears more than once and 3 is odd. Other odd-valent | |
* * arrays are {3, 3, 3, 3} and {8, 8, 8, 4, 4, 7, 2} | |
* * | |
* * The following arrays are not odd-valent: | |
* * {1, 2, 3, 4, 5} no value appears more than once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A Daphne array is an array that contains either all odd numbers or all even numbers. For example, | |
* * {2, 4, 2} (only even numbers) and {1, 3, 17, 5} (only odd numbers) are Daphne arrays but {3, 2, 5} is | |
* * not because it contains both odd and even numbers. | |
* * | |
* * Write a function named isDaphne that returns 1 | |
* * if its array argument is a Daphne array. Otherwise it returns 0. | |
* * | |
* * If you are programming in Java, the function prototype is | |
* * int isDaphne (int[ ] a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Write a function named countOnes that returns the number of ones in the binary representation of | |
* * its argument. For example, countOnes(9) returns 2 because the binary representation of 9 is 1001. | |
* * | |
* * Some other examples: | |
* * countOnes(5) returns 2 because binary 101 equals 5 | |
* * countOnes(15) returns 4 because binary 1111 equals 15. | |
* * You may assume that the argument is greater than 0. | |
* * | |
* * The function prototype is |