22
\$\begingroup\$

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!

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

18 Answers 18

13
\$\begingroup\$

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!

\$\endgroup\$
  • 1
    \$\begingroup\$ Nice use combining Œ with ×. \$\endgroup\$ – Emigna Jul 7 '16 at 12:08
  • 1
    \$\begingroup\$ @Adnan Nice Work! c= \$\endgroup\$ – user54200 Jul 7 '16 at 14:47
23
\$\begingroup\$

Retina, 9 bytes

(.+)\1{4}

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

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

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
\$\endgroup\$
6
\$\begingroup\$

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)

\$\endgroup\$
4
\$\begingroup\$

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"))
\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Business Cat Jul 7 '16 at 13:14
  • \$\begingroup\$ @BusinessCat You're absolutely right, I guess I missed that in the question. Thanks for the suggestion. \$\endgroup\$ – charredgrass Jul 7 '16 at 13:18
  • \$\begingroup\$ You needn't take standard input, you could use function arguments \$\endgroup\$ – cat Jul 7 '16 at 13:28
  • 2
    \$\begingroup\$ 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}/)? \$\endgroup\$ – Patrick Roberts Jul 7 '16 at 17:50
  • \$\begingroup\$ The question states that "any number repeated 5 or more times" is Boring. \$\endgroup\$ – Toothbrush Jul 8 '16 at 18:04
3
\$\begingroup\$

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)

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

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.

\$\endgroup\$
  • \$\begingroup\$ Good one, but there are better golfers out there. Its still good though. \$\endgroup\$ – user54200 Jul 7 '16 at 11:48
  • 4
    \$\begingroup\$ I'm not sure Perl can do better than that... And I still wanted to submit a Perl solution, so here it is. \$\endgroup\$ – Dada Jul 7 '16 at 11:50
  • \$\begingroup\$ Can you add an explanation? \$\endgroup\$ – user54200 Jul 7 '16 at 11:58
  • \$\begingroup\$ 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. \$\endgroup\$ – Dom Hastings Jul 7 '16 at 11:58
  • 1
    \$\begingroup\$ Yup you're right, I was tring to match a "very boring number" when only boring ones were enough \$\endgroup\$ – Dada Jul 7 '16 at 12:38
1
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ You can take the argument as a string though, which should save you some bytes. \$\endgroup\$ – Leaky Nun Jul 7 '16 at 11:38
  • 1
    \$\begingroup\$ Wouldn't @"(.+)\1{4}" work as the regex as well? Does in my C# environment at least. \$\endgroup\$ – Emigna Jul 7 '16 at 12:30
  • \$\begingroup\$ You can use a lambda. It is allowed. s=>Syst... \$\endgroup\$ – aloisdg says Reinstate Monica Jul 7 '16 at 12:56
  • \$\begingroup\$ @Emigna - it would definitely work regardless of the C# environment. Anything with >5 consecutive characters will also work for exactly 5 consecutive characters. \$\endgroup\$ – charredgrass Jul 7 '16 at 13:04
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – aloisdg says Reinstate Monica Jul 7 '16 at 13:26
1
\$\begingroup\$

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)
\$\endgroup\$
  • \$\begingroup\$ get 8 bytes by replacing m with f and taking out the sum. \$\endgroup\$ – Maltysen Jul 7 '16 at 13:36
1
\$\begingroup\$

Mathematica, 46 40 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!

\$\endgroup\$
  • \$\begingroup\$ Nice use of pattern matching. \$\endgroup\$ – miles Jul 7 '16 at 23:01
1
\$\begingroup\$

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.
\$\endgroup\$
  • 1
    \$\begingroup\$ <?=preg_match... is a few chars shorter \$\endgroup\$ – NoOneIsHere Jul 7 '16 at 16:43
1
\$\begingroup\$

Haskell, 80 (63?)

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

\$\endgroup\$
  • 1
    \$\begingroup\$ I hope My upvote helped making yourself able to comment. \$\endgroup\$ – user54200 Jul 8 '16 at 13:44
0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – pajonk Jul 7 '16 at 14:20
  • \$\begingroup\$ 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. \$\endgroup\$ – Rɪᴋᴇʀ Jul 7 '16 at 14:56
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

PowerShell, 26 bytes

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

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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'));
\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Rɪᴋᴇʀ Jul 7 '16 at 22:13
  • \$\begingroup\$ I like the idea of avoiding regex. Replace(['boring','let','false','true']['b','','0','1']; that cut 20 characters \$\endgroup\$ – Coomie Jul 8 '16 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy