| Bytes | Lang | Time | Link |
|---|---|---|---|
| 080 | Raku Perl 6 rakudo | 250425T170212Z | xrs |
| 096 | Tcl | 170128T133318Z | sergiol |
| 031 | Vyxal | 221013T115839Z | DialFros |
| 023 | SOGL | 170129T124822Z | dzaima |
| 073 | Factor + qw | 220528T222050Z | chunes |
| 079 | AWK | 210517T000120Z | cnamejj |
| 104 | /// | 210516T123039Z | nph |
| 095 | Subleq 8bit words | 210516T183134Z | Axuary |
| 029 | 05AB1E | 190912T154354Z | Grimmy |
| 111 | ink | 190329T204839Z | Sara J |
| 098 | Clojure | 190118T060443Z | Closed Y |
| nan | Stax | 180224T064247Z | Weijun Z |
| 061 | q/kdb+ | 171027T152508Z | mkst |
| 061 | J | 171028T161827Z | FrownyFr |
| 070 | Ruby | 171027T193709Z | earksiin |
| 132 | C | 170127T174851Z | Ahemone |
| 037 | Japt | 170904T160219Z | Shaggy |
| 124 | Cbcc 32 bit int | 170502T220241Z | user5898 |
| 155 | Axiom | 170502T185407Z | user5898 |
| 106 | /// | 170430T230404Z | sporkl |
| 204 | Python3 | 170430T211238Z | Discrete |
| 054 | Pyth | 170125T160348Z | Erik the |
| 096 | 8th | 170129T165118Z | Chaos Ma |
| 080 | Python | 170128T174014Z | FlipTack |
| 078 | JavaScript | 170129T162659Z | FlipTack |
| 092 | SmileBASIC | 170128T201747Z | 12Me21 |
| 082 | QBIC | 170128T172958Z | steenber |
| 099 | Qbasic | 170128T163748Z | steenber |
| 183 | Java 8 | 170125T191152Z | user1893 |
| 078 | ><> Fish | 170126T212922Z | Nick Mat |
| 093 | C | 170125T134522Z | edc65 |
| 066 | Dyalog APL | 170125T013556Z | Adá |
| 080 | JavaScript | 170125T212308Z | apsiller |
| 029 | Pyke | 170125T175433Z | Blue |
| 123 | SpecBAS | 170125T155348Z | Brian |
| 088 | Befunge | 170125T034442Z | James Ho |
| 077 | TIBasic | 170124T222945Z | Timtech |
| 104 | Haskell | 170125T101929Z | user3389 |
| 078 | Bash | 170125T093451Z | Mitchell |
| 071 | JavaScript ES6 | 170125T083921Z | edc65 |
| 055 | Pip | 170125T092803Z | DLosc |
| 211 | C | 170125T092815Z | Abel Tom |
| 108 | C gcc | 170125T050549Z | Dennis |
| 107 | C gcc | 170125T033830Z | Dennis |
| 070 | PHP | 170125T074510Z | user6395 |
| 056 | Actually | 170125T050422Z | user4594 |
| 052 | CJam | 170125T021728Z | aditsu q |
| 035 | Jolf | 170125T031742Z | Conor O& |
| 070 | Stacked | 170125T025455Z | Conor O& |
| 024 | Jelly | 170125T021640Z | Dennis |
| 061 | Perl 6 | 170125T021011Z | smls |
| 080 | JavaScript ES6 | 170124T224842Z | Arnauld |
| 098 | Clojure | 170125T001848Z | Carcigen |
| 086 | Pari/GP | 170124T235802Z | Gottfrie |
| 063 | Perl | 170124T233215Z | Dada |
| 081 | Python | 170124T220343Z | xnor |
| 086 | R | 170124T222525Z | MickyT |
| 060 | Vim | 170124T223154Z | DJMcMayh |
| 030 | 05AB1E | 170124T223014Z | Emigna |
| 084 | Mathematica | 170124T223726Z | Martin E |
Raku (Perl 6) (rakudo), 80 bytes
{my%m=(my@a=<war freedom ignorance strength slavery peace>)Z=>@a.reverse;%m{$_}}
Tcl, 96 bytes
puts [lindex [set L {war peace freedom slavery ignorance strength}] [expr [lsearch $L $argv]^1]]
SOGL, 23 bytes
7"ņVυr11<╝⅔`▒τ¶‘@Θ,Wh-w
Explanation:
7 push 7
"ņVυr11<╝⅔`▒τ¶‘ push "ignorance strength war peace freedom slavery"
@Θ split on spaces
,W get the index of input in the array (e.g. war)
stack: [7, [ignorance,strength,war,peace,freedom slaver], 3]
h swap the 7 and array
stack: [[ignorance,strength,war,peace,freedom slaver], 7, 3]
- subtract
stack: [[ignorance,strength,war,peace,freedom slaver], 4]
w get the nth item from the array (e.g. peace)
I didn't have a split on function. Dunno how that happened.
Would be 22 bytes with a split on space command but this is a more realistic score.
Factor + qw, 73 bytes
[ qw{ war freedom ignorance strength slavery peace } dup reverse zip at ]
How?
! "freedom"
qw{ war freedom ignorance strength slavery peace } ! "freedom" { "war" "freedom" "ignorance" "strength" "slavery" "peace" }
dup ! "freedom" { "war" "freedom" "ignorance" "strength" "slavery" "peace" } { "war" "freedom" "ignorance" "strength" "slavery" "peace" }
reverse ! "freedom" { "war" "freedom" "ignorance" "strength" "slavery" "peace" } { "peace" "slavery" "strength" "ignorance" "freedom" "war" }
zip ! "freedom" {
{ "war" "peace" }
{ "freedom" "slavery" }
{ "ignorance" "strength" }
{ "strength" "ignorance" }
{ "slavery" "freedom" }
{ "peace" "war" }
}
at ! "slavery"
AWK, 79 bytes
$0=/w/?"peace":/f/?"slavery":/p/?"war":/v/?"freedom":/t/?"ignorance":"strength"
This is a straightforward nested ternary using string searches for a character unique to each input string. The else and the end assigned the value which is associated with ignorance, so the code assumes only value input strings will be used.
It's essentially equivalent to this code...
if(index($0,"w") $0 = "peace"
else if(index($0,"f") $0 = "slavery"
..etc..
else $0 = "strength"
The value of the ternary becomes the value of $0, which is always truthy, to the code prints that value.
///, 107 bytes 105 104 bytes
/peace/wa*//slavery/f*eedom//strength/igno*ance//war/p\eace//freedom/s\lavery//ignorance/s\trength//*/r/
Subleq (8-bit words), 95 bytes
-1 100 -1
-1 101 -1
30 101 18
36 18 -1
0 6 -1
12 12 6
37 12 -1
12 -1 24
0 18 -1
12 12 18
97 4 2 5 6 2 -10
-112 -101 -97 -99 -101 0 0 0 0 0
-119 -97 -114 0 0 0 0 0 0 0
-115 -116 -114 -101 -110 -103 -116 -104 0 0
-102 -114 -101 -101 -100 -111 -109 0 0 0
-115 -108 -97 -118 -101 -114 -121 0 0 0
-105 -103 -110 -111 -114 -97 -110 -99 -101
Explanation
-1 100 -1 ' 0: Input first letter to 100:
-1 101 -1 ' 3: Input second letter to 101:
30 101 18 ' 6: if 101: <= "a" (later loops "e","g","l","r","t") goto 18:
36 18 -1 ' 9: 18: = 18: + 10 (move to next word)
0 6 -1 '12: 6: = 6: + 1 (move to next second letter comparison)
12 12 6 '15: 12: = 0 goto 6:
37 12 -1 '18: put -37: into 12 (this address is incremented in the code) if 12: <= 0 exit
12 -1 24 '21: output 12:
0 18 -1 '24: 18: = 18: + 1
12 12 18 '27: 12: = 0 goto 18
97 4 2 5 6 2 -10 '30: to 36: data for loop starting at 6:
-112 -101 -97 -99 -101 0 0 0 0 0 '37:-"peace"
-119 -97 -114 0 0 0 0 0 0 0 '47:-'war"
-115 -116 -114 -101 -110 -103 -116 -104 0 0 '57:-"strength"
-102 -114 -101 -101 -100 -111 -109 0 0 0 '67:-"freedom"
-115 -108 -97 -118 -101 -114 -121 0 0 0 '77:-"slavery"
-105 -103 -110 -111 -114 -97 -110 -99 -101 '87:-"ignorance"
ink, 111 bytes
=n(w)
LIST d=war,freedom,ignorance,peace,slavery,strength
~d=d(1)
-(i){"{d}"==w:{d+3:{d+3}|{d-3}}->->}
~d++
->i
Called as ->n("war")->.
If taking one of the list values rather than a string as input is acceptable (I feel like it probably shouldn't be), there's a 79-byte solution:
=n(w)
LIST D=war,freedom,ignorance,peace,slavery,strength
{w+3:{w+3}|{w-3}}->->
Clojure, 98 (?) bytes
(def m '("war""peace""freedom""slavery""ignorance""strength"))(apply hash-map(concat(reverse m)m))
The second expression is a hash-map which can be called as though it were a function to obtain the desired result, but I'm not sure this exact line of code counts when you have to go in there and add a parenthesis in the middle to actually use it. Anyhow this manages to be marginally shorter than just writing the whole map out manually by taking advantage of how hash-map reads items in a sequence as alternately keys and values by reversing the sequence and concatenating it to itself to provide both forward and backward mappings.
Stax, 31 bytesCP437
é≡[pZÉz>╨=üX«Θv¥5║6◙%▌ëQù&ü╢╟FP
37 bytes when unpacked,
`j<r:8GGme*6k{"TQH>C;q)Jc4%&`jc,]INv@
Explanation
`j<r:8GGme*6k{"TQH>C;q)Jc4%&` Compressed string literal for
war freedom ignorance strength slavery peace
j Split on spaces
c,]I Find index of input
Nv Negate it and minus one
@ Get the element at index
Implicit output
q/kdb+, 65 61 bytes
Solution:
{(x,y)!y,x}[`war`freedom`ignorance;`peace`slavery`strength]`$
Examples:
q){(x,y)!y,x}[`war`freedom`ignorance;`peace`slavery`strength]`$"war"
`peace
q){(x,y)!y,x}[`war`freedom`ignorance;`peace`slavery`strength]`$"slavery"
`freedom
Explanation:
Built a dictionary of keys->values, lookup user input in the merged dictionary:
{(x,y)!y,x}[`war`freedom`ignorance;`peace`slavery`strength]`$ / solution
{ }[ ; ] / lambda with implicit x and y
`war`freedom`ignorance / the x
`peace`slavery`strength / the y
y,x / append x to y
(x,y) / append y to x
! / create dictionary keys!values
`$ / cast input from a string into a symbol
J, 61 bytes
-&.((cut': war freedom ignorance strength slavery peace')i.<)
: fills the 0th position, so the first element corresponds to negative 1st (last), and so on. Lookup the word and negate the index.
Ruby, 70 bytes
->s{a=%w(war freedom ignorance strength slavery peace);a[~a.index(s)]}
- Assign an array of strings
war, freedom, etc. toa:a=%w(...) - Find the index of the passed in parameter inside of
a:a.index(s) - Find the complement of the index.
~a.index(s)ex)~0 == -1; ~1 == -2; ~-3 == 2 - Get the element at the complement:
a[~a.index(s)]
C, 137 101 98 132 characters
counted with escaped characters as 1
void i(char*i){char*s="\7\4\23c\25e\25\36\4\23\1\35\24\0\32\23\34\12\34\6\32\13e";for(s+=i[3]&4?i[4]&2?14:6:0;putchar(*i++^*s++););}
C(bcc 32 bit int), 124 bytes
g(int*a){int*b[]={"war","peace","freedom","slavery","ignorance","strenght"},i=0;for(;i<6&&*b[i++]-*a;);return b[i%2?i:i-2];}
g:Strings->Strings would return the next b[i+1] or the precedent b[i-1] pointer value based on i%2
Axiom, 155 bytes
t:Table(String,String):=table();a:=["war","peace","freedom","slavery","ignorance","strenght"];for i in 1..#a-1 by 2 repeat(t(a.i):=a.(i+1);t(a.(i+1)):=a.i)
test and result
(3) -> for i in a repeat output [i,t(i)]
["war","peace"]
["peace","war"]
["freedom","slavery"]
["slavery","freedom"]
["ignorance","strenght"]
["strenght","ignorance"]
///, 106 bytes
/war/p@eace//peace/wa@r//freedom/slav@ery//slavery/fr@eedom//ignorance/str@ength//stregnth/ignoranc@e//@//
Since /// has no other way of taking input, it can be hard-coded. The input goes at the very end of the program.
Pretty simple, it takes one word, and replaces it with another, but the replacement has an @ sign in it. That is because if there was no @ sign, the program would get stuck replacing one word with the same word. The @s are removed at the end of the program.
Python3, 204 bytes
def O(W):
A="cenayhglmodrtvifspw";R="";X=A.find(W[1]);F=round(131440+(X-3)*(63697-(X-1)*(2024847403.324*X-177731638.24852*X**2+4768471.50996*X**3-7117316292.214)))
while(F>0):R+=A[F%19];F//=19;
return R
A bit longer than I hoped, but hopefully interesting enough.
Try it online! (all testcases included)
Ungolfed:
Alphabet = "cenayhglmodrtvifspw" #Alphabet to convert strings to numbers and vice versa
def StringToNumber (s): #Identify the word by the second letter
return Alphabet.find(s[1])
def NumberToString (O):
res=""
while (O>0):
res+=Alphabet[O%19]
O//=19
return res
def F(x): # the 'magic' function. Note that we can use floats with fewer decimals due to rounding
return 177638 + (172739/3 + (1074106505/264 + (-(32699060621/7392) + (1986769150133/22176 - (2050733259611*(-7 + x))/332640)*(-8 + x))*(-12 + x))* (-1 + x))*(-4 + x)
def Orwell(s):
return NumberToString(round(F(StringToNumber(s))))
Since most answers seem to be literally writing the words or looking them up in a dictionary to output them, I was interested in not doing that, as that could be an improvement for most non-golfing languages.
The basic idea is simple: change the input into a number x, calculate F(x) and change that back into a word.
Of course, F(x) is chosen such that the number corresponding to "war" maps to the number for "peace", etc. This is done using Lagrange interpolation, which gives the unique minimum degree polynomial such that F(x_1)=y_1, F(x_2)=y_2, etc. To reduce the constants in the formula a bit, the characters in the alphabet are placed such that characters in the end of the longer words come first. The first character in the alphabet cannot be at the end of a word, since this means we have to distinguish trialing zeros, which we cannot (int("0039")==int("39")).
Still, the formula is quite big. This approach would probably work better if the strings were over a smaller alphabet, as that reduces the constants in F.
8th, 96 bytes
: f ["ignorance","strength","war","peace","freedom","slavery"] swap ' s:= a:indexof 1 bxor a:@ ;
Usage and output
ok> "war" f . drop
peace
Ungolfed version (with comments)
: f \ s -- a s
["ignorance","strength","war","peace","freedom","slavery"] \ Push the array on the stack
swap \ Put input string on TOS
' s:= a:indexof \ Get the index of the input string in the array
1 bxor \ XOR the index with 1
a:@ \ Push on the stack the element in the array at that index
;
Python, 80 bytes
Somehow outgolfed xnor!
This is an unnamed lambda function, which returns the result.
lambda w,a="war slavery ignorance strength freedom peace".split():a[~a.index(w)]
The list of words is arranged such that it each is in the opposite position to its counterpart. Given the word w, we find its index in the word list, and then bitwise NOT (~) it. This flips all the bits, which is computes n => -n-1. Due to Python's negative indexing, gets the opposite index in the list.
As a kind of unintentional bonus, you can pass any word list of opposites to this function as the second argument.
JavaScript, 78 bytes
w=>(a="war slavery ignorance strength freedom peace".split` `)[5-a.indexOf(w)]
This is a kind-of port of my Python answer. We store the words in a string where each is in the opposite position to its counterpart. We find the index of the given word w, and get that index from the end, to return the result.
Test snippet:
f = w=>(a="war slavery ignorance strength freedom peace".split` `)[5-a.indexOf(w)]
console.log(f("peace"))
console.log(f("ignorance"))
console.log(f("war"))
SmileBASIC, 92 bytes
A$="PEACE
E$="WAR
R$="SLAVERY
L$="FREEDOM
G$="STRENGTH
T$="IGNORANCE
INPUT I$?VAR(I$[1]+"$")
QBIC, 82 bytes
;?mid$(@ignorancefreedom peace strength slavery war `+B,instr(B,A)+27,9)
This is a quite literal translation of my QBasic answer. It's a bit shorter because QBIC handles (some of) the QBasic boilerplate.
Qbasic, 138 99 bytes
D$="ignorancefreedom peace strength slavery war ":INPUT A$:?MID$(D$+D$,INSTR(D$,A$)+27,9)
D$ stores all the words from the left side of the mantra, then all those of the right side. Each word is padded with spaces to exactly 9 letters per word. D$ then gets appended to itself.
Then instr is used to find the index of the word entered by the user. The other part of the mantra is always stored exactly 9*3 positions further in the string, so we print a substring starting at that position, taking 9 characters.
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
><> (Fish), 84 78 bytes
0i~ia%.
v'raw'
>ol?!;
^'htgnerts'
^'yrevals'
^'ecnarongi'
^'ecaep'
^'modeerf'
We start swimming from the upper left, heading right.
First we load the stack with a 0.
Then we read the first letter of input (i), discard it (~), read the second letter (i), and reduce its ASCII value modulo 10 (a%).
This maps a, e, r, l, g, and t to 7, 1, 4, 8, 3, and 6, respectively—let's call this number N. . pops two values from the stack—N and 0—and jumps to line N, character 0.
After a jump, the fish proceeds one tick before executing instructions, so it ignores the first character and swims across line N, which loads the corresponding word onto the stack. Finally we go to line 2, which outputs the whole stack and exits.
- Saved six bytes by using a jump, instead of the cool code self-modification I used before. Oh well.
C, 93
@Arnauld's answer ported to C
#define F(w)(char*[]){"freedom",0,"war",0,"strength",0,"slavery","peace","ignorance"}[w[1]%9]
Dyalog APL, 66 bytes
Either one of these:
'slavery' 'freedom' 'ignorance' 'strength' 'war' 'peace'⊃⍨6|⎕UCS⊃⍞ uses this method (requires ⎕IO←0 which is default on many systems).
'strength' 'freedom' 'war' 'peace' 'slavery' 'ignorance'(⍳⊃(⌽⊣))⊂⍞ does a lookup, then picks the corresponding element from the reversed list.
JavaScript, 80 bytes
Somewhat similar to this JavaScript answer (but developed totally independently), this program reads the input as a base-30 number, takes the parsed value modulo 7, and uses that result as an index to fetch the corresponding value from an array. war cannot be parsed as a base-30 number, so it produces NaN, which falls back to peace outside the array.
s=>"slavery00war0freedom0strength0ignorance".split(0)[parseInt(s,30)%7]||"peace"
Pyke, 29 bytes
.d⻌૽ɦڷࠛ⯤dci@1.^iR@
.d⻌૽ɦڷࠛ⯤ - "war peace freedom slavery ignorance strength"
dc - ^.split(" ")
i - i=^
@ - ^.find(input)
1.^ - ^ xor 1
iR@ - input[^]
SpecBAS - 123
1 DIM a$="war","peace","freedom","slavery","ignorance","strength"
2 INPUT b$: n=SEARCH(a$() FOR b$): ?a$(IIF(ODD n,n+1,n-1))
Finds the index of the input string.
Inline IF checks if that is odd to print either the string after or before that position.
Befunge, 89 88 bytes
<>_00g1v2+%7~%2~"slavery"0"war"0"freedom"0"ignorance"0"strength"0"peace"
|p00:-<
@>:#,_
Explanation
We start by pushing all the possible output strings onto the stack, null terminated. This sequence is executed right to left so the values are pushed in reverse, since that's the order the characters will be needed when they're eventually output.
We then read the first two characters from stdin, which is all we need to identify the input string. If we take the ASCII value of the first letter mod 2, plus the second letter mod 7, we get a unique number in the range 2 to 7.
Input ASCII %2 %7 Sum
[fr]eedom 102 114 0 2 2
[pe]ace 112 101 0 3 3
[sl]avery 115 108 1 3 4
[st]rength 115 116 1 4 5
[ig]norance 105 103 1 5 6
[wa]r 119 97 1 6 7
This number can then be used as a kind of index into the string list on the stack. We iteratively decrement the index (the first time by 2), and for each iteration we clear one string from the stack with the sequence >_.
Once the index reaches zero, we're left with the correct output string at the top of the stack, so we use a simple string output sequence to write the result to stdout.
TI-Basic, 103 84 77 bytes
Reducing to a one-liner saved lots of bytes! Haha, how ironic that statement was...
inString("EALRGT",sub(Ans,2,1
sub("WAR PEACE FREEDOMSLAVERY STRENGTH IGNORANCE ",9Ans+1,4+Ans
Haskell, 104 111 bytes
data O=WAR|FREEDOM|IGNORANCE|PEACE|SLAVERY|STRENGTH deriving(Show,Enum)
f s=toEnum$mod(3+fromEnum s)6::O
Idea:
- Enumerate the keywords such that their counterpart is 3 positions away
- Take the keyword, get its position by
fromEnum, move 3 steps to right (modulus 6) and convert back to the keyword - The
::Ois needed because type inference has some problems. Givingfa signaturef :: O -> Owould have the same effect but is not that short.
Edit:
Replaced
f s=toEnum$mod(3+fromEnum s)6
by
f=toEnum.(`mod`6).(+3).fromEnum
thanks to @Laikoni.
Bash, 100 87 86 78 bytes
a=peace;e=war;r=slavery;l=freedom;g=strength;t=ignorance;x=${1:1:1};echo ${!x}
The 2nd letter of each word uniquely identifies that word, so I use that character as a variable name; the value of that variable is the corresponding other word.
For instance, the 2nd letter of peace is e, and the word corresponding to peace is war, so I set e=war.
Given an input string, the 2nd character of that string is used as a variable name to pull up the desired corresponding word, using bash's indirect parameter expansion.
JavaScript (ES6), 71 78
So much boring than Arnauld's answer, but shorter too.
Now I added the encoding with btoa. In the encoded string there are 4 bytes that I can not post to this site, even if they are valid characters in a javascript string. So I used an hex escape in the form \xHH. Each one of these escapes is counted as 1 byte.
The encoded string is strength0ignorance0peace0war0slavery0freedom
x=>(w=btoa`²ÚÞ\x9e\x0baÒ('¢¶§qí)y§\x1eÓ\x06«ÒÉZ½êòÑúÞyÚ&`.split(0))[w.indexOf(x)^1]
This one is 82 and case insensitive
x=>',,strength,,slavery,war,,,ignorance,peace,freedom'.split`,`[parseInt(x,36)%15]
Test
F=
x=>(w=btoa`²ÚÞ\x9e\x0baÒ('¢¶§qí)y§\x1eÓ\x06«ÒÉZ½êòÑúÞyÚ&`.split(0))[w.indexOf(x)^1]
;['freedom','slavery','war','peace','ignorance','strength']
.forEach(w=>console.log(w + ' -> ' + F(w)))
Pip, 57 55 bytes
(aN_FI"warpeace freedomslavery ignorancestrength"^s)Rax
Saved 2 bytes by adapting MickyT's clever R answer. Try it online or verify all test cases.
Explanation
a is cmdline arg; s is space (implicit)
"..."^s Split string on spaces to create three-item lookup table
FI Filter on this function:
aN_ a is a substring?
( )Rax In matching lookup entry, replace a with empty string and autoprint
C 211 bytes
#define S !strcmp void f(char *s){*a[]="WAR","PEACE","FREEDOM","SLAVERY","IGNORANCE","STRENGTH"};printf("%s",S(s,a[0])?a[1]:S(s,a[1])?a[0]:S(s,a[2])?a[3]:S(s,a[3])?a[2]:S(s,a[4])?a[5]:S(s,a[5])?a[4]:"\0");
Assuming inputs in caps only.
Ungolfed version:
#define S !strcmp
void f(char *);
int main(int argc, char *argv[])
{
system("clear");
f(argv[1]);
}
void f(char *s)
{
char *a[]={"WAR","PEACE","FREEDOM","SLAVERY","IGNORANCE","STRENGTH"};
printf("%s",S(s,a[0])?a[1]:S(s,a[1])?a[0]:S(s,a[2])?a[3]:S(s,a[3])?a[2]:S(s,a[4])?a[5]:S(s,a[5])?a[4]:"\0");
}
Can definitely be shortened in someway!
C (gcc), 113 108 bytes
f(char*s){char*t="5WAR\0+PEACE\09FREEDOM\0'SLAVERY\0;IGNORANCE\0%STRENGTH";while(strcmp(s,++t));puts(t+*--t-47);}
All instances of \0 can be replaced with actual NUL bytes for scoring purposes.
t+*--t-47 is undefined behavior; this may/will not work with other compilers.
C (gcc), 120 107 bytes
f(long*s){long r[2]={0};strcpy(r,s);s=*r>>40?*r>>56?"\n":"":"CE";*r^=*s;r[1]^=69;puts(r);}
Maximum pointer abuse! Requires a little-endian machine and 64-bit longs.
The code contains a few unprintables, but copy-pasting should still work.
PHP, 70 bytes
<?=[ignorance,peace,slavery,strength,freedom,war][md5("^$argv[1]")%7];
Actually, 56 bytes
' "war peace freedom slavery ignorance strength"s;)í1^@E
Unfortunately, without any compression builtins, it's shorter to not compress the string and manually decompress it.
Explanation:
' "war peace freedom slavery ignorance strength"s;)í1^@E
' "war peace freedom slavery ignorance strength"s split the string on spaces
;) make a copy, push it to the bottom of the stack
í index of input in list
1^ XOR with 1
@E that element in the list
CJam, 52 (ASCII only)
"/.|Mv
DO'y EK{ {:nBct'Pt}d4sE"144b26b'af+'j/_ra#1^=
Note: the space-looking things are tab characters (one before and one after "EK{")
Explanation:
The part up to "+" is decompressing the "slaveryjfreedomjwarjpeacejignorancejstrength" string, using base conversion:
string (treated as array of character codes) → (base 144) number → (base 26) array of numbers → (adding 'a' to each number) string
'j/ split around 'j' characters
_ duplicate the resulting word array
ra read the input and wrap in array
# find the index of the input in the word array
1^ XOR with 1
= get the word at the new index
Jolf, 35 bytes
.γG"ΞΠΞ¦ΞpΞsΞΈΞ3I"-5 iγ
There are many unprintables. Here's a hexdump, though it won't do much good:
00000000: 2ece b347 22ce 9e07 cea0 c28e ce9e 07c2 ...G"...........
00000010: 8ac2 a6ce 9e06 c28e 70ce 9e07 73c2 8fce ........p...s...
00000020: 9e06 ce88 c280 ce9e 0133 4922 052d 3520 .........3I".-5
00000030: 69ce b3 i..
Basically, the code looks like:
.γG"..."♣-5 iγ
G"..."♣ split uncompressed string on spaces
γ set gamma to this
iγ index of the input in gamma
.γ -5 and get 5 - this from gamma
Stacked, 70 bytes
@x'war
strength
freedom
slavery
ignorance
peace'LF split:x index\rev\#
Try it here! Takes input on stack and leaves output on stack. For example:
'war'
@x'war
strength
freedom
slavery
ignorance
peace'LF split:x index\rev\#
out
This code is fairly self-explanatory. Slightly modified to run all test cases:
('war' 'slavery' 'ignorance')
{x:'war
strength
freedom
slavery
ignorance
peace'LF split:x index\rev\#x\,}"!
disp
Jelly, 24 bytes
“Ñ=ƘḊ¹ƥ¹Ƙ⁷ṅ8cøGị»Ḳµiɠ^1ị
How it works
First, the token
“Ñ=ƘḊ¹ƥ¹Ƙ⁷ṅ8cøGị»
indexes into Jelly's dictionary to create the string
strength war peace freedom slavery ignorance
which Ḳ splits at spaces to yield the string array
["strength", "war", "peace", "freedom", "slavery", "ignorance"]
µ begins a new, monadic chain, with that string array as its argument, which is also the current return value.
ɠ reads one line of input from STDIN, and i finds its index of the previous return value, i.e., the generated string array.
Now, ^1 takes the bitwise XOR of that index and 1. For even indices – remember that Jelly indexes are 1-based and modular, so strength has index 1 and ignorance has index 6/0 – this increments the index; for odd indices, it decrements them.
Finally, ị retrieves the string at that index from the chain's argument.
Perl 6, 61 bytes
With unprintable characters shown as � (because StackExchange strips them otherwise):
{first {s/^\w+<(\0*$//},["���ce","�������","���
����e"X~^$_]}
Here's an xxd hex dump:
00000000: 7b66 6972 7374 207b 732f 5e5c 772b 3c28 {first {s/^\w+<(
00000010: 5c30 2a24 2f2f 7d2c 5b22 0704 1363 6522 \0*$//},["...ce"
00000020: 2c22 151e 0413 011d 1422 2c22 1a13 1c0a ,".......","....
00000030: 1c06 1a0b 6522 587e 5e24 5f5d 7d0a ....e"X~^$_]}.
Expanded version (unprintable characters replaced with escape sequences, and whitespace & comments added):
{ # A Lambda.
first { # Return first element which:
s/ ^ \w+ <( \0* $ // # after stripping \0 has only word characters left.
},
[ # The array to search:
"\x[7]\x[4]\x[13]ce", # "war" xor "peace"
"\x[15]\x[1e]\x[4]\x[13]\x[1]\x[1d]\x[14]", # "freedom" xor "slavery"
"\x[1a]\x[13]\x[1c]\n\x[1c]\x[6]\x[1a]\x[b]e" # "ignorance" xor "strength"
X~^ $_ # each xor'ed with the input.
]
}
JavaScript (ES6), 80 bytes
s=>'freedom,,war,,strength,,slavery,peace,ignorance'.split`,`[s.charCodeAt(1)%9]
How it works
We use a small lookup table based on the ASCII code of the 2nd character of each word, returning the index of its counterpart.
Word | 2nd char. | ASCII code | MOD 9
----------+-----------+------------+------
war | a | 97 | 7
peace | e | 101 | 2
freedom | r | 114 | 6
slavery | l | 108 | 0
ignorance | g | 103 | 4
strength | t | 116 | 8
As a side note, if mixed case was allowed, using war PEACE FREEDOM slavery IGNORANCE strength with modulo 6 would lead to a perfect hash.
Test
let f =
s=>'freedom,,war,,strength,,slavery,peace,ignorance'.split`,`[s.charCodeAt(1)%9]
console.log('war', '->', f('war'))
console.log('peace', '->', f('peace'))
console.log('freedom', '->', f('freedom'))
console.log('slavery', '->', f('slavery'))
console.log('ignorance', '->', f('ignorance'))
console.log('strength', '->', f('strength'))
Clojure, 98 bytes
Direct port of @Arnauld's JavaScript answer.
#((clojure.string/split"freedom,,war,,strength,,slavery,peace,ignorance"#",")(rem(int(nth % 1))9))
Pregolfed:
(defn war [word]
; Create a list of strings by splitting on commas, and "get" from the resulting list
((clojure.string/split "freedom,,war,,strength,,slavery,peace,ignorance" #","
; Calculate the index to get (see the original answer for details)
(rem (int (nth word 1)) 9))))
Pari/GP , 86 Byte
Pari/GP is an interactive interpreter, we do not need a "print"-cmd for output; however, the Try-It_Online-utility needs a "print"-cmd so I separated this to the "footer".
We define an "object-function" (the letter O reminds me lovely of the Orwell-function... ;-) ) :
x.O=s=[war,freedom,ignorance,strength,slavery,peace];for(k=1,6,if(x==s[k],i=7-k));s[i]
After that, call
print(war.O) \\ input to Pari/GP with the O-rwell-member of "war"
peace \\ output by Pari/GP
(Note, that in Pari/GP the tokens given here are not strings but legal variable-names! That variables should never have any value assigned to)
Perl, 63 bytes
62 bytes + -p flag.
$_=(slavery,freedom,ignorance,strength,war,peace)[(ord)%6+/h/]
ord returns the char code of the first character of the input word.
After the %6, we have :
- freedom => ord = 102 => %6 = 0 - slavery => ord = 115 => %6 = 1 - ignorance => ord = 105 => %6 = 3 - strength => ord = 115 => %6 = 1 - war => ord = 119 => %6 = 5 - peace => ord = 112 => %6 = 4
So we have slavery and strength both returning 1 (since they both start with the same letter), and none returning 2. Hence, we add 1 for strength (it's the only word that will match /h/), and we have each word mapped to an index from 0 to 5.
Python, 81 bytes
l='war peace freedom slavery ignorance strength'.split()
lambda s:l[l.index(s)^1]
Or, same length:
l='war slavery ignorance strength freedom peace'.split()
dict(zip(l,l[::-1])).get
R, 86 87 92 Bytes
Changed to an unnamed function and gsub to sub for a few bytes. The grep determines which of the 3 strings is used and the input is removed from that string with sub.
function(v)sub(v,'',(l=c("warpeace","freedomslavery","ignorancestrength"))[grep(v,l)])
Vim, 60 bytes
D3iwar freedom ignorance peace slavery strength <esc>2?<C-r>"
3wdwVp
Try it online! in the backwards compatible V interpreter.
Of course, if we were to switch to V we could save one byte by using a more convenient input method. But since this is such a small difference I'd prefer using the non-golfing version.
Explanation:
D " Delete this whole line
3i...<esc> " Insert the text three times
2? " Search backwards twice
<C-r>" " For the words we deleted
3w " Move three words forward
dw " Delete a word
V " Select this whole line
p " And paste the word we deleted over it
05AB1E, 30 bytes
05AB1E uses CP-1252.
“ignorance¤í‡î—™šÔÃÒry“#DIk1^è
Try it online! or as a Test suite
Explanation
The straight forward approach
- Push the string
ignorance strength war peace freedom slavery - Split on spaces
- Get the index of the input in the list
- XOR the index with 1
- Get the element in the list at that index
Mathematica, 84 bytes
(x="war""peace")(y="freedom""slavery")(z="ignorance""strength")/#/.x->1/.y->1/.z->1&
Explanation
More "arithmetic" with strings! As in the linked answer, this is based on the fact that you can "multiply" strings in Mathematica which will leave them unevaluated (similar to multiplying two unassigned variables x*y), but that Mathematica will apply basic simplifications, like cancelling factors in a division.
So we start by storing the three pairs as products in x, y, z, respectively and multiply them all together:
(x="war""peace")(y="freedom""slavery")(z="ignorance""strength")
This evaluates to
"freedom" "ignorance" "peace" "slavery" "strength" "war"
(Mathematica automatically sorts the factors, but we don't care about the order.)
We divide this by the input to remove the word we don't want with .../#, since Mathematica cancels the factors. E.g. if the input was "peace" we'd end up with:
"freedom" "ignorance" "slavery" "strength" "war"
Finally, we get rid of the pairs we're not interested in, by substituting each of x, y and z with 1. Again, Mathematica's simplification kicks in that 1*a is always a. This part is done with:
/.x->1/.y->1/.z->1
The nice thing is that Mathematica knows that multiplication is Orderless so this will find the two factors regardless of whether they're adjacent in the product or not. Only the word that is opposite to the input is no longer paired in the product, so that one won't be removed and remains as the sole output.
