def feed_the_primates(animals: list, food: list) -> list: if "🍌" not in food: return 'No bananas!' return list(map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] else None, animals))) # Solution 1: Slow #if "🍌" not in food: return 'No bananas!' #return [f"🍌{m}" for m in animals if m in ["🐒", "🦍"]]
- def feed_the_primates(animals: list, food: list) -> list:
- if "🍌" not in food: return 'No bananas!'
return list(map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] and "🍌" in food else None, animals)))- return list(map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] else None, animals)))
- # Solution 1: Slow
- #if "🍌" not in food: return 'No bananas!'
#return [f"🍌" for m in animals if m in ["🐒", "🦍"] and "🍌" in food]- #return [f"🍌{m}" for m in animals if m in ["🐒", "🦍"]]
Finding max element with Google Guava
import static com.google.common.primitives.Ints.max; public class Kata { public static int findMax(int[] my_array) { // Write a method that returns the largest integer in the list. // You can assume that the list has at least one element. return max(my_array); } }
import java.util.*;- import static com.google.common.primitives.Ints.max;
- public class Kata {
- public static int findMax(int[] my_array) {
- // Write a method that returns the largest integer in the list.
- // You can assume that the list has at least one element.
Arrays.sort(my_array);return (my_array[my_array.length-1]);- return max(my_array);
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Write more tests to prove your code bleow class SolutionTest { @Test void testSomething() { assertEquals(Kata.findMax(new int[]{4, 5, 6, 7}), 7); assertEquals(Kata.findMax(new int[]{598, 124, 0, -675}), 598); assertEquals(Kata.findMax(new int[]{-53, -245, 1, 9, -3}), 9); assertEquals(Kata.findMax(new int[]{-100, -99, -102, -101}), -99); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Write more tests to prove your code bleow
- class SolutionTest {
- @Test
- void testSomething() {
- assertEquals(Kata.findMax(new int[]{4, 5, 6, 7}), 7);
- assertEquals(Kata.findMax(new int[]{598, 124, 0, -675}), 598);
- assertEquals(Kata.findMax(new int[]{-53, -245, 1, 9, -3}), 9);
- assertEquals(Kata.findMax(new int[]{-100, -99, -102, -101}), -99);
- }
- }
public class Kata { public static int speedLimit(int speed, int[] signals) { int penalty = 0; for (int signal : signals){ if (speed > signal){ if (speed - signal >= 30){ penalty += 500; } else if (speed - signal >= 20){ penalty += 250; } else if (speed - signal >= 10){ penalty += 100; } } } return penalty; } }
- public class Kata {
- public static int speedLimit(int speed, int[] signals) {
- int penalty = 0;
for (int i = 0; i < signals.length; i++){if (speed > signals[i]){if (speed - signals[i] >= 30){- for (int signal : signals){
- if (speed > signal){
- if (speed - signal >= 30){
- penalty += 500;
} else if (speed - signals[i] >= 20 && speed - signals[i] < 30){- } else if (speed - signal >= 20){
- penalty += 250;
} else if (speed - signals[i] >= 10 && speed - signals[i] < 20){- } else if (speed - signal >= 10){
- penalty += 100;
- }
- }
- }
- return penalty;
- }
- }