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

Post History

60%
+1 −0
Challenges How many odd digits?

Given a positive integer, count its odd digits. Input An integer from 1 to 999,999,999, inclusive, in any of the following formats: A number (such as an integer or floating point number), li...

6 answers  ·  posted 4mo ago by trichoplax‭  ·  last activity 2mo ago by Shaggy‭

Question code-golf number
#2: Post edited by user avatar trichoplax‭ · 2024-08-28T01:05:33Z (4 months ago)
Make input format more flexible
  • Given a positive integer, count its odd digits.
  • ## Input
  • - An integer from 1 to 999,999,999, inclusive.
  • ## Output
  • - The number of odd digits in the input.
  • ## Test cases
  • Test cases are in the format `input : output`.
  • ```text
  • 1 : 1
  • 2 : 0
  • 3 : 1
  • 4 : 0
  • 5 : 1
  • 6 : 0
  • 7 : 1
  • 8 : 0
  • 9 : 1
  • 10 : 1
  • 11 : 2
  • 12 : 1
  • 13 : 2
  • 14 : 1
  • 15 : 2
  • 16 : 1
  • 17 : 2
  • 18 : 1
  • 19 : 2
  • 20 : 0
  • 111111111 : 9
  • 222222222 : 0
  • 123456789 : 5
  • 999999999 : 9
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • Given a positive integer, count its odd digits.
  • ## Input
  • - An integer from 1 to 999,999,999, inclusive, in any of the following formats:
  • - A number (such as an integer or floating point number), like `123`.
  • - A string, like `"123"`.
  • - A sequence of characters (such as an array or list), like `['1', '2', '3']`.
  • - A sequence of single digit numbers, like `[1, 2, 3]`.
  • ## Output
  • - The number of odd digits in the input.
  • ## Test cases
  • Test cases are in the format `input : output`.
  • ```text
  • 1 : 1
  • 2 : 0
  • 3 : 1
  • 4 : 0
  • 5 : 1
  • 6 : 0
  • 7 : 1
  • 8 : 0
  • 9 : 1
  • 10 : 1
  • 11 : 2
  • 12 : 1
  • 13 : 2
  • 14 : 1
  • 15 : 2
  • 16 : 1
  • 17 : 2
  • 18 : 1
  • 19 : 2
  • 20 : 0
  • 111111111 : 9
  • 222222222 : 0
  • 123456789 : 5
  • 999999999 : 9
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#1: Initial revision by user avatar trichoplax‭ · 2024-08-26T22:41:23Z (4 months ago)
How many odd digits?
Given a positive integer, count its odd digits.

## Input
- An integer from 1 to 999,999,999, inclusive.

## Output
- The number of odd digits in the input.

## Test cases
Test cases are in the format `input : output`.

```text
1 : 1
2 : 0
3 : 1
4 : 0
5 : 1
6 : 0
7 : 1
8 : 0
9 : 1
10 : 1
11 : 2
12 : 1
13 : 2
14 : 1
15 : 2
16 : 1
17 : 2
18 : 1
19 : 2
20 : 0
111111111 : 9
222222222 : 0
123456789 : 5
999999999 : 9
```

## Scoring
This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.

> Explanations are optional, but I'm more likely to upvote answers that have one.


[code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"