Java 8, 183 bytes
Golfed:
s->java.util.Arrays.stream(new String[]{"pewar","wapeace","slfreedom","frslavery","stignorance","igstrength"}).filter(t->t.startsWith(s.substring(0,2))).findFirst().get().substring(2)
Ungolfed with test program:
public class WarIsPeaceFreedomIsSlaveryIgnoranceIsStrength {
public static void main(String[] args) {
for (String str : new String[] { "war", "peace", "freedom", "slavery", "ignorance", "strength" }) {
System.out.print(str);
System.out.print(" = ");
System.out.println(f(s -> java.util.Arrays.stream(
new String[] { "pewar", "wapeace", "slfreedom", "frslavery", "stignorance", "igstrength" }).filter(
t -> t.startsWith(s.substring(0, 2))).findFirst().get().substring(2),
str));
}
}
private static String f(java.util.function.Function<String, String> function, String input) {
return function.apply(input);
}
}
This function is nested lambdas with streams. It takes an array of strings where the first two characters of the string acts as a map key, matching the input, while the remainder of each string is the map value, the output. It finds the string matching the given input and returns the string that matches it.
Program output:
war = peace
peace = war
freedom = slavery
slavery = freedom
ignorance = strength
strength = ignorance
10Related :-) – xnor – 2017-01-24T22:04:32.973
1Do input and output have to be in the same case? – Dennis – 2017-01-25T02:21:58.207
2@Dennis Yes. Either everything is lowercase, or everything is uppercase. – Calvin's Hobbies – 2017-01-25T02:26:59.537
1Hm, that kinda kills the approach I had in mind... Anyway, thanks for clarifying. – Dennis – 2017-01-25T02:33:48.657
3Don't know if anyone can use this to compress their strings more (it didn't improve my score in Pip), but the initial letters of these words (
w p f s i
) are not found anywhere else in any of the words. An intriguing property. – DLosc – 2017-01-25T08:51:11.4901Why oh why does this remind me of the line from the Mechwarrior game series: "War is life, death is the only true peace"? Will give this a go if I can get a break from working on an OpenBSD firewall for my internship. – NZKshatriya – 2017-01-25T17:14:23.017
13This is a doubleplusgood challenge – Jojodmo – 2017-01-26T06:28:45.637
3Almost nobody likes this book. It's full of lies! Sad. – Peter - Reinstate Monica – 2017-01-26T10:38:35.700
1Aldous Huxley would disgree. – Magic Octopus Urn – 2017-01-26T15:08:47.417
1would
@PEACE
be a valid output? – 12Me21 – 2017-01-28T20:07:25.1401@12Me21 No it wouldn't – Calvin's Hobbies – 2017-01-28T20:45:52.180