Golf to find Boring numbers

If an integer has a digit/sequence of digits in it which repeats continuously (You will understand why I said "continuously") 5 or more times, we call It "Boring".

For example, 11111 is Boring, whereas 12345 is not.

Instructions

Take an Integer as Input

Output a truthy value if the integer is boring, and a falsey value if the integer is not boring.

Example

11111=>true or 1 (1 repeats 5 times)

12345=>false or 0

1112111=>false or 0

4242424242=>true or 1 (42 repeats 5 times)

-11111=>true or 1

3452514263534543543543543543876514264527473275=>true or 1 (543 repeats 5 times)

If you use other types of "truth" and "false", specify it.

Rules

Basic rules apply.

Good luck!

• Is 1112111 boring? – Leaky Nun Jul 7 '16 at 11:33
• Is 4242424242 boring? – Fatalize Jul 7 '16 at 11:33
• 4242424242 is boring.1112111 is not. – user54200 Jul 7 '16 at 11:33
• I guess today is the day of numbers no one likes. :) – Seims Jul 7 '16 at 11:39
• Strictly speaking, all numbers are boring, as they all can be written with an arbitrary number of leading zeros. :-) – celtschk Jul 7 '16 at 14:51

05AB1E, 8 bytes

Code:

Œv¹y5×åO


Explanation:

Œ         # Compute all substrings from the input.
v        # For each substring.
y5×    # Repeat the substring 5 times (42 × 5 = 4242424242).
¹   å   # Check if it's in the input string.
O  # Sum up the result. Non-boring numbers should give 0.


Truthy is non-zero and falsy is zero. Uses the CP-1252 encoding.

Try it online!

• Nice use combining Œ with ×. – Emigna Jul 7 '16 at 12:08
• @Adnan Nice Work! c= – user54200 Jul 7 '16 at 14:47
• 5 bytes (although I realize that wasn't possible yet when you've posted your answer mid-2016). – Kevin Cruijssen Oct 27 '20 at 9:24

Retina, 9 bytes

(.+)\1{4}


Verify all testcases! (slightly modified to run all testcases at once.)

• Wait, People are doing It THIS fast? – user54200 Jul 7 '16 at 11:37
• I was way too slow to post this. Knew Retina would love this challenge :) – Emigna Jul 7 '16 at 11:39
• @Emigna sorry xd – Leaky Nun Jul 7 '16 at 11:39
• @LuisMendo Doesn't that match any 5+ anything regardless if they're the same or not? For example it would match 12345 – Emigna Jul 7 '16 at 12:06
• @LuisMendo (.+){5} expands to (.+)(.+)(.+)(.+)(.+) while (.+)\1{4} expands to (.+)\1\1\1\1. – Leaky Nun Jul 7 '16 at 12:29

Java 8, 52 bytes

s->s.matches(".*(.+)\\1{4}.*")


Outgolfed this Java 8 answer with a direct String#matches.

Explanation:

Try it here.

s->              // Method with String parameter and boolean return-type
s.matches(     //  Return whether the entire String matches the following regex:
".*          //   0 or more leading characters
(.+)\\1{4}  //   group of 1 or more characters, repeated 5 times
.*")        //   0 or more trailing characters


Java 8, 73 66 bytes:

L->java.util.regex.Pattern.compile("(.+)\\1{4}").matcher(L).find();


Hooray for Java 8 lambdas! Returns true if match is found and false otherwise.

Try It Online! (Ideone)

Lua, 35 Bytes

Well, I don't see how to do better with Lua's patterns! Takes a command-line argument as input and output nil for falsy cases, and the number repeated when truthy.

print((...):match("(%d+)%1%1%1%1"))


JavaScript, 16 bytes

In node.js (60 bytes)

process.stdin.on('data',t=>console.log(/(.+)\1{4}/.test(t)))


Wasting a ton of bytes on input/output.

JavaScript ES6 (33 bytes)

alert(/(.+)\1{4}/.test(prompt()))


Again wasting bytes on input/output.

Preferably, as an anonymous function (22 bytes)

n=>/(.+)\1{4}/.test(n)


Or even shorter (16 bytes)

/(.+)\1{4}/.test


Thanks @BusinessCat for pointing out my mistakes.

• You can use /(.+)\1{4}/.test(n) instead of match which saves a few bytes. Also it doesn't look like this will actually output anything. – Business Cat Jul 7 '16 at 13:14
• @BusinessCat You're absolutely right, I guess I missed that in the question. Thanks for the suggestion. – charredgrass Jul 7 '16 at 13:18
• You needn't take standard input, you could use function arguments – cat Jul 7 '16 at 13:28
• Uncaught TypeError: Method RegExp.prototype.test called on incompatible receiver undefined. I'm not sure if that technically counts as a correct answer, wouldn't it need to be something like /./.test.bind(/(.+)\1{4}/)? – Patrick Roberts Jul 7 '16 at 17:50
• The question states that "any number repeated 5 or more times" is Boring. – Toothbrush Jul 8 '16 at 18:04

Python 3.5, 49 43 bytes:

(-6 bytes thanks to tips from Martin Ender!)

import re;lambda u:re.search(r'(.+)\1{4}',u)


Uses a Regular Expression to match all repeating sequences of characters as long as they repeat continuously 5 or more times. Returns an re match object (such as <_sre.SRE_Match object; span=(0, 10), match='4242424242'>) if a match is found as a truthy value, and nothing or None as a falsey value.

Try It Online! (Ideone)

• Ah, the almighty regex. – user54200 Jul 7 '16 at 11:57
• Replace {4,} by {4}? – Leaky Nun Jul 7 '16 at 12:38
• @LeakyNun Yeah, that also works. – R. Kap Jul 7 '16 at 12:41
• What's the \1 do after the regex group? – speedplane Jul 8 '16 at 11:55
• @speedplane Matches any subsequent occurrences of the match from the group. – R. Kap Jul 8 '16 at 17:11

Perl, 17 15 bytes

$_=/(.+)\1{4}/  + the p flag. (run with perl -pe '$_=/(.+)\1{4}/')

Thanks to Dom Hasting for the (.+) instead of (\d+).

Explanations if needed : (.+) will match any part of the number, and \1{4}$ searches if it is repeated 4 times consecutives. • Good one, but there are better golfers out there. Its still good though. – user54200 Jul 7 '16 at 11:48 • I'm not sure Perl can do better than that... And I still wanted to submit a Perl solution, so here it is. – Dada Jul 7 '16 at 11:50 • Can you add an explanation? – user54200 Jul 7 '16 at 11:58 • I think you might need $_=/(\d+)\1{4}/ instead as 111112 is boring but this won't catch it. You might even be able to use /./ as per the Retina answer. – Dom Hastings Jul 7 '16 at 11:58
• Yup you're right, I was tring to match a "very boring number" when only boring ones were enough – Dada Jul 7 '16 at 12:38

Husk, 13 11 bytes

§ṁ€ȯm*5tQda


Try it online!

similar to 05AB1E.

-2 bytes from Dominic Van Essen and Jo King.

• ...and you can use ȯ to get 11 bytes... – Dominic van Essen Oct 27 '20 at 8:56
• @DominicvanEssen @JoKing Thanks for the help. Also, Q instead of Ṗ would be more accurate I think. – Razetime Oct 27 '20 at 9:23

SABDT, 41 bytes

White Space-less:

if($.r("(.+)\1{4})"=""){pr"0";}el{pr"1";}  Prettified: if($.r( "(.+)\1{4}" ) = "" ){
pr "0";
} el {
pr "1";
}


Answer brought to you partly by the brilliant person who came up the regex "(.+)\1{4}"

C# - 93 38 bytes

s=>new Regex(@"(.+)\1{4}").IsMatch(s);


Takes a string, returns an integer.

Thanks to aloisdg for saving a lot of bytes!

• You can take the argument as a string though, which should save you some bytes. – Leaky Nun Jul 7 '16 at 11:38
• Wouldn't @"(.+)\1{4}" work as the regex as well? Does in my C# environment at least. – Emigna Jul 7 '16 at 12:30
• You can use a lambda. It is allowed. s=>Syst... – aloisdg Jul 7 '16 at 12:56
• @Emigna - it would definitely work regardless of the C# environment. Anything with >5 consecutive characters will also work for exactly 5 consecutive characters. – charredgrass Jul 7 '16 at 13:04
• Also, I think that we should be able to write s=>new Regex(@"(.+)\1{4}").IsMatch(s); Because we stay in .NET (which his our stdlib) and we never count for using System.Linq; or using System.Collections.Generic. – aloisdg Jul 7 '16 at 13:26

Pyth, 9 8 bytes

1 byte thanks to Maltysen.

sm}*5dQ.:
f}*5TQ.:


Truthy value is a non-empty array.

Falsey value is [] (empty array).

Test suite.

f}*5TQ.:   input as a string stored in Q
f}*5TQ.:Q  implicit arguments
Q  input
.:   all substrings of.
f   T      filter for this condition, keep those returning true:
*5           repeat five times
}   Q         in Q? (True/False)

• get 8 bytes by replacing m with f and taking out the sum. – Maltysen Jul 7 '16 at 13:36

Mathematica, 4640 36 bytes

b=a__;StringContainsQ[b~~b~~b~~b~~b]


Function. Takes a string as input and outputs True or False. Tests strings against the expression a__~~a__~~a__~~a__~~a__, which represents the same character sequence repeated 5 times. For reference, the shortest solution using a regex is 45 bytes long:

StringContainsQ@RegularExpression@"(.+)\1{4}"


curse you RegularExpression!

• Nice use of pattern matching. – miles Jul 7 '16 at 23:01

PHP, 37 33 bytes

thanks to NoOneIsHere, I forgot about <?=

program for PHP<5.4, prints 1 for boring numbers, 0 else

<?=preg_match('/(.+)\1{4}/U',$n);  usage: • set register_globals=1 in php.ini for php-cgi then call php-cgi <filename> n=<number>;echo"" • for PHP>=5.4, replace $n with $_GET[n] non-regexp solution, 152 147 140 bytes <?for($e=$n+1;--$e;)for($f=$e;$f--;)for($a=str_split(substr($n,$f),$e),$k=$c='';strlen($v=array_pop($a));)$c-$v?$k=0&$c=$v:($k++<3?:die(1));  • returns exit code 1 for boring numbers, 0 else replace die(1) with die(print 1) and append echo 0; to print instead • same usage as above, but also set short_open_tags=1 if disabled • The outer loop got an unreasonable start value in the golfing, replace $n+1 with ceil(strlen($n)/5)+1 or at least with strlen($n) for testing or it may loop like forever.
• <?=preg_match... is a few chars shorter – NoOneIsHere Jul 7 '16 at 16:43

It would be 63 if there were no import statement.

import Data.List
f x=or$tail[isInfixOf(concat$replicate 5 b)x|b<-subsequences x]


Usage

f "11111211"
f "11111"
f "12345"
f "1112111"
f "4242424242"
f "-11111"
f "3452514263534543543543543543876514264527473275"


By the way, consecutive makes more sense to me than continuously.

(Sorry, I can't comment yet.)

• I hope My upvote helped making yourself able to comment. – user54200 Jul 8 '16 at 13:44

CJam, 22 bytes

q:T,{)Tew{5*T\#)}/}%:+


Try it online!

Takes sum of 1-indexed positions of all possible repeated substrings in the input. Returns 0 if interesting, anything non-zero if boring.

Japt, 7 bytes

øUã mp5


Try it (includes all test cases)

øUã mp5     :Implicit input of string U
ø           :Does U contain any element of
Uã         :  Substrings of U
m       :  Map
p5     :    Repeat 5 times


Python 3 without regex, 66 bytes

lambda s:any(s[j:i]*5in s for i in range(len(s))for j in range(i))


Try it online!

MATLAB, 26 or 13 bytes

s=int2str(i);all(s==s(1))


this takes an integer variable 'i'. A string is just the last part:

all(s==s(1))


I have counted the newline as a character.

• You need to specify the input, eg. take it with i=input('') or make the whole thing a function (eg. @(i)...). BTW, I dond think it would be too much stretch to take the integer as a string already. PS I think it fails for the last test case and also simple 211111. – pajonk Jul 7 '16 at 14:20
• Whoever edited the question: Don't do that. If the OP hasn't responded after a while (e.g. tomorrow), then you can try to edit. Also, it needs to be deleted, not kept as non-competing. – Rɪᴋᴇʀ Jul 7 '16 at 14:56

TSQL, 151 bytes

Golfed:

DECLARE @t varchar(99)='11111'

,@z bit=0,@a INT=1,@ INT=1WHILE @a<LEN(@t)SELECT @z=IIF(@t LIKE'%'+replicate(SUBSTRING(@t,@a,@),5)+'%',1,@z),@=IIF(@=20,1,@+1),@a+=IIF(@=1,1,0)PRINT @z


Ungolfed:

DECLARE @t varchar(99)='11111'

,@z bit=0,
@a INT=1,
@ INT=1
WHILE @a<LEN(@t)
SELECT
@z=IIF(@t LIKE'%'+replicate(SUBSTRING(@t,@a,@),5)+'%',1,@z),
@=IIF(@=20,1,@+1),
@a+=IIF(@=1,1,0)

PRINT @z


Fiddle

PowerShell, 26 bytes

\$args[0]-match"(.+)\1{4}"


I'm by no means a regex master, so credit to the other answers for that.

Clojure, 24 bytes

#(re-find #"(.+)\1{4}"%)


Uses clojure's falsey values of nil/false and truthy values for everything else. Specifically, nil when no match is found for false, and an array [] for true when a match is found like for 11111 then ["11111" "1"] is true.

JS without regexes, 166

b=s=>{for(let i=0;i<s.length-4;i++){for(let n=1;n<=Math.floor((s.length-i)/5);n++){if([1,2,3,4].every(k=>s.slice(i,i+n)==s.slice(i+n*k,i+n*(k+1))))return 1}}return 0}


non minified:

// test any start pos, and length
var b = s => {
for (let i = 0; i <= s.length - 5; i++) {
for (let n = 1; n <= Math.floor((s.length - i) / 5); n++) {
// test if s is boring at position i, with length n
if ([1, 2, 3, 4].every(k => s.slice(i, i + n) === s.slice(i + n * k, i + n * (k + 1)))) {
return 1;
}
}
}
return 0;
};

console.log(b('11111'));
console.log(b('12345'));
console.log(b('1112111'));
console.log(b('-11111'));
console.log(b('3452514263534543543543543543876514264527473275'));

• Hi, and welcome to PPCG! However, this can really be golfed more. You can remove just the extra whitespace for a much shorter code. Please either golf it more or delete. – Rɪᴋᴇʀ Jul 7 '16 at 22:13
• I like the idea of avoiding regex. Replace(['boring','let','false','true']['b','','0','1']; that cut 20 characters – Coomie Jul 8 '16 at 3:45