Image

Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Single letter HTML

+3
−0

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.

History

0 comment threads

8 answers

+3
−0

Python, 20 bytes

lambda _:_ in'abipq'

Same approach as the others, standard Python golf techniques.

History

0 comment threads

+2
−0

C (gcc), 31 30 bytes

#define f(a) strchr("abipq",a)

Try it online!

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.

History

0 comment threads

+1
−0

Japt, 7 bytes

Returns the input string (truthy) for valid tags and an empty string (falsey) for invalid ones. Add the flag for boolean output.

o"abipq

Try it

History

0 comment threads

+1
−0

Retina, 9 bytes

a`[abipq]

Attempt This Online!

naive regex, anchored to the entire string

History

0 comment threads

+1
−0

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)
History

0 comment threads

+1
−0

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

Try it online!

History

0 comment threads

+1
−0

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
History

0 comment threads

+1
−0

Vyxal 3, 6 bytes

"
|.„∩

Vyxal It Online!

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.

History

0 comment threads

Sign up to answer this question »