Skip to content

Instantly share code, notes, and snippets.

@youssef3wi
Created August 28, 2025 19:03
Show Gist options
  • Select an option

  • Save youssef3wi/d266d2178313e8deb52c29b46bced589 to your computer and use it in GitHub Desktop.

Select an option

Save youssef3wi/d266d2178313e8deb52c29b46bced589 to your computer and use it in GitHub Desktop.
Spell
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* In the echanted land of Evenaria,
* an elf named Codelia was searching for the mystical Even Stones, which maintained balance and harmony.
* One day, she discovered an ancient scroll with a list of numbers representing their locations.
* However, the scroll was damaged and the numbers looked scrambled.
* <p>
* Codelia sought the wise counsel of an old owl,
* who advised her to reserve the list and keep only even numbers to unveil the original sequence of the stones.
* Now, it's up to you to help Codelia decipher the ancient scroll by writing a spell that performs this operation.
*/
public class Spell {
/**
* @param numbers A list of integers
* @return The reversed list with only even numbers
*/
public static List<Integer> spell(List<Integer> numbers) {
List<Integer> results = new ArrayList<>();
for (int idx = numbers.size() - 1; idx >= 0; idx--) {
int current = numbers.get(idx);
if (current % 2 == 0) {
results.add(current);
}
}
return results;
}
public static void main(String[] args) {
int[] values = new int[]{4, 2, 28, 19, 44, 32, 18, 26, 2, 13};
System.out.println("Using example: " + spell(Arrays.stream(values).collect(ArrayList::new, ArrayList::add, ArrayList::addAll)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment