16
\$\begingroup\$

In Spanish, the word 'or' is represented as 'o', with the exception of cases where the following letter starts with 'o' or 'ho' (including accented forms like 'ó' or 'hó'). Numbers also follow this rule if they start with \$8\$ or are exactly \$11\$, because all numbers that start with \$8\$ in Spanish starts with "och", like ocho (8), ochenta (80), ochocientos (800), etc, so these words start with 'o' and the number \$11\$ in Spanish is once, which starts with 'o'. The 'H' in Spanish isn't pronounced, so the "u" is used before the words that start with "Ho" with or without accent.

Examples:

Quiero unos 3 o 4 panqueques.

Quiero unos 7 u 8 panqueques.


¿Comió 34 panqueques, Octavio o Manuel?

¿Comió 78 panqueques, Manuel u Octavio?

Task

Your task is to choose "o" or "u" depending on the string (see below), that may contain alphanumeric characters, including these characters: ÁÉÍÓÚáéíóúüÑñ (You may ignore these characters if your (programming) language doesn't support them, but instead use other characters of your choice (must be 13 characters long, including 2 characters that represent as "o", but these characters are obligatory if your language supports it)) in the shortest way, because this is . The characters of the strings can be uppercased even if they're not the first character of the string. Strings don't start with double "h" nor contain both numbers and letters. Also, if the string is a number, it's assumed to be less than 10999.

Output "o" if it meets one of the criteria below:

  • The string is a number, but it doesn't start with \$8\$, or isn't the number \$11\$

  • The string doesn't start with "o", "ó", "O" or "Ó"

  • The string doesn't start with "ho", "Ho", "hO", "HO", "hó", "Hó", "hÓ" or "HÓ" (sorry).

Output "u" if it doesn't meet a criterion above.

Testcases

alejandro => o
óleo => u
oreja => u
Hórrido => u
833 => u
8 => u
11 => u
1 => o
111 => o
6 => o
mal => o
horno => u
hOra => u
Héroe => o
Chocolate => o
WordInEnglish => o
OSO => u
Paro => o
o => u
u => o
O => u
U => o
Ho => u
Hu => o
Hueso => o
Humo => o
Húmedo => o
\$\endgroup\$
10
  • \$\begingroup\$ Did you mean to negate "The string is a number, and it starts with 8 or is exactly 11"? \$\endgroup\$
    – Aaron
    Commented Jul 10 at 19:23
  • \$\begingroup\$ @Aaron I negated, thank you for correcting me. \$\endgroup\$
    – Fmbalbuena
    Commented Jul 10 at 19:24
  • 1
    \$\begingroup\$ @LuisMendo 1) Yeah, I'm used to saying "panqueques" :-D 2) I added the explanation for that grammar rule, thank you. 3) That's my mistake, I added stress and added a testcase that starts with "o". Sorry. \$\endgroup\$
    – Fmbalbuena
    Commented Jul 10 at 22:36
  • 3
    \$\begingroup\$ Can I reduct this problem as decision-problem? \$\endgroup\$ Commented Jul 11 at 4:39
  • 2
    \$\begingroup\$ the "u" is used after the words that start with "Ho" — did you mean before? \$\endgroup\$
    – Adám
    Commented Jul 11 at 6:05

15 Answers 15

7
\$\begingroup\$

JavaScript (ES6), 35 bytes

-2 thanks to Fmbalbuena

s=>"ou"[+/^h?[oó8]|^11$/i.test(s)]

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ 35 bytes since both letters and numbers in the same string isn't allowed. \$\endgroup\$
    – Fmbalbuena
    Commented Jul 11 at 18:27
4
\$\begingroup\$

Google Sheets, 49 bytes

=if(regexmatch(A1,"(?i)^h?[oó]|^11$|^8"),"u","o")

Put the string in cell A1 and the formula in B1. Expects that the data is text strings as specified in the question (Format > Number > Plain text). Uses Arnauld's regex.

screenshot

\$\endgroup\$
1
  • \$\begingroup\$ Funny enough Excel can beat GS if it comes to regex since short. For example =IF(REGEXTEST(A1,"^h?[oó8]|^11$",1),"u","o") \$\endgroup\$
    – JvdV
    Commented 2 days ago
4
\$\begingroup\$

R, 47 bytes

\(s)`if`(grepl("^h?[oó]|^11$|^8",s,T),"u","o")

Attempt This Online!

Port of @Arnauld's JavaScript regex answer.

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

QuadR i, 24 23 bytes

−1 thanks to Fmbalbuena.

^(11$|h?[oó8]).*
.+
u
o

Try it online!

If at the very beginning (^) we find any of the following:

  • "11" followed by the end ($)
  • an optional (?) "h" followed by "o" or "ó" or "8"

then we replace it and anything that follows it (.+) with a "u".

Everything else (.+) we replace with an "o".

\$\endgroup\$
2
  • 1
    \$\begingroup\$ -1 byte (It marks "h8" as true, but this is fine because in this challenge it says: "Strings don't [...] contain both numbers and letters."). \$\endgroup\$
    – Fmbalbuena
    Commented Jul 11 at 18:52
  • \$\begingroup\$ @Fmbalbuena Thanks! \$\endgroup\$
    – Adám
    Commented 2 days ago
3
\$\begingroup\$

Retina 0.8.2, 26 bytes

Mi`^11$|^8|^h?[oó]
T`d`\ou

Try it online! Link includes test suite that removes the => [ou] suffix to allow the test cases to be used as input. Explanation: Port of @Arnauld's JavaScript answer.

Mi`^11$|^8|^h?[oó]

Count the number of occurrences of the pattern in the input.

T`d`\ou

Index that into the string ou. (o is magic in transliteration mode so it needs to be quoted to be literal. d is also magic, being a byte shorter than writing 01.)

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

05AB1E, 24 bytes

„ouIl'hæ„óoâJ8ªÅ?àI11Q~è

Try it online or verify all test cases.

Explanation:

„ou             # Push "ou"
I               # Push the input-string
 l              # Lowercase it
  'h           '# Push "h"
    æ           # Pop and push its powerset: ["","h"]
     „óo        # Push "óo"
        â       # Cartesian product to create all possible pairs:
                #  [["","ó"],["","o"],["h","ó"],["h","o"]]
         J      # Join each together: ["ó","o","hó","ho"]
          8ª    # Append 8: ["ó","o","hó","ho","8"]
            Å?  # Check for each whether the lowercased input starts with it
              à # Check if any is truthy (by leaving the maximum)
I               # Push the input-string again
 11Q            # Check whether it equals 11
~               # Check if either of the two is truthy
 è              # Use that 0 or 1 to (0-based) index into the "ou"
                # (after which the result is output implicitly)
\$\endgroup\$
2
\$\begingroup\$

Charcoal, 24 bytes

§uo∧⁻N¹¹⬤8oó⬤θ⌕↧θ⁺…hμι

Try it online! Link is to verbose version of code. Explanation:

     N                  Input as a number (zero if not)
    ⁻                   Subtract
      ¹¹                Literal integer `11`
   ∧                    Logical And
         8oó            Literal string `8oó`
        ⬤               All characters satisfy
             θ          Input string
            ⬤           All characters satisfy
                θ       Input string
               ↧        Lowercased
              ⌕         Does not start with
                     ι  Outer character
                 ⁺      Prefixed with
                   h    Literal string `h`
                  …     Extended to
                    μ   Inner index
§                       Index into
 uo                     Literal string `uo`
                        Implicitly print

Note that the version of Charcoal on TIO mistakenly counts ó as one byte but the version on ATO gets it right, or you can add the -x flag which produces an xxd style dump showing the correct number of bytes.

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

Python, 64 62 bytes

Edit: -2 bytes thanks to @xnor.

lambda s:re.match("^h?[oó]|^11$|^8",s,2)and"u"or"o"
import re

Attempt This Online!

Port of @Arnauld's JavaScript regex answer.

\$\endgroup\$
2
  • \$\begingroup\$ Looks like you can pass the IGNORECASE flag as re.match(...,s,2). \$\endgroup\$
    – xnor
    Commented Jul 11 at 16:36
  • \$\begingroup\$ @xnor thanks - I searched for something shorted than re.I, but couldn't find it. \$\endgroup\$
    – pajonk
    Commented Jul 11 at 18:14
2
\$\begingroup\$

Nibbles, 41 nibbles (20.5 bytes)

? + ? `D256 o/-.$`)$"H"$ ==$"11" "u" "o" 384fd3

Attempt This Online!

   `D256 384fd3                   # decode from base-256
                                  # to [56,79,211]
  ?                               # now get the index in this of
        o                         #   codepoint of
         /         $              #   first element of
           .$`)$                  #   input mapped to uppercase
          -     "H"               #   without any "H"s
 +                                # add this to
                    ==$"11"       #   is the input equal to "11"?
?                                 # if the answer is non-zero
                           "u"    #    output "u"
                                  # otherwise
                              "o" #    output "o"
\$\endgroup\$
1
\$\begingroup\$

Python 3.8 (pre-release), 66 bytes

lambda s:'ou'[s.strip('hH')[:1]in[*'oóOÓ']or'8'==s[:1]or'11'==s]

The list unpacking could be removed (-3 bytes) if strings matching /^[hH]*$/g could output 'u' instead of 'o'.

Try it online!

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

Bash, 49 bytes

grep -qiE '^h?[oó]|^11$|^8'<<<$1&&echo u||echo o

Attempt This Online!

use as a body of a bash function or bash script, takes input as first argument and outputs to stdout.

explanation:

grep -qiE                  <<<$1 #match on the first argument, don't output matches, case-insensitive, extended expressions
          '^h?[oó]|^11$|^8'      #the expression we know and love at this point
                                &&echo u||echo o #if match, output u, o otherwise.
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Are we allowed to use external commands? grep isn't [art of bash or linked to it in any way. \$\endgroup\$
    – terdon
    Commented 2 days ago
  • \$\begingroup\$ @terdon: bash used to be separated into 'pure bash' and 'bash+coreutils' but it is generally agreed that anything available on ATO or TIO is fair game, unless you specifically are going for pure bash. \$\endgroup\$ Commented 2 days ago
  • \$\begingroup\$ Got it, thanks. +1 then! \$\endgroup\$
    – terdon
    Commented 2 days ago
1
\$\begingroup\$

Java, 44 bytes

s->s.matches("(?i)11|(8|h?[oó]).*")?'u':'o'

Try it online.

Explanation:

s->     // Method with String parameter and character return-type
  s.matches("(?i)11|(8|h?[oó]).*")?
        //  If the String matches the full regex explained below:
    'u' //   Return 'u'
   :    //  Else:
    'o' //   Return 'o' instead

Regex explanation:

The String#matches method implicitly matches the entire String, adding a leading ^ and trailing $.

(?i)^11|(8|h?[oó]).*$
(?i)                    # Enable case-insensitive matching
    ^               $   # Match the entire string
     11                 #   It's "11"
       |                #  OR:
         8              #    It starts with an "8"
        ( |      )      #   or
           h?           #    An optional "h"
             [oó]       #    Followed by either "o" or "ó"
                  .*    #   Followed by 0 or more additional characters
\$\endgroup\$
1
\$\begingroup\$

Ruby, 41 33 bytes

->s{s=~/^h?[oó]|^11$|^8/i??u:?o}

Attempt This Online!

Thanks to almost the same syntax, the regex is gratefully copypasted from the Arnauld's answer :D

(The following comment refers to the previous 41-byte version)

What I like here, is how three question marks appear together (alas, a space cannot be removed), each one having a different role: the first one is a part of the boolean expression that checks whether a value is nil, the second one belongs to the ternary operator and the last one is a shortcut for 'o'.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ If you swap ?o and ?u then you can do away with .nil? and the parentheses, saving 7 bytes. \$\endgroup\$
    – Dingus
    Commented Jul 11 at 13:04
  • \$\begingroup\$ @Dingus ...and also the space isn't anymore necessary. Thanks! \$\endgroup\$ Commented Jul 11 at 14:19
1
\$\begingroup\$

Lexurgy, 60 bytes

r:
{{{h,H}? {o,ó,O,Ó}},\8} []*=>u/$ _
\11=>u/$ _ $
[]+=>o

Explanation

r:
{{{h,H}? {o,ó,O,Ó}},\8} []*=>u/$ _ # match /[hH]?[oóOÓ]|8/ at the start of the word, and replace it all with u
\11=>u/$ _ $                       # special case for 11
[]+=>o                             # everything else is o
\$\endgroup\$
1
\$\begingroup\$

Go, 110 bytes

import."regexp"
func f(s string)string{o:="o"
if b,_:=MatchString(`(?i)^h?[oó]|^11$|^8`,s);b{o="u"}
return o}

Attempt This Online!

Uses the case-insensitive regexp that everyone else is using.

\$\endgroup\$

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.