68
\$\begingroup\$

As George Orwell wrote in 1984:

War is peace
Freedom is slavery
Ignorance is strength

Write a program or function that takes in one of the six main words from the Orwell quote and outputs its counterpart.

Specifically:

[input] -> [output]
war -> peace
peace -> war
freedom -> slavery
slavery -> freedom
ignorance -> strength
strength -> ignorance

No other input/output pairs are required.

You should assume the words are always fully lowercase, as above. Alternatively, you may assume the words are always fully uppercase: WAR -> PEACE, PEACE -> WAR, etc.

The shortest code in bytes wins.

\$\endgroup\$
  • 10
    \$\begingroup\$ Related :-) \$\endgroup\$ – xnor Jan 24 '17 at 22:04
  • 2
    \$\begingroup\$ @Dennis Yes. Either everything is lowercase, or everything is uppercase. \$\endgroup\$ – Calvin's Hobbies Jan 25 '17 at 2:26
  • 3
    \$\begingroup\$ Don'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. \$\endgroup\$ – DLosc Jan 25 '17 at 8:51
  • 13
    \$\begingroup\$ This is a doubleplusgood challenge \$\endgroup\$ – Jojodmo Jan 26 '17 at 6:28
  • 3
    \$\begingroup\$ Almost nobody likes this book. It's full of lies! Sad. \$\endgroup\$ – Peter A. Schneider Jan 26 '17 at 10:38

53 Answers 53

58
\$\begingroup\$

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
\$\endgroup\$
  • 42
    \$\begingroup\$ 14 bytes shorter than the length of all the words. What even is this language? \$\endgroup\$ – DJMcMayhem Jan 24 '17 at 22:34
  • 65
    \$\begingroup\$ > Push the string ignorance strength war peace freedom slavery I feel like I'm missing about a dozen steps in there! \$\endgroup\$ – Bob Jan 24 '17 at 22:50
  • 31
    \$\begingroup\$ i.imgur.com/vI4ZIfW.jpg \$\endgroup\$ – Pavel Jan 24 '17 at 23:41
  • 10
    \$\begingroup\$ Can anyone explain where the rest of the words besides "ignorance" come from? \$\endgroup\$ – Carcigenicate Jan 25 '17 at 0:02
  • 36
    \$\begingroup\$ 05AB1E has a built-in dictionary of words that are represented by 2 bytes each: github.com/Adriandmen/05AB1E/blob/master/dictionary.py \$\endgroup\$ – Robert Fraser Jan 25 '17 at 0:41
48
\$\begingroup\$

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'))

\$\endgroup\$
  • 2
    \$\begingroup\$ That's a cool approach. Would have never thought of that. \$\endgroup\$ – Carcigenicate Jan 25 '17 at 0:04
  • \$\begingroup\$ Very nice. The remainders aren't distinct for 6, 7, 8, so you need 9. \$\endgroup\$ – ShreevatsaR Jan 25 '17 at 0:36
  • \$\begingroup\$ Using a separator like z and then compressing the string with atob saves 8 bytes? \$\endgroup\$ – Downgoat Jan 25 '17 at 2:37
  • \$\begingroup\$ @Downgoat Wouldn't that require a lot of escaping for characters outside the range 32-126? \$\endgroup\$ – Arnauld Jan 25 '17 at 8:29
  • \$\begingroup\$ using atob you get a string that is mostly valid javascript - eventually you need to escape only the `\` and the closing quote. It can be difficult to post it on this site, but that does not invalidate the answer. See the perl answer by smis \$\endgroup\$ – edc65 Jan 25 '17 at 8:49
32
\$\begingroup\$

Jelly, 24 bytes

“Ñ=ƘḊ¹ƥ¹Ƙ⁷ṅ8cøGị»Ḳµiɠ^1ị

Try it online!

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.

\$\endgroup\$
16
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Argh, so well done! I lose by 7 bytes with WordList[][[<|"l"->14007,"t"->17083,"a"->25105,"r"->32106,"g"->33790,"e"->39048|>@#[[2]]]]&. \$\endgroup\$ – Greg Martin Jan 25 '17 at 1:53
  • \$\begingroup\$ @GregMartin Oh, WordList is nice. Taking a list of characters as input and returning a string seems a bit dodgy though. ;) That said, you can do 4 bytes better with x[[7-Position[x={"war","slavery","ignorance","strength","freedom","peace"},#][[1,1]]]]&. \$\endgroup\$ – Martin Ender Jan 25 '17 at 7:25
  • \$\begingroup\$ I'll be interested in your opinion, but to me, it seems PP&CG-sanctioned dodgy :) \$\endgroup\$ – Greg Martin Jan 25 '17 at 8:14
  • \$\begingroup\$ also <|#->#2&~MapThread~{x={"war","slavery","ignorance","strength","fre‌edom","peace"},Reverse@x}|> for 94 bytes \$\endgroup\$ – Greg Martin Jan 25 '17 at 8:15
13
\$\begingroup\$

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
\$\endgroup\$
10
\$\begingroup\$

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.

Try it online!

\$\endgroup\$
8
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ Are variable definitions outside the lamba allowed, when using a lambda instead of a full program? \$\endgroup\$ – smls Jan 25 '17 at 0:58
  • 1
    \$\begingroup\$ @smls Yes, see this meta discussion. Note that even otherwise, one could smuggle in l as an optional argument. \$\endgroup\$ – xnor Jan 25 '17 at 0:59
8
\$\begingroup\$

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.
    ]
}
\$\endgroup\$
8
\$\begingroup\$

Bash, 100 87 86 78 bytes

a=peace;e=war;r=slavery;l=freedom;g=strength;t=ignorance;x=${1:1:1};echo ${!x}

Try it online!

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.

\$\endgroup\$
8
\$\begingroup\$

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
\$\endgroup\$
7
\$\begingroup\$

Perl, 63 bytes

62 bytes + -p flag.

$_=(slavery,freedom,ignorance,strength,war,peace)[(ord)%6+/h/]

Try it online!

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.

\$\endgroup\$
6
\$\begingroup\$

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)])
\$\endgroup\$
5
\$\begingroup\$

PHP, 70 bytes

<?=[ignorance,peace,slavery,strength,freedom,war][md5("^$argv[1]")%7];
\$\endgroup\$
5
\$\begingroup\$

Befunge, 89 88 bytes

<>_00g1v2+%7~%2~"slavery"0"war"0"freedom"0"ignorance"0"strength"0"peace"
 |p00:-<
@>:#,_

Try it online!

Explanation

Source code with execution paths highlighted

* 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.

\$\endgroup\$
  • 2
    \$\begingroup\$ I like the use of :-< and @>:# "smileys" here :) \$\endgroup\$ – Tobias Kienzler Jan 26 '17 at 7:07
5
\$\begingroup\$

Pyke, 29 bytes

.d⻌૽ɦڷࠛ⯤dci@1.^iR@

Try it here!

.d⻌૽ɦڷࠛ⯤           -     "war peace freedom slavery ignorance strength"
         dc         -     ^.split(" ")
           i        -    i=^
            @       -   ^.find(input)
             1.^    -  ^ xor 1
                iR@ - input[^]
\$\endgroup\$
5
\$\begingroup\$

C, 93

@Arnauld's answer ported to C

#define F(w)(char*[]){"freedom",0,"war",0,"strength",0,"slavery","peace","ignorance"}[w[1]%9]
\$\endgroup\$
4
\$\begingroup\$

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.

Try it online!

\$\endgroup\$
4
\$\begingroup\$

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)))

\$\endgroup\$
3
\$\begingroup\$

CJam, 52 (ASCII only)

"/.|Mv
DO'y    EK{ {:nBct'Pt}d4sE"144b26b'af+'j/_ra#1^=

Try it online

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
\$\endgroup\$
3
\$\begingroup\$

><> (Fish), 84 78 bytes

0i~ia%.
v'raw'
>ol?!;
^'htgnerts'
^'yrevals'

^'ecnarongi'
^'ecaep'
^'modeerf'

Try it online!

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.
\$\endgroup\$
3
\$\begingroup\$

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"))

\$\endgroup\$
2
\$\begingroup\$

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

Try it online!

(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)

\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
  • 1
    \$\begingroup\$ what does 'LF do? \$\endgroup\$ – Downgoat Jan 25 '17 at 3:14
  • 1
    \$\begingroup\$ @Downgoat Well, @x sets a variable, '...' is a string, and LF is the linefeed variable \$\endgroup\$ – Conor O'Brien Jan 25 '17 at 3:15
  • 1
    \$\begingroup\$ Ah I see, so function argument comes before function name? \$\endgroup\$ – Downgoat Jan 25 '17 at 3:37
  • 1
    \$\begingroup\$ @Downgoat Precisely. Stacked is, well, stack-based. \$\endgroup\$ – Conor O'Brien Jan 25 '17 at 3:52
  • 1
    \$\begingroup\$ yay now I feel dumb for not realizing such obvious fact :| \$\endgroup\$ – Downgoat Jan 25 '17 at 4:05
2
\$\begingroup\$

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..

Here's an online link.

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
\$\endgroup\$
2
\$\begingroup\$

Actually, 56 bytes

' "war peace freedom slavery ignorance strength"s;)í1^@E

Try it online!

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
\$\endgroup\$
2
\$\begingroup\$

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 ::O is needed because type inference has some problems. Giving f a signature f :: O -> O would 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.

\$\endgroup\$
  • 2
    \$\begingroup\$ Using point-full notation for f is shorter: f s=toEnum$mod(3+fromEnum s)6 \$\endgroup\$ – Laikoni Jan 25 '17 at 10:40
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

SmileBASIC, 92 bytes

A$="PEACE
E$="WAR
R$="SLAVERY
L$="FREEDOM
G$="STRENGTH
T$="IGNORANCE
INPUT I$?VAR(I$[1]+"$")
\$\endgroup\$
2
\$\begingroup\$

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)]

Try it online!

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.