33
4
Inspired by Is it double speak?, I devised a harder challenge. Given a string, determine if the string is n-speak, for any \$n\geq 2\$.
N-speak is defined by repeating each letter \$n\$ times. With \$n = 4\$, the string Hello
is transformed to HHHHeeeelllllllloooo
. Your goal is to figure out if the input is a valid output for any n-speak transformation.
It should be noted that any sentence which is valid n-speak, for \$n = 2k\$, is also valid k-speak. Thus, the hard parts to solve will be odd values of \$n\$.
Input
A string consisting of at least 2 characters. Input could also be a list of characters. Input is case sensitive.
Output
Truthy
if the string is n-speak, falsey
otherwise.
Examples
True cases
HHeelllloo,, wwoorrlldd!!
TTTrrriiipppllleee ssspppeeeaaakkk
QQQQuuuuaaaaddddrrrruuuupppplllleeee ssssppppeeeeaaaakkkk
7777777-------ssssssspppppppeeeeeeeaaaaaaakkkkkkk
999999999
aaaabb
aaaaaaaabbbbcc
aaaaabbbbb
@@@
If you want to generate additional truthy cases, you can use this MathGolf script. Place the string within the quotation marks, and the value of \$n\$ as the input.
False cases
Hello, world!
TTTrrriiipppllleee speak
aaaaaaaaaaaaaaaab
Ddoouubbllee ssppeeaakk
aabbab
aaaabbb
a (does not need to be handled)
(empty string, does not need to be handled)
Of course, since this is code golf, get ready to trim some bytes!
Suggested test case:
aabbab
– Adám – 2019-08-12T15:22:50.063Suggested test case:
aaaabbb
– 640KB – 2019-08-12T15:37:03.457I'll add them both tomorrow, good suggestions. – maxb – 2019-08-12T21:12:48.767
4I am genuinely honoured and flattered that you have used and expanded my challenge :) – AJFaraday – 2019-08-13T09:46:14.317
@AJFaraday glad that you liked it! I enjoyed both of your challenges, which gave me the idea for this one. There might be an even harder challenge coming soon. – maxb – 2019-08-13T10:25:13.243
@maxb by all means. Although I find that relatively simple challenges often get more response. Just think to yourself "If I saw this, would I automatically start thinking about how to code it". Those are the winners :) – AJFaraday – 2019-08-13T10:29:00.403
When is someone going to post "n-speak"? ;) – dana – 2019-08-14T02:23:05.630
"It should be noted that any sentence which is valid n-speak, for n=2k, is also valid k-speak. Thus, the hard parts to solve will be odd values of n." This is an interesting claim since your examples are $n=2$ and $n=4$ which can't be reduced to odd values. – JiK – 2019-08-14T15:17:32.410
@JiK the 2nd, 4th, 5th, and 9th test cases are all odd numbered. It was mostly an observation that for every even case, a solution to the original Is is double speak? challenge would also would also be correct. – maxb – 2019-08-14T17:57:07.937