56
3
Unless you have a userscript that modifies the site's design (or even if so), you should have noticed that we have our site design!
So, to celebrate, let's make a program that retroactively applies this design (oversimplified, of course)!
So, the most important changes are:
- our new name is now Code Golf and Coding Challenges
- our site is no longer the default blue color and is instead a nice dark green
So, given a string, change:
PPCG
toCGCC
Programming Puzzles {non-whitespace} Code Golf
toCode Golf {same-thing} Coding Challenges
(for example,Programming Puzzles + Code Golf
,and Code Golf
, and& Code Golf
would all be changed toCode Golf + Coding Challenges
,and Coding Challenges
, and& Coding Challenges
.#abc
to#acb
(swap blue to green and vice versa - just ignore the fact that green shouldn't logically become blue but I don't want to complicate the color shifting)#abcdef
to#abefcd
(same as above)
Note that for the color swaps, you should accept any hexadecimal digit from 0-9
to a-f
. You can choose what case of hex digit to require, but it must be consistent and the same from input to output.
Your substitutions can be case-sensitive, and if not, please specify how the output works.
The substitutions should only happen when the string is surrounded by word boundaries (including the start of the #
). In other words, each of the specified substitutions should only occur if the match is at the edge of the string or is bordered by non-alphanumeric characters (on both sides).
Standard loopholes apply. This is a code-golf challenge, so the shortest code wins!
Examples
PPCG -> CGCC
Programming Puzzles or Code Golf -> Code Golf or Coding Challenges
PPCG stands for Programming Puzzles and Code Golf and its site color is #abf -> CGCC stands for Code Golf and Coding Challenges and its site color is #afb
The color #00f is much more intense than #5568ed -> The color #0f0 is much more intense than #55ed68
Programming Puzzles and No Substitution -> Programming Puzzles and No Substitution
No Substitution and Code Golf -> No Substitution and Code Golf
Programming Puzzles and no substitution Code Golf -> Programming Puzzles and no substitution Code Golf
Code Golf and Programming Puzzles -> Code Golf and Programming Puzzles
Programming Puzzles and Programming Puzzles and Code Golf -> Programming Puzzles and Code Golf and Coding Challenges
(for the last test case, it is important to note that the translated string could be translated again but the transformation must be applied exactly once)
Important Update
(Thanks @tsh)
The Programming Puzzles ... Code Golf
substitution rule can include the other rules inside of it (Programming Puzzles PPCG Code Golf
is valid). In this case, you may choose whether or not the rules are applied, but it must be deterministic. I'm not requiring that you be consistent between PPCG
and #...
because answers seem to implement the rules in my list ordering which results in inconsistencies. This is just a clarification; I believe all current answers remain valid.
3Should be apply the substitutions only if there are word boundaries around the substrings or everywhere? – Erik the Outgolfer – 2019-06-11T20:33:33.117
1@EriktheOutgolfer Good catch; should have word boundaries. I will specify that; thanks. – HyperNeutrino – 2019-06-11T20:44:39.397
Define "word boundary" for a #; regex implementations generally don't consider a # to start a word. – tomsmeding – 2019-06-11T20:59:28.907
@tomsmeding I'm just going to make it so that the substitutions have to be at the edge of the string or have non-alnum around it – HyperNeutrino – 2019-06-11T21:00:40.060
Got test cases? – Value Ink – 2019-06-11T21:07:34.473
@ValueInk added some, thanks – HyperNeutrino – 2019-06-11T21:09:58.397
May one keyword appear multiple times in a testcase? May some testcases doesn't contain any of these words? If so, I would suggest that include at least one of such thing. – tsh – 2019-06-12T02:01:13.367
Is
Programming Puzzles #123 Code Golf
,Programming Puzzles PPCG Code Golf
valid testcases? What is expected to be outputed? – tsh – 2019-06-12T02:07:08.803@tsh I never thought about that, good catch. Since the answers are inconsistent between the two, I'm going to say that you can choose whether or not the joiner for
Programming Puzzles ... Code Golf
gets modified. Thanks. – HyperNeutrino – 2019-06-12T02:15:14.803@Veskah Will add, thanks. – HyperNeutrino – 2019-06-12T12:19:26.510
1Oh, I guess
Programming Puzzles and no substitution Code Golf
might also catch someone (even though everyone's using the same valid regex) – Veskah – 2019-06-12T12:27:22.000@Veskah That's a good one too, though I don't think that would happen (
\S
is a bit too easy to screw up :P). I'll add it anyway – HyperNeutrino – 2019-06-12T12:40:15.3371Suggested test cases
Code Golf and Programming Puzzles
andProgramming Puzzles and Programming Puzzles and Code Golf
. @Veskah Hmm, and I think that last suggested test case fails in my 05AB1E answer, since I don't have regex.. >.< Back to the drawing board.. – Kevin Cruijssen – 2019-06-12T12:40:38.343@KevinCruijssen Added, thanks – HyperNeutrino – 2019-06-12T12:47:29.760
Suggested test case:
color-#00f-
(not surrounded by whitespace). Also,\b
in regexes is usuallyA-Za-z0-9_
, so do we need to include the_
as well (since you mention non-alphanumeric, I could interpret this as not; which would invalid almost all answers). Or is either with or without fine? – Kevin Cruijssen – 2019-06-13T10:55:54.960I didn't think it would happen during my lifetime. – coredump – 2019-06-14T07:31:23.473
@coredump lol... I mean, it only took 4-6 weeks ;) – HyperNeutrino – 2019-06-14T11:17:27.573