| Bytes | Lang | Time | Link |
|---|---|---|---|
| nan | 240808T062633Z | RARE Kpo | |
| 024 | Retina 0.8.2 | 240711T001547Z | Neil |
| 045 | R | 240711T055300Z | pajonk |
| 060 | Python | 240711T130805Z | pajonk |
| 055 | Python 3.8 prerelease | 240710T235814Z | squarero |
| 027 | AWK vIGNORECASE=1 | 240718T130032Z | corvus_1 |
| 047 | Bash | 240711T080538Z | Themooni |
| nan | Nibbles | 240712T151449Z | Dominic |
| 023 | QuadR i | 240711T062145Z | Adá |
| 035 | JavaScript ES6 | 240710T200347Z | Arnauld |
| 110 | Go | 240711T151242Z | bigyihsu |
| 060 | Lexurgy | 240711T150341Z | bigyihsu |
| 033 | Ruby | 240711T081015Z | int 21h |
| 044 | Java | 240711T082106Z | Kevin Cr |
| 024 | 05AB1E | 240711T074131Z | Kevin Cr |
| 024 | Charcoal | 240711T063055Z | Neil |
| 049 | Google Sheets | 240710T202030Z | doubleun |
even for platforms that don't support UTF-8 at all this challenge can still be safely coded up via octals
awk '$0=/^(11$|8[0-9]*|[Hh]?(O|o|\703[\223\663])[^0-9]*)/?"u":"o"'
but one can always hard-code in the UTF-8 bytes instead :
awk '$0=/^(11|8[0-9]*|[Hh]?(O|o|Ó|ó)[^0-9]*)$/?"u":"o"'
Retina 0.8.2, 26 24 bytes
Mi`^11$|^h?[8oó]
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$|^h?[8oó]
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.)
Edit: Saved 2 bytes by porting @Fmbalbuena's golf to @Arnauld's answer.
R, 45 bytes
\(s)`if`(grepl("^h?[oó8]|^11$",s,T),"u","o")
Port of @Arnauld's JavaScript regex answer.
Python, 64 62 60 bytes
Edit: -2 bytes thanks to @xnor and -2 bytes thanks to @squareroot12621.
lambda s:re.match("^h?[oó8]|^11$",s,2)and"u"or"o"
import re
Port of @Arnauld's JavaScript regex answer.
Python 3.8 (pre-release), 66 55 bytes
-11 bytes by realizing that strings like 'H8' are undefined behavior.
lambda s:'ou'[s.strip('hH')[:1]in[*'oóOÓ8']or'11'==s]
The list unpacking could be removed (-3 bytes) if strings matching /^[hH]*$/g could output 'u' instead of 'o'.
Bash, 47 bytes
-2 bytes by @Fmbalbuena with golfed regex
grep -qiE '^h?[oó8]|^11$'<<<$1&&echo u||echo o
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ó8]|^11$' #the expression we know and love at this point
&&echo u||echo o #if match, output u, o otherwise.
Nibbles, 41 nibbles (20.5 bytes)
? + ? `D256 o/-.$`)$"H"$ ==$"11" "u" "o" 384fd3
`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"
QuadR i, 24 23 bytes
−1 thanks to Fmbalbuena.
^(11$|h?[oó8]).*
.+
u
o
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".
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}
Uses the case-insensitive regexp that everyone else is using.
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
Ruby, 41 33 bytes
- -8 bytes thanks to Dingus
->s{s=~/^h?[oó]|^11$|^8/i??u:?o}
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'.
Java, 44 bytes
s->s.matches("(?i)11|(8|h?[oó]).*")?'u':'o'
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
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)
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.
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.
