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

71%
+3 −0
Challenges Mediocre pop count

Given a sequence of letters, omit those with the highest or lowest pop count. Terminology The pop count or population count of a binary string is the number of 1s in it. For this challenge, the ...

6 answers  ·  posted 2y ago by trichoplax‭  ·  last activity 2y ago by A username‭

#1: Initial revision by user avatar trichoplax‭ · 2022-10-09T19:22:44Z (about 2 years ago)
Mediocre pop count
Given a sequence of letters, omit those with the highest or lowest pop count.

## Terminology
The pop count or [population count] of a binary string is the number of `1`s in it.

For this challenge, the pop count of a letter is the number of `1`s in its ASCII character code in binary.

For example, the letter "Z" has ASCII character code 90, which is `1011010` in binary. There are 4 `1`s in this binary string, so the pop count of "Z" is 4.

Here is the pop count of every letter, in the format `letter : pop count`:

```text
A : 2
B : 2
C : 3
D : 2
E : 3
F : 3
G : 4
H : 2
I : 3
J : 3
K : 4
L : 3
M : 4
N : 4
O : 5
P : 2
Q : 3
R : 3
S : 4
T : 3
U : 4
V : 4
W : 5
X : 3
Y : 4
Z : 4
a : 3
b : 3
c : 4
d : 3
e : 4
f : 4
g : 5
h : 3
i : 4
j : 4
k : 5
l : 4
m : 5
n : 5
o : 6
p : 3
q : 4
r : 4
s : 5
t : 4
u : 5
v : 5
w : 6
x : 4
y : 5
z : 5
```
## Input
- A sequence of letters
- This may be a string or any ordered data structure of characters
- The letters may contain a mixture of upper and lower case
- The characters that count as letters for this challenge are A-Z and a-z, specifically `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
- The input may be empty (it may have length zero)

## Output
- A sequence of letters
- This may be a string or any ordered data structure of characters. It does not need to match the input format (provided it is consistent between inputs)
  - For example, you may take input as an array of characters, and output as a string, provided this does not change for different inputs
- All of the letters from the input are included in the output in the same order, except for those with the highest or lowest pop count, which are omitted
- If all of the letters have either the highest or lowest pop count, the output is empty (a sequence of length zero)
- Case must be maintained
  - a letter that is lower case in the input must be lower case in the output (if present)
  - a letter that is upper case in the input must be upper case in the output (if present)

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

```text
"" : ""
"a" : ""
"ab" : ""
"abc" : ""
"abcd" : ""
"abcde" : ""
"abcdef" : ""
"abcdefg" : "cef"
"A" : ""
"AB" : ""
"ABC" : ""
"ABCD" : ""
"ABCDE" : ""
"ABCDEF" : ""
"ABCDEFG" : "CEF"
"oAPwSoeHcoDretMBBoesoBsagHDoew" : "SecretMessage"
"SecretMessage" : "SecretMee"
```

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



[population count]: https://en.wikipedia.org/wiki/Hamming_weight "Wikipedia page for 'Hamming weight' - a generalisation of pop count"