War is peace. Freedom is slavery. Ignorance is strength

69

9

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.

Calvin's Hobbies

Posted 2017-01-24T21:53:00.450

Reputation: 84 000

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

1Why 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.140

1@12Me21 No it wouldn't – Calvin's Hobbies – 2017-01-28T20:45:52.180

Answers

58

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

Emigna

Posted 2017-01-24T21:53:00.450

Reputation: 50 798

4214 bytes shorter than the length of all the words. What even is this language? – James – 2017-01-24T22:34:45.250

2@DJMcMayhem: It is pretty good at challenges like these which use common words. Ignorance, unfortunately didn't exist and it was one byte longer to transform Ignore. – Emigna – 2017-01-24T22:38:12.017

66> Push the string ignorance strength war peace freedom slavery I feel like I'm missing about a dozen steps in there! – Bob – 2017-01-24T22:50:37.867

31http://i.imgur.com/vI4ZIfW.jpg – Pavel – 2017-01-24T23:41:34.013

10Can anyone explain where the rest of the words besides "ignorance" come from? – Carcigenicate – 2017-01-25T00:02:26.743

2@Carcigenicate Though I have never programmed in this, I would assume some of the weird characters represent common words – Golden Ratio – 2017-01-25T00:36:26.363

36

05AB1E has a built-in dictionary of words that are represented by 2 bytes each: https://github.com/Adriandmen/05AB1E/blob/master/dictionary.py

– Robert Fraser – 2017-01-25T00:41:20.240

1@RobertFraser Wow. That's... handy. – Carcigenicate – 2017-01-25T00:56:02.113

2Would it work to encode "nor" or "ran" in the middle of the string like you did with slavery? – Nathan Merrill – 2017-01-25T02:54:58.550

4@NathanMerrill: Any ascii character used will turn up normally. Only the specific cp-1252 chars encode words. The problem with the middle of the string is that I'm using a string-type with implicit spaces between words so unfortunately encoding nor would in this case become ig norance. – Emigna – 2017-01-25T07:14:22.787

liberty=freedom – Chloe – 2017-01-25T20:28:30.417

2this is evil. I don't know 05AB1E enough, but does "ignorance" = "ignore".rstrip('e') + "lance".lstrip('l') help? – Tobias Kienzler – 2017-01-26T07:02:15.497

2@TobiasKienzler: Unfortunately not. I tried something similar at first with ignorance = ignore.rstrip('e')+ance but it turned out a byte longer than this. Combining words while modifying them unfortunately requires doing it in separate strings and concatenating, so that actually turns out longer than the actual word :( – Emigna – 2017-01-26T07:12:33.463

1

@Emigna I see. I wonder if that'd still apply for German words like Donaudampfschiffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft

– Tobias Kienzler – 2017-01-26T07:14:54.897

The built-in dictionary of words is awesome. But why is the word "I" encoded at 2 bytes? – Fels – 2017-01-26T15:23:45.423

3@Fels yeah, I don't really see a use case for that :) I think the dict was just taken as is from somewhere leaving words like "i" and "a". – Emigna – 2017-01-26T15:27:54.807

So where do the spaces come from? If they're automatically added when using the two-byte shorthands, how is the space suppressed between "slave" and "ry"? – Tim Pederick – 2017-01-27T04:48:50.447

@TimPederick: The stringtype automatically adds spaces before compressed words (except if it is the first word in the string). So you can add ascii chars after a compressed word and those letters will be counted as part of the word, but you can't do it before a word which is why ignorance and strength are 2 different words here but slave and ry aren't. – Emigna – 2017-01-27T07:24:02.263

47

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

Arnauld

Posted 2017-01-24T21:53:00.450

Reputation: 111 334

2That's a cool approach. Would have never thought of that. – Carcigenicate – 2017-01-25T00:04:12.287

Very nice. The remainders aren't distinct for 6, 7, 8, so you need 9. – ShreevatsaR – 2017-01-25T00:36:57.577

Using a separator like z and then compressing the string with atob saves 8 bytes? – Downgoat – 2017-01-25T02:37:17.220

@Downgoat Wouldn't that require a lot of escaping for characters outside the range 32-126? – Arnauld – 2017-01-25T08:29:12.223

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 – edc65 – 2017-01-25T08:49:07.930

@Arnauld while StackExchange may mangle some of the unprintables, it's still OK as edc said – Downgoat – 2017-01-25T17:06:05.317

@Downgoat & edc65 - Thanks for the clarification! – Arnauld – 2017-01-26T00:37:34.510

32

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.

Dennis

Posted 2017-01-24T21:53:00.450

Reputation: 196 637

16

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.

Martin Ender

Posted 2017-01-24T21:53:00.450

Reputation: 184 808

Argh, so well done! I lose by 7 bytes with WordList[][[<|"l"->14007,"t"->17083,"a"->25105,"r"->32106,"g"->33790,"e"->39048|>@#[[2]]]]&. – Greg Martin – 2017-01-25T01:53:16.470

@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]]]]&. – Martin Ender – 2017-01-25T07:25:27.027

I'll be interested in your opinion, but to me, it seems PP&CG-sanctioned dodgy :) – Greg Martin – 2017-01-25T08:14:59.947

also <|#->#2&~MapThread~{x={"war","slavery","ignorance","strength","fre‌edom","peace"},Reverse@x}|> for 94 bytes – Greg Martin – 2017-01-25T08:15:34.947

13

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

James

Posted 2017-01-24T21:53:00.450

Reputation: 54 537

10

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!

Dennis

Posted 2017-01-24T21:53:00.450

Reputation: 196 637

8

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

xnor

Posted 2017-01-24T21:53:00.450

Reputation: 115 687

Are variable definitions outside the lamba allowed, when using a lambda instead of a full program? – smls – 2017-01-25T00:58:38.380

1

@smls Yes, see this meta discussion. Note that even otherwise, one could smuggle in l as an optional argument.

– xnor – 2017-01-25T00:59:58.910

8

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

Timtech

Posted 2017-01-24T21:53:00.450

Reputation: 12 038

8

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.

Mitchell Spector

Posted 2017-01-24T21:53:00.450

Reputation: 3 392

7

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.

Dada

Posted 2017-01-24T21:53:00.450

Reputation: 8 279

7

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

smls

Posted 2017-01-24T21:53:00.450

Reputation: 4 352

6

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

MickyT

Posted 2017-01-24T21:53:00.450

Reputation: 11 735

5

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.

James Holderness

Posted 2017-01-24T21:53:00.450

Reputation: 8 298

2I like the use of :-< and @>:# "smileys" here :) – Tobias Kienzler – 2017-01-26T07:07:30.717

5

PHP, 70 bytes

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

user63956

Posted 2017-01-24T21:53:00.450

Reputation: 1 571

5

C, 93

@Arnauld's answer ported to C

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

edc65

Posted 2017-01-24T21:53:00.450

Reputation: 31 086

5

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[^]

Blue

Posted 2017-01-24T21:53:00.450

Reputation: 26 661

4

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!

Dennis

Posted 2017-01-24T21:53:00.450

Reputation: 196 637

4

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

edc65

Posted 2017-01-24T21:53:00.450

Reputation: 31 086

3

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

aditsu quit because SE is EVIL

Posted 2017-01-24T21:53:00.450

Reputation: 22 326

3

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

Nick Matteo

Posted 2017-01-24T21:53:00.450

Reputation: 591

3

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

FlipTack

Posted 2017-01-24T21:53:00.450

Reputation: 13 242

2

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)

Gottfried Helms

Posted 2017-01-24T21:53:00.450

Reputation: 201

2

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.

Adám

Posted 2017-01-24T21:53:00.450

Reputation: 37 779

2

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

Conor O'Brien

Posted 2017-01-24T21:53:00.450

Reputation: 36 228

1what does 'LF do? – Downgoat – 2017-01-25T03:14:07.180

1@Downgoat Well, @x sets a variable, '...' is a string, and LF is the linefeed variable – Conor O'Brien – 2017-01-25T03:15:17.807

1Ah I see, so function argument comes before function name? – Downgoat – 2017-01-25T03:37:07.950

1@Downgoat Precisely. Stacked is, well, stack-based. – Conor O'Brien – 2017-01-25T03:52:33.243

1yay now I feel dumb for not realizing such obvious fact :| – Downgoat – 2017-01-25T04:05:13.857

2

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

Conor O'Brien

Posted 2017-01-24T21:53:00.450

Reputation: 36 228

2

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

Mego

Posted 2017-01-24T21:53:00.450

Reputation: 32 998

2

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.

user3389669

Posted 2017-01-24T21:53:00.450

Reputation: 341

2Using point-full notation for f is shorter: f s=toEnum$mod(3+fromEnum s)6 – Laikoni – 2017-01-25T10:40:52.757

2

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.

steenbergh

Posted 2017-01-24T21:53:00.450

Reputation: 7 772

2

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.

FlipTack

Posted 2017-01-24T21:53:00.450

Reputation: 13 242

2

SmileBASIC, 92 bytes

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

12Me21

Posted 2017-01-24T21:53:00.450

Reputation: 6 110

2

Ruby, 70 bytes

->s{a=%w(war freedom ignorance strength slavery peace);a[~a.index(s)]}

  1. Assign an array of strings war, freedom, etc. to a: a=%w(...)
  2. Find the index of the passed in parameter inside of a: a.index(s)
  3. Find the complement of the index. ~a.index(s) ex) ~0 == -1; ~1 == -2; ~-3 == 2
  4. Get the element at the complement: a[~a.index(s)]

earksiinni

Posted 2017-01-24T21:53:00.450

Reputation: 121

1

Pyth, 54 bytes

@Jc"war peace freedom slavery ignorance strength"dx1xJ

Try it here.

Thanks to Leaky Nun for -2.

Erik the Outgolfer

Posted 2017-01-24T21:53:00.450

Reputation: 38 134

or @Jc"war peace freedom slavery ignorance strength"dx1xJ for 54 bytes.

– Leaky Nun – 2017-04-30T10:46:13.077

@LeakyNun OK, I have edited. – Erik the Outgolfer – 2017-04-30T10:58:23.383

1

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.

Discrete lizard

Posted 2017-01-24T21:53:00.450

Reputation: 559

Not sure if this is considered a 'serious contender'. According to this, other methods are ok even if they have a low score, but the comments imply that worse than naive scores are not acceptable.

– Discrete lizard – 2017-04-30T21:12:50.827

1

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

RosLuP

Posted 2017-01-24T21:53:00.450

Reputation: 3 036

1

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.

Try it online!

FrownyFrog

Posted 2017-01-24T21:53:00.450

Reputation: 3 112

1

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@

Run and debug online!

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

Weijun Zhou

Posted 2017-01-24T21:53:00.450

Reputation: 3 396

0

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

Carcigenicate

Posted 2017-01-24T21:53:00.450

Reputation: 3 295

0

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

DLosc

Posted 2017-01-24T21:53:00.450

Reputation: 21 213

0

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!

Abel Tom

Posted 2017-01-24T21:53:00.450

Reputation: 1 150

0

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.

Brian

Posted 2017-01-24T21:53:00.450

Reputation: 1 209

0

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

user18932

Posted 2017-01-24T21:53:00.450

Reputation:

1Try "pewar wapeace slfreedom frslavery stignorance igstrength".split(" "). And you can use Stream.findAny. – Jakob – 2017-09-04T16:11:20.447

0

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"

apsillers

Posted 2017-01-24T21:53:00.450

Reputation: 3 632

Just wrote a solution, w=>(a="war slavery ignorance strength freedom peace".split(" "))[5-a.indexOf(w)], that is also 80 bytes! – FlipTack – 2017-01-28T18:42:33.697

@FlipTack Then is think you can beat mine by doing .split(0)! – apsillers – 2017-01-28T22:19:43.547

You're right, posted it :)

– FlipTack – 2017-01-29T16:30:40.073

0

Tcl, 114 bytes

set L {war peace freedom slavery ignorance strength}
puts [lindex $L [expr [set i [lsearch $L war]]%2?$i-1:($i+1)%7]]

                                         ^
                                         Not accounting "war" word as it is input parameter

Try it online!

sergiol

Posted 2017-01-24T21:53:00.450

Reputation: 3 055

0

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.

steenbergh

Posted 2017-01-24T21:53:00.450

Reputation: 7 772

0

SOGL, 23 bytes (non-competing)

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)

non-competing because somehow 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.

dzaima

Posted 2017-01-24T21:53:00.450

Reputation: 19 048

0

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
;

Chaos Manor

Posted 2017-01-24T21:53:00.450

Reputation: 521

0

///, 106 bytes

/war/p@eace//peace/wa@r//freedom/slav@ery//slavery/fr@eedom//ignorance/str@ength//stregnth/ignoranc@e//@//

Try it online!

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.

Comrade SparklePony

Posted 2017-01-24T21:53:00.450

Reputation: 5 784

0

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

RosLuP

Posted 2017-01-24T21:53:00.450

Reputation: 3 036

0

Japt, 38 37 bytes

`°ãïêæ¡È7ea­«lavyåMLL­`qu
g3+UbNg

Try it

Shaggy

Posted 2017-01-24T21:53:00.450

Reputation: 24 623

0

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

streetster

Posted 2017-01-24T21:53:00.450

Reputation: 3 635

0

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.

Closed Your

Posted 2017-01-24T21:53:00.450

Reputation: 1

0

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

Try it online!

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

Try it online!

Sara J

Posted 2017-01-24T21:53:00.450

Reputation: 2 576

0

05AB1E, 29 bytes

“‡î—™ÃÒryšÔ¤í¸ï“¨'–›¦«#DIk1^è

Try it online!

Grimmy

Posted 2017-01-24T21:53:00.450

Reputation: 12 521

-1

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++););}

Try it online

Ahemone

Posted 2017-01-24T21:53:00.450

Reputation: 608

It's likely because I'm cheating a little and relying on the layout of the input strings in the main function. I was hoping someone would pick up on that ;) – Ahemone – 2017-01-29T11:33:07.233

1You're printing extra null characters, and your byte count is incorrect. – Jakob – 2017-09-04T16:19:28.430