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 Expand a greyscale/colour hex code

Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour: A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue. A ...

1 answer  ·  posted 18h ago by trichoplax‭  ·  last activity 8h ago by trichoplax‭

Question code-golf string
#3: Post edited by user avatar trichoplax‭ · 2025-01-18T11:09:33Z (about 18 hours ago)
Add further test cases
  • Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour:
  • - A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue.
  • - A 2 digit code is greyscale. The 2 digits are used for each of red, green, and blue.
  • - A 3 digit code is shorthand for a 6 digit code with repeated digits for red, green, and blue.
  • - A 1 digit code is shorthand for a 2 digit greyscale code with the same 1 digit repeated.
  • ## Input
  • - A colour code in the format "#" followed by 1, 2, 3, or 6 hexadecimal digits.
  • - You may take input as either a string or any ordered sequence data type.
  • ## Output
  • - A colour code in the format "#" followed by 6 hexadecimal digits.
  • - The output after the "#" depends on the number of hexadecimal digits in the input as follows:
  • - Input with 1 digit: output the 1 digit 6 times.
  • - Input with 2 digits: output the 2 digit string 3 times.
  • - Input with 3 digits: output each digit twice (rather than the 3 digit string twice).
  • - Input with 6 digits: output the same 6 digits.
  • - You may output as either a string or any ordered sequence data type.
  • ## Test cases
  • Test cases are in the format `Input : Output`.
  • ```text
  • #0 : #000000
  • #2E : #2E2E2E
  • #ACF : #AACCFF
  • #012345 : #012345
  • ```
  • ## 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.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour:
  • - A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue.
  • - A 2 digit code is greyscale. The 2 digits are used for each of red, green, and blue.
  • - A 3 digit code is shorthand for a 6 digit code with repeated digits for red, green, and blue.
  • - A 1 digit code is shorthand for a 2 digit greyscale code with the same 1 digit repeated.
  • ## Input
  • - A colour code in the format "#" followed by 1, 2, 3, or 6 hexadecimal digits.
  • - You may take input as either a string or any ordered sequence data type.
  • ## Output
  • - A colour code in the format "#" followed by 6 hexadecimal digits.
  • - The output after the "#" depends on the number of hexadecimal digits in the input as follows:
  • - Input with 1 digit: output the 1 digit 6 times.
  • - Input with 2 digits: output the 2 digit string 3 times.
  • - Input with 3 digits: output each digit twice (rather than the 3 digit string twice).
  • - Input with 6 digits: output the same 6 digits.
  • - You may output as either a string or any ordered sequence data type.
  • ## Test cases
  • Test cases are in the format `Input : Output`.
  • ```text
  • #0 : #000000
  • #A : #AAAAAA
  • #2E : #2E2E2E
  • #44 : #444444
  • #ACF : #AACCFF
  • #989 : #998899
  • #777 : #777777
  • #012345 : #012345
  • #BBBBBB : #BBBBBB
  • ```
  • ## 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.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#2: Post edited by user avatar trichoplax‭ · 2025-01-18T11:02:26Z (about 18 hours ago)
Remove ambiguity
  • Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour:
  • - A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue.
  • - A 2 digit code is greyscale. The 2 digits are repeated for each of red, green, and blue.
  • - A 3 digit code is shorthand for a 6 digit code with repeated digits for red, green, and blue.
  • - A 1 digit code is shorthand for a 2 digit greyscale code with the same 1 digit repeated.
  • ## Input
  • - A colour code in the format "#" followed by 1, 2, 3, or 6 hexadecimal digits.
  • - You may take input as either a string or any ordered sequence data type.
  • ## Output
  • - A colour code in the format "#" followed by 6 hexadecimal digits.
  • - The output after the "#" depends on the number of hexadecimal digits in the input as follows:
  • - Input with 1 digit: output the 1 digit 6 times.
  • - Input with 2 digits: output the 2 digit string 3 times.
  • - Input with 3 digits: output each digit twice (rather than the 3 digit string twice).
  • - Input with 6 digits: output the same 6 digits.
  • - You may output as either a string or any ordered sequence data type.
  • ## Test cases
  • Test cases are in the format `Input : Output`.
  • ```text
  • #0 : #000000
  • #2E : #2E2E2E
  • #ACF : #AACCFF
  • #012345 : #012345
  • ```
  • ## 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.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour:
  • - A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue.
  • - A 2 digit code is greyscale. The 2 digits are used for each of red, green, and blue.
  • - A 3 digit code is shorthand for a 6 digit code with repeated digits for red, green, and blue.
  • - A 1 digit code is shorthand for a 2 digit greyscale code with the same 1 digit repeated.
  • ## Input
  • - A colour code in the format "#" followed by 1, 2, 3, or 6 hexadecimal digits.
  • - You may take input as either a string or any ordered sequence data type.
  • ## Output
  • - A colour code in the format "#" followed by 6 hexadecimal digits.
  • - The output after the "#" depends on the number of hexadecimal digits in the input as follows:
  • - Input with 1 digit: output the 1 digit 6 times.
  • - Input with 2 digits: output the 2 digit string 3 times.
  • - Input with 3 digits: output each digit twice (rather than the 3 digit string twice).
  • - Input with 6 digits: output the same 6 digits.
  • - You may output as either a string or any ordered sequence data type.
  • ## Test cases
  • Test cases are in the format `Input : Output`.
  • ```text
  • #0 : #000000
  • #2E : #2E2E2E
  • #ACF : #AACCFF
  • #012345 : #012345
  • ```
  • ## 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.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#1: Initial revision by user avatar trichoplax‭ · 2025-01-18T10:50:50Z (about 18 hours ago)
Expand a greyscale/colour hex code
Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour:
- A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue.
- A 2 digit code is greyscale. The 2 digits are repeated for each of red, green, and blue.
- A 3 digit code is shorthand for a 6 digit code with repeated digits for red, green, and blue.
- A 1 digit code is shorthand for a 2 digit greyscale code with the same 1 digit repeated.

## Input
- A colour code in the format "#" followed by 1, 2, 3, or 6 hexadecimal digits.
- You may take input as either a string or any ordered sequence data type.

## Output
- A colour code in the format "#" followed by 6 hexadecimal digits.
- The output after the "#" depends on the number of hexadecimal digits in the input as follows:
  - Input with 1 digit: output the 1 digit 6 times.
  - Input with 2 digits: output the 2 digit string 3 times.
  - Input with 3 digits: output each digit twice (rather than the 3 digit string twice).
  - Input with 6 digits: output the same 6 digits.
- You may output as either a string or any ordered sequence data type.

## Test cases
Test cases are in the format `Input : Output`.

```text
#0 : #000000
#2E : #2E2E2E
#ACF : #AACCFF
#012345 : #012345
```

## 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.


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