Single letter HTML
Indicate whether a letter is an HTML element.
Input
- A single lowercase letter.
Output
- An indication of whether the input is a standard HTML element.
- This could be one of 2 distinct values to indicate true or false, or any truthy or falsy value if your programming language supports that.
- You may choose whether truthy or falsy indicates an HTML element.
Test cases
Test cases are in the format input : output.
These are correct at time of posting, and will remain the measure of validity for answers to this challenge even if the HTML specification changes in future.
a : true
b : true
c : false
d : false
e : false
f : false
g : false
h : false
i : true
j : false
k : false
l : false
m : false
n : false
o : false
p : true
q : true
r : false
s : false
t : false
u : false
v : false
w : false
x : false
y : false
z : false
Scoring
This is a code golf challenge. Your score is the number of bytes in your code.
Explanations are optional, but I'm more likely to upvote answers that have one.
Python, 20 bytes ``` lambd …
18d ago
[C (gcc)], 31 30 bytes …
12d ago
awk, 12 bytes Print nothing …
4h ago
sed, 12 bytes Print nothing …
4h ago
Japt, 7 bytes Returns the i …
4d ago
sed, 16 bytes /[abipq]/ …
16d ago
Vyxal 3, 6 bytes ``` " |. …
17d ago
Retina, 9 bytes ``` a`[abi …
18d ago
8 answers
Python, 20 bytes
lambda _:_ in'abipq'
Same approach as the others, standard Python golf techniques.
0 comment threads
C (gcc), 31 30 bytes
#define f(a) strchr("abipq",a)
f(a){return strchr("abipq",a);}
The most obvious (and non-creative) solution. This under default rules that a truthy value in the language is anything non-zero. To display explicitly 1 or 0 would require two !! before the strchr call.
(Passing a as pointer and returning value through it gives me worse golf results.)
EDIT: function-like macros are generally less ideal than functions for golf but in this case it shaves one character.
0 comment threads
sed, 12 bytes
Print nothing if true; newline if false.
/[abipq]/d;x
- if match, delete and go to next line of input
- else swap input with empty hold space and print (gives newline)
0 comment threads
sed, 16 bytes
/[abipq]/{c
q};d
Prints a newline for true and an empty string for false.
Annotated
/[abipq]/{ # run grouped commands for lines matching [abipq]
c # change current buffer with remainder of this line (i.e. \n)
q # quit
}; # start new command
d # delete current buffer
0 comment threads
awk, 12 bytes
Print nothing if false, 1 if true
$0=/[abipq]/
- replace input with result of match
- no match: assigns false (empty string) ⇒ default print action is skipped
- match: assigns true (stringifies to
1) ⇒ default print action is run
0 comment threads
Vyxal 3, 6 bytes
"
|.„∩
Returns an empty string if the input is not a single letter element. Returns the input otherwise.
Simply perform intersection with the string "abipq". "<newline>|.„" is a base-252 compressed string.

0 comment threads