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

Comments on Evens or Odds - you know this one

Parent

Evens or Odds - you know this one

+7
−0

Get ready for a comparatively dry question - this is intended to be one of the "the"s of the code-golfing dictionary.

Create a program which inputs a base 10 non-negative whole number (without leading 0s) and outputs something if the number is odd or something else if the number is even.

You MUST input through STDIN unless your language doesn't have input facilities, in which case you may make a function for the purpose.

The odd and even outputs can be whatever you want, so long as the output for a specific parity will stay the same no matter what number of that parity is inputted.

One of the outputs can be absolutely nothing (0 characters) so long as the other output isn't nothing - one or both of the outputs can be printed through STDERR as long as the erroring output is constant for its parity (doesn't change depending on what numbers of a parity you feed it).

Shortest code following the rules wins.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Clarify input and output methods (2 comments)
Post
+6
−0

Python 3, 10 bytes

1 .__and__

Try it online!

Returns 1 for odd numbers and 0 for even numbers.

Two bytes shorter than the trivial lambda x:x%2 and one byte shorter than the equivalent magic function 2 .__rmod__.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Useless comment (1 comment)
Useless comment
user‭ wrote over 2 years ago

Nice! It's a pity Python can't do 1.& or even 1.__and__.