0
\$\begingroup\$

The following code is 47 characters.

print(("Ekki v","V")["COV"in input()]+"eikur!")

How can it be reduced to 46 or less?

I have even been brainstorming bitwise tricks but can not think of any way to do this. I am starting to think it is not possible to reduce this any further.

One idea I had was

print('Ekki veikur!'[4*('COV'in input()):])

but this does not correctly output the capital letter for Veikor.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ what's the problem statement? \$\endgroup\$
    – Sisyphus
    Commented May 10 at 7:48
  • 1
    \$\begingroup\$ The code outputs a specific phrase based on whether the input contains the substring "COV". Specifically: If "COV" is present, it outputs "Veikur!". Otherwise, it outputs "Ekki veikur!". The objective is to reduce the code to 46 or fewer characters while maintaining the same behavior. The original code is 47 characters long. \$\endgroup\$
    – LargeHorse
    Commented May 10 at 7:54
  • 1
    \$\begingroup\$ And this was sourced from a private problem set. I cannot say for certain wether the exact letter are relevant. \$\endgroup\$
    – LargeHorse
    Commented May 10 at 8:10
  • 1
    \$\begingroup\$ @Sisyphus I'm guessing the the COV is referring to COVID as the outputs are Icelandic for "Sick" and "Not sick". \$\endgroup\$
    – ElPedro
    Commented May 10 at 12:41
  • 5
    \$\begingroup\$ You should put all of the requirements in your question. As it is, it can be hard to tell if your code can be golfed because of various possible side effects. For example, the answer you got works if outputting to STDERR works, but we have no way of knowing if that is acceptable right now. \$\endgroup\$ Commented May 10 at 23:06

1 Answer 1

6
\$\begingroup\$

Python 3.8 (pre-release), 46 bytes

You can use exit instead of print to save 1 byte. This displays the same for me in a terminal running on Windows and displays the string in the Debug section in TIO.

exit(("Ekki v","V")["COV"in input()]+"eikur!")

Try it online!

\$\endgroup\$

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