Post History
Sandbox
Mediocre pop count [FINALIZED]
#6: Post edited
Mediocre pop count
- Mediocre pop count [FINALIZED]
- 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"
- # Now posted: [Mediocre pop count](https://codegolf.codidact.com/posts/287199)
- ---
- 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"
#5: Post edited
- 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), and 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"
- 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"
#4: Post edited
- 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- - 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), and 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"
- 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), and 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"
#3: Post edited
- 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 zero or more letters- - 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), and 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 in answers 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"
- 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
- - 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), and 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"
#2: Post edited
- 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 1s 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 zero or more letters
- - 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), and 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 in answers 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"
- 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 zero or more letters
- - 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), and 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 in answers 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"
#1: Initial revision
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 1s 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 zero or more letters - 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), and 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 in answers 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"