3
\$\begingroup\$

Introduction

You started to write a "Hello, World!" program, but after you wrote the part to print the hello, you forgot what your program should actually print. So now, you somehow managed it to write a program which can check if the entered word is what you search.

The task

Your task is to write a program or function, which first prints Hello... eh, whom should I greet?, then asks for input, and if the input equals world ignoring capitalization, the program should print Ah, yes. World., else it should print No. That isn't what I meant..

But you are not allowed to use any of the bytes equivalent to the ASCII values of:
worldWORLD
- that is, for those using code-pages not aligned with ASCII, bytes:
0x...: 77, 6f, 72, 6c, 64, 57, 4f, 52, 4c, 44.

Compact rules

  • No substring of the byte-string worldWORLD may appear in your program or in the file name of the program on any way

  • print "Hello... eh, whom should I greet?"; if input.lower == "world" print "Ah, yes. World."; else print "No. That isn't what I meant.";

  • Leading or trailing spaces are ignored.

  • This is a challenge, so the program with the lowest amount of chars wins!

\$\endgroup\$
5
  • \$\begingroup\$ "But you are not allowed to use any of the chars w, o, r, l or d in any capitalization in your program." - what if my language doesn't use any of these characters? Or rather, what if it uses raw bytes rather than characters? \$\endgroup\$ Commented Apr 23, 2017 at 18:44
  • \$\begingroup\$ @JanDvorak Well, then you're lucky. The chars are needed in the string "world", which appears at least one time, but if you found a way to ignore that, you solved the question :D \$\endgroup\$
    – univalence
    Commented Apr 23, 2017 at 18:46
  • 10
    \$\begingroup\$ I've downvoted this challenge, because I don't think it's very easily golfable. There's not really more than 1 way to do this, which is print string; input(); isequal? string1 : string2. It panders to golfing languages with those builtins not assigned to world and with short names. \$\endgroup\$
    – Riker
    Commented Apr 23, 2017 at 19:25
  • \$\begingroup\$ @CartManagerXD Here is a functional equivalent of my below program submission, although it breaks FP best practices of avoiding sideeffects and non-argument data. \$\endgroup\$
    – Adám
    Commented Apr 24, 2017 at 0:26
  • 1
    \$\begingroup\$ I've upvoted this challenge, as there is in fact a lot of ways to golf it. See Python 3 submissions in here. \$\endgroup\$
    – user85052
    Commented Jul 8, 2019 at 11:00

14 Answers 14

4
\$\begingroup\$

Jelly, 70 bytes

“¡Kịy<⁷ẊṘṘsṁñAỵḋẇ,ẇʂI»Ṅø“¢ƈṫ(Ɲ¬÷Ø“¡ṣƓ»µɠŒteḊȧKȯ“TḲj/Ẇi¤cecṡĿt⁺ƘNƁ⁻»;”.

Jelly's code-page is equal to ASCII in the range ' ', 0x20, through to '~', 0x7e, inclusive so the lack of any of worldWORLD in the code above suffices (note: ẇȯṘĿḊ are not woRLD or equivalent bytes.)

Try it online!

This took a little fiddling to avoid the forbidden bytes:
all the naive string compressions contained illegal characters;
finding the first index of a sublist within another is performed with the w atom;
finding the length of a list (for chopping and measuring to replace w) uses L - something I considered was summing the indices with JS (triangle(9)=45), I ended up using a list of strings and a separate trailing period to kill three birds with one stone [sic], allowing a dequeue-flatten-dequeue chain, ḊFḊ, to pick out the word World, this can be further shortened by post-joining the list with the space using , allowing for a simple dequeue, to be used instead saving another byte.

Adding the trailing period to whichever response is output as a single action also allowed compression without illegal bytes.

For some reason, the word yes is not in Jelly's dictionary, yet even though compressing Ah, yes. is the same length as the raw string, having the compression as a list of strings ['Ah, yes.',' World'] (“¢ƈṫ(Ɲ¬÷Ø“¥ḄḞ») is shorter by two bytes than concatenating (“Ah, yes.”;“¥ḄḞ»), the third bird.

For the first message I compressed Hell as a word and prepended the string '...' with an 'o' to avoid the forbidden bytes.

Commented code:

W: “¡Kịy<⁷ẊṘṘsṁñAỵḋẇ,ẇʂI» - compressed string "Hello... eh, whom should I greet?"

R: “¢ƈṫ(Ɲ¬÷Ø“¡ṣƓ» - compressed list of strings ["Ah, yes.","World"]

D: “TḲj/Ẇi¤cecṡĿt⁺ƘNƁ⁻» - compressed string "No. That isn't what I meant"

WṄøRµɠŒteḊȧKȯD;”. - Main link: no arguments
W                 - "Hello... eh, whom should I greet?"
 Ṅ                - print and yield
  ø               - niladic chain separation, no input to the following
   R              - ["Ah, yes.","World"]
    µ             - monadic chain separation, call that L
     ɠ            - read a line from STDIN
      Œt          - title-case it (e.g. "wOrLd" -> "World")
         Ḋ        - dequeue L: ["World"]
        e         - exists in?       (0 or 1)
          ȧ       - and L            (0 or ["Ah, yes.","World"])
           K      - join with spaces (0 or "Ah, yes. World")
             D    - "No. That isn't what I meant"
            ȯ     - or               ("No. That isn't what I meant" or "Ah, yes. World")
               ”. - literal '.'
              ;   - concatenate      ("No. That isn't what I meant." or "Ah, yes. World.")
\$\endgroup\$
4
\$\begingroup\$

Java 8, 376 361 bytes

v->{System.\u006Fut.p\u0072int\u006Cn("He\u006C\u006C\u006F... eh, \u0077h\u006Fm sh\u006Fu\u006C\u0064 I g\u0072eet?");System.\u006Fut.p\u0072int\u006Cn(ne\u0077 java.uti\u006C.Scanne\u0072(System.in).next().equa\u006CsIgn\u006F\u0072eCase("\u0077\u006F\u0072\u006C\u0064")?"Ah, yes. \u0057\u006F\u0072\u006C\u0064.":"N\u006F. That isn't \u0077hat I meant.");}

-15 bytes switching from Java 7 to 8.

Try it online.

Explanation:

In Java you can use unicode escapes in the form of \u####. Fortunately, u wasn't one of the disallowed characters, so I've used these unicode escapes for the characters that are disallowed.

The method above, without unicode escapes:

v->{                            // Method with empty unused parameter & no return
  System.out.println("Hello... eh, whom should I greet?");
                                //  Print the greetings line
  System.out.println(new java.util.Scanner(System.in).next()
                                //  Get the user input from STDIN
    .equalsIgnoreCase("world")? //  If it's equal to (case-insensitive) "world":
      "Ah, yes. World."         //   Print the World-response line
    :                           //  Else:
      "No. That isn't what I meant.");}
                                //   Print the No-response line

Taking the input as parameter and returning a String instead of using STDIN/STDOUT (which I think is allowed reading the challenge again, so not sure why I hadn't done that four years ago when I posted my answer), it would be 239 bytes instead:

s->"He\u006C\u006C\u006F... eh, \u0077h\u006Fm sh\u006Fu\u006C\u0064 I g\u0072eet?\n"+(s.equa\u006CsIgn\u006F\u0072eCase("\u0077\u006F\u0072\u006C\u0064")?"Ah, yes. \u0057\u006F\u0072\u006C\u0064.":"N\u006F. That isn't \u0077hat I meant.")

Try it online.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You could use Java 8 and turn it into a lambda by replacing v\u006Fi\u0064 c() with ()->. \$\endgroup\$
    – Okx
    Commented Apr 26, 2017 at 11:38
3
\$\begingroup\$

SOGL, 67 bytes

P5√~!9!j┌⁰‚V{7Χ←½χķ²‘q"A6‘,u=?"ΤΞ¦▲ξ⌠²ō⅞Σ↔─╚‘p}"⁽∙šžøp⅔…ļ4∑Ν…ZH]└»‘

Explanation:

...‘                        push "Hello... eh, whom should I greet?"
    q                       output, without disabling implicit output
     "A6‘                   push "world"
         ,u=?       }       if equal to lowercased input
             "....‘           push "Ah, yes. World."
                   p          output, disabling implicit output
                     "...‘  push "No. That isn't what I meant."
                            implicitly output that if that hasn't been disabled by the if.
\$\endgroup\$
3
  • \$\begingroup\$ FYI - I know you answered before the hold, but I made an edit to make the challenge a little more language-agnostic. If that holds this would no longer be valid (it contains one P and two ps, 0x4f and 0x6f respectively, I believe). \$\endgroup\$ Commented Apr 23, 2017 at 20:08
  • \$\begingroup\$ @JonathanAllan Oh. Never noticed that the byte table of SOGL is not ASCII-aligned, trough it's supposed to be. The problem with fixing that is that (almost) all my previous answers would not work with that being fixed. \$\endgroup\$
    – dzaima
    Commented Apr 23, 2017 at 21:06
  • \$\begingroup\$ Oh, I thought it might have been on purpose. You could change your / make a second code page - languages can change, although I agree it could confuse. I am surprised, once again, by how short the compressions are. Would you mind adding an answer to the tips question I just asked?! \$\endgroup\$ Commented Apr 23, 2017 at 21:23
2
\$\begingroup\$

JavaScript (ES6), 215 247 bytes

If I've understood correctly, the challenge is to not use any of the following chracters: 0, 2, 4, 5, 6, 7, c, d, f, l, o, r, w, x, D, L, O, R, W.

(t=this,T=""+t,A=T[8],a=T[13],b=T[1],e=(""+!!1)[1],g=(""+!1)[3-1],h=T[11])=>t[`p${e+b}mpt`](`He${g+g+b}... eh, ${a}h${b}m sh${b}u${g+h} I g${e}eet?`)[`t${b}L${b+a}e${e}Case`]()==a+(z=b+e+g+h)?`Ah, yes. ${A+z}.`:`N${b}. That isn't ${a}hat I meant.`

Try It

y=
(t=this,T=""+t,A=T[8],a=T[13],b=T[1],e=(""+!!1)[1],g=(""+!1)[3-1],h=T[11])=>t[`p${e+b}mpt`](`He${g+g+b}... eh, ${a}h${b}m sh${b}u${g+h} I g${e}eet?`)[`t${b}L${b+a}e${e}Case`]()==a+(z=b+e+g+h)?`Ah, yes. ${A+z}.`:`N${b}. That isn't ${a}hat I meant.`
alert(y())

Explanation

t=this         // assigns the window object to variable t
T=""+t         // converts t to a string ("[object Window]") and assigns it to variable T
A=T[8]         // assigns the 9th character of T ("W") to variable A
a=T[13]        // assigns the 14th character of T ("w") to variable a
b=T[1]         // assigns the 2nd character of T ("o") to variable b
e=(""+!!1)[1]  // converts true to a string and assigns the 2nd character ("r") to variable e
g=(""+!1)[3-1] // converts false to a string and assigns the 3rd character ("l") to variable g
               // (1 is a truthy value in JS, so !1=false and !!1=true)
h=T[11]        // assigns the 12th character of T ("d") to variable h

// The rest then uses template literals and the above variables to construct the following:

window["prompt"]("Hello... eh, whom should I greet?")["toLowerCase"]()=="w"+(z="orld")?
"Ah, yes. W"+z:
"No. That isn't what I meant."
\$\endgroup\$
2
\$\begingroup\$

JavaScript, 484 347 bytes

This is horrible and could most likely be golfed more. Just seeing if I could answer in JavaScript with the restrictions.

z=({}+[]+{})[-~[]]
y=(!![]+[])[+!+[]]
x=([][[]]+[])[!+[]+!+[]]
v=this
c=n=>v[`St${y}ing`][`f${y}${z}mCha${y}C${z}${x}e`](n*9)
u=c(12)
t=c(13.3)
v[s=`a${u}e${y}t`](`He${u+u+z}... eh, ${t}h${z}m sh${z}u${u+x} I g${y}eet?`)
v[s](v[`p${y+z}mpt`]()[`t${z+c(8.5)+z+t}e${y+c(7.5)}ase`]()==t+(s=z+y+u+x)?`Ah, yes. ${c(9.7)+s}.`:`N${z}. That isn't ${t}hat I meant.`)

Try it online!

z=({}+[]+{})[-~[]]
y=(!![]+[])[+!+[]]
x=([][[]]+[])[!+[]+!+[]]
v=this
c=n=>v[`St${y}ing`][`f${y}${z}mCha${y}C${z}${x}e`](n*9)
u=c(12)
t=c(13.3)
v[s=`a${u}e${y}t`](`He${u+u+z}... eh, ${t}h${z}m sh${z}u${u+x} I g${y}eet?`)
v[s](v[`p${y+z}mpt`]()[`t${z+c(8.5)+z+t}e${y+c(7.5)}ase`]()==t+(s=z+y+u+x)?`Ah, yes. ${c(9.7)+s}.`:`N${z}. That isn't ${t}hat I meant.`)

\$\endgroup\$
4
  • \$\begingroup\$ z,y and x are JSF*ck, right? \$\endgroup\$
    – univalence
    Commented May 13, 2017 at 16:00
  • \$\begingroup\$ @MegaMan sort of but not quite. -~{} are not in the allowed characters. \$\endgroup\$
    – powelles
    Commented May 13, 2017 at 16:25
  • \$\begingroup\$ Oh. Of course :P But x and y are. \$\endgroup\$
    – univalence
    Commented May 13, 2017 at 16:32
  • \$\begingroup\$ @MegaMan definitely. \$\endgroup\$
    – powelles
    Commented May 13, 2017 at 16:36
2
\$\begingroup\$

05AB1E, 71 bytes

.•ǝ·Þ•“Ÿ™...Ûß,£Ô‚© I ÿ?“ćuì,u‘‚ï‘Qi“ºÆ,…Ü.‚ï.“ë“€¸.€Š€ˆn't€À I±….“}.ª,

05AB1E uses a custom code-page, but the lower- and uppercase characters are on the same hexadecimal positions on the code-page, so as long as I don't use worldWORLD it's fine.

Try it online.

Explanation:

.•ǝ·Þ•               # Push compressed string "greet" (which unfortunately isn't part of
                     # the dictionary, AND contains an 'r'..)
 “Ÿ™...Ûß,£Ô‚© I ÿ?“ # Push dictionary string "hello... eh, whom should I ÿ?",
                     # where the `ÿ` is filled with the "greet" we pushed earlier
  ć                  # Extract head; pop and push remainder and first character separately
   u                 # Uppercase this first character
    ì                # Prepend it back to the remainder-string
     ,               # And output it to STDOUT with trailing newline
u                    # Convert the (implicit) input-string to uppercase
 ‘‚ï‘                # Push dictionary string "WORLD"
     Qi              # If they are equal:
       “ºÆ,…Ü.‚ï.“   #  Push dictionary string "ah, yes. world."
      ë              # Else:
       “€¸.€Š€ˆn't€À I±….“
                    '#  Push dictionary string "no. that isn't what I meant."
      }.ª            # After the if-else: sentence capitalize the string
         ,           # And also output it to STDOUT

See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why .•ǝ·Þ• is "greet"; “Ÿ™...Ûß,£Ô‚© I ÿ?“ is "hello... eh, whom should I ÿ?"; ‘‚ï‘ is "WORLD"; “ºÆ,…Ü.‚ï.“ is "ah, yes. world."; and “€¸.€Š€ˆn't€À I±….“ is "no. that isn't what I meant.".

If all characters would be allowed, there are only two minor differences:

  • The greet would have been placed literally inside the dictionary sentence
  • The input would have been changed to lowercase with l instead, so '‚ï could be used for "world"

So it would be 68 bytes instead:

“Ÿ™...Ûß,£Ô‚© I greet?“ćuì,l'‚ïQi“ºÆ,…Ü.‚ï.“ë“€¸.€Š€ˆn't€À I±….“}.ª,

Try it online.

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

Vyxal, 75 bytes

`ƈṡ... eh, ↓Ṅ ƛ¤ I £Ẋet?`,⇩`ƛ†`=[`Ah, ∨ȯ. ƛ€.`,|«ƛτ«ǐ`. λ÷ ⋏°'t λ⟨ I ḋ↓.`J,

Try it Online!

\$\endgroup\$
1
\$\begingroup\$

APL (Dyalog), 171 bytes

No compression here!

Requires ⎕IO←0 which is default on many systems. All characters are in the character set.

c←{⎕AV[¯25+⎕AV⍳⍵]}
c'Á.558GGGm.1´m∆186m¥18£5¯mÂm0⊢..$⍒'
c'Ë8GmÒ1z$m2¥7v$m∆1z$mÂm6.z7$G' 'Z1mB.¥GmÕ8⊢5¯G'⊃⍨(c'∆8⊢5¯')≡819⌶⍞

Try it online!

Works by first defining a custom decoding function c which decodes from a simple shifted encoding which was carefully chosen to be able to represent all the required strings while avoiding the ten forbidden characters.

c←{} a function:
⎕AV[] the Atomic Vector indexed by
  ¯25+ the downshifted-by-25
  ⎕AV⍳ indices into the Atomic Vector for
   the argument

c'Á.558GGGm.1´m∆186m¥18£5¯mÂm0⊢..$⍒' implicitly print the decoded Hello... eh, whom should I greet?

 get character input
819⌶ lowercase it
()≡ compare it to
c'∆8⊢5¯'  the decoded world
'Ë8GmÒ1z$m2¥7v$m∆1z$mÂm6.z7$G' 'Z1mB.¥GmÕ8⊢5¯G'⊃⍨ use that Boolean to pick from the encoded No. That isn't what I meant. (if false) and Ah yes. World. (if true)
c decode that

\$\endgroup\$
1
\$\begingroup\$

brainfuck, 1445 bytes

->-[------->+<]>-.-[->+++++<]>++.+++++++..+++.[->+++++<]>+++...++[--->++<]>.+[->+++<]>++.+++.----[->+++<]>.------------.--[->++++<]>-.+[->+++<]>.+++++++.--.[->+++++<]>-.---[->++++<]>-.-----------.+++++++.++++++.---------.--------.-[--->+<]>-.++++[->++<]>+.-[->++++<]>.++[->+++<]>+.+++++++++++.-------------..[--->+<]>---.-[->+++++<]>.[-]+[-<+]->>>,[>>+<+<-]<------[>+++<--]>[->-<]+>[<->[-]]<[<<+>>-]-[>+<---]>++[->-<]+>[<->[-]]<[<<<+>>>-]+[-<+]->>>,[>>+<+<-]<-[>--<-------]>+[->-<]+>[<->[-]]<[<<+>>-]-[>+<---]>------[->-<]+>[<->[-]]<[<<<+>>>-]+[-<+]->>>,[>>+<+<-]<-[>++<+++++++++]>[->-<]+>[<->[-]]<[<<+>>-]-[>+<---]>---[->-<]+>[<->[-]]<[<<<+>>>-]+[-<+]->>>,[>>+<+<-]<-[>--<-------]>--[->-<]+>[<->[-]]<[<<+>>-]-[>+<-------]>+++[->-<]+>[<->[-]]<[<<<+>>>-]+[-<+]->>>,[>>+<+<-]<-[>++<-----]>--[->-<]+>[<->[-]]<[<<+>>-]----[>---<----]>+[->-<]+>[<->[-]]<[<<<+>>>-]+[-<+]->>,[<+>-]<-----[>+>+<<-]>[<+>-]+>[>-[--->+<]>-------.-[--->+<]>.[->+++++<]>+++.++[--->++<]>.>-[--->+<]>-.[---->+++++<]>-.-------.--[--->+<]>-.[---->+<]>+++.-[--->++<]>-.++++++++++.-----.[++>---<]>++.[->+++<]>-.[---->+<]>+++.--[->++++<]>-.+[->+++<]>.-------.--[--->+<]>-.[---->+<]>+++.++++[->++<]>+.-[->++++<]>.+[----->+<]>.--------.----.+++++++++++++.++++++.[++>---<]>.+[-<+]->>->[-]]<[>>----[---->+<]>++.[--->+<]>---.----[->+++<]>.------------.--[->++++<]>+.--[->+++<]>.[--->+<]>----.+[++>---<]>.++[--->++<]>.---[->+++<]>.-[--->+<]>---.+++.------.--------.[->+++<]>++.+[-<+]->>-]

Try it online!

Requires an 8-bit wrapping implementation where EOF=0.

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 76 73 bytes

u”Ÿ™... ”“Ûß,£Ô‚© I g“«’‚™ˆÆ?’«,‘‚ï‘Qi“ºÆ,…Ü.‚ï.“ë“€¸.€Š€ˆn't€À I±….“}.ª,

Try it online!

-3 bytes thanks to @ovs.

                                # (implicit) push STDIN to stack
u                               # convert top of stack to uppercase
”Ÿ™... ”“Ûß,£Ô‚© I g“«’‚™ˆÆ?’«  # push "Hello... eh, whom do I greet?"
,                               # output top of stack to STDOUT
‘‚ï‘                            # push "WORLD"
  Qi                            # if top two stack values are equal...
    “ºÆ,…Ü.‚ï.“                 # push "ah, yes. world."
  ë                             # else... 
    “€¸.€Š€ˆn't€À I±….“         # push "no. that isn't what I meant."
}                               # exit if statement
.ª                              # push top of stack in sentence case
,                               # output top of stack to STDOUT
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nice answer! If you use ëlse, you can save some bytes on the repeated : tio.run/##yy9OTMpM/f8/… \$\endgroup\$
    – ovs
    Commented Sep 23, 2020 at 22:12
1
\$\begingroup\$

Python 3, 186 bytes

t=a,b,c,e,f=5*'%c'%(87,111,114,108,100)
exec(f'exit(["N{b}. That isn\'t \u0077hat I meant.","Ah, yes. {t}."][input("He{e+e+b}... eh, \u0077h{b}m sh{b}u{e+f} I g{c}eet?").tit{e}e()==t])')

Try it online!

Outputs to STDERR.

\$\endgroup\$
0
\$\begingroup\$

Retina, 211 194 bytes

T`a-z`A-Z
T`A-Z`A-C\E-KMNPQS-VX-Z(%[]{
^(?!%SVNE$).*
Qs. Yiay jxq'y =iay J pfaqy.
%SVNE
Ai, *fx. %svne.
^
Ifnns... fi, =isp xiszne J hvffy?¶
T`A-C\E-KMNPQS-VX-Z(%[]{a-ce-kmn\pqs-vx-z}=+*&`A-Za-z

Explanation:

T`a-z`A-Z - Stage one (uppercasing input)
T`     Configuration - Transliterate;
a-z    Lowercase letters of the alphabet
`      ...into...
A-Z    Uppercase letters of the alphabet

T`A-Z`A-C\E-KMNPQS-VX-Z(%[]{ - Stage two (encoding input)
T`                             Configuration - Transliterate:
A-Z                            Uppercase letters of the alphabet
`                              ...into...
A-C\E-KMNPQS-VX-Z              All uppercase characters, excluding "WORLD"
                 (%[]{         And these characters to make up for the missing 5 characters

^(?!%SVNE$).*
Qs. Yiay jxq'y =iay J pfaqy. - Stage three (check whether input is not "world")
                               Implicit Configuration - Replace:
^(?!%SVNE$).*                  Anything except "%SVNE" (the encoded version of "WORLD") with
Qs. Yiay jxq'y =iay J pfaqy.   This line (encoded version of "No. That isn't what I meant.").

%SVNE
Ai, *fx. %svne.    - Stage four (check whether input is "world")
                     Implicit Configuration - Replace:
%SVNE                %SVNE with
Ai, *fx. %svne.      This line (the encoded version of "Ah, yes. World.")

^
Ifnns... fi, =isp xiszne J hvffy?¶ - Stage five (append message to start)
                                     Implicit Configuration - Replace:
^                                    The start with
Ifnns... fi, =isp xiszne J hvffy?¶   This line (the encoded version of ("Hello... eh, whom should I greet?"). The ¶ represents a newline

T`A-C\E-KMNPQS-VX-Z(%[]{a-ce-kmn\pqs-vx-z}=+*&`A-Za-z - Stage six (decode)
T`                                                      Configuration - Transliterate:
A-C\E-KMNPQS-VX-Z                                       All uppercase characters, excluding "WORLD"
                 (%[]{                                  And these characters to make up for the missing 5 characters
A-C\E-KMNPQS-VX-Z                                       All lowercase characters, excluding "world"
                 }=+*&                                  And these characters to make up for the missing 5 characters
`                                                       ...with...
A-Za-z                                                  All the uppercase characters followed by the lowercase characters.

Try it online!

I used this program to encode the strings, and this one to decode them.

\$\endgroup\$
0
\$\begingroup\$

C (gcc), 208 205 202 bytes

a[];main(){puts("He\x6c\x6c\x6f... eh, \x77h\x6fm sh\x6fu\x6c\x64 I g\162eet?");gets(a);puts((*a|'    ')^1819438967|(a[1]|32)^100?"N\x6f. That isn't \x77hat I meant.":"Ah, yes. \x57\x6f\x72\x6c\x64.");}

Try it online!

Apparently you don't even have to specify an array length. Ungolfed:

int a[];                  // Array of ints. Hint: ints are 4 characters wide.

main(){
    puts("Hello... eh, whom should I greet?");
    gets(a);              // Read input line.
    puts(
        (*a | '    ')     // Tolower() the first four characters
            ^ 1819438967  // Compare to "worl", non-zero if not the same
        | (a[1] | 32)     // Tolower() the fifth character
            ^ 100         // Compare to "d\0\0\0", non-zero if not the same
        ?                 // If non-zero bits present, it wasn't "world".
            "No. That isn't what I meant."
        :                 // Otherwise, we have a match.
            "Ah, yes. World.");
}

Thanks to @ceilingcat for shaving off 3 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ @ceilingcat That's fantastic, I didn't know multi-character character literals would actually work as expected! It's too bad that 'lrow' is odd, otherwise I could probably have created another four-character literal that doesn't contain those letters but that I could multiply by 2. \$\endgroup\$
    – G. Sliepen
    Commented Sep 7, 2019 at 8:44
0
\$\begingroup\$

Python 3.7, 239 267 260 258 bytes

a,b,c,e,f,g='\u0057','\u0077','\u006f','\u0072','\u006c','\u0064'
exec(f'p=p{e}int;p("He{f}{f}{c}... eh, {b}h{c}m sh{c}u{f}{g} I g{e}eet?");p("Ah, yes. {a}{c}{e}{f}{g}."if input().{f}{c}{b}e{e}()=="{b}{c}{e}{f}{g}"e{f}se"N{c}. That isn\'t {b}hat I meant.")')

Try it online!

I had to write exec because I had to write p\u0072int instead of print, e\u006Cse instead of else and \u006C\u006F\u0077e\u0072 instead of lower.

\$\endgroup\$
5
  • \$\begingroup\$ Your code isn't case insensitive. \$\endgroup\$
    – G. Sliepen
    Commented Aug 31, 2019 at 22:00
  • \$\begingroup\$ @G.Sliepen oh i misunderstood the question then lol, ill edit it \$\endgroup\$ Commented Aug 31, 2019 at 22:53
  • \$\begingroup\$ Your code contains the letter r in the print I'm afraid. \$\endgroup\$ Commented Sep 2, 2019 at 11:39
  • \$\begingroup\$ @KevinCruijssen wow, how did i miss that lmao \$\endgroup\$ Commented Sep 20, 2019 at 21:10
  • \$\begingroup\$ 232 bytes. \$\endgroup\$
    – Chris
    Commented Sep 29, 2020 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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