# Emanresu numbers

My userid is 100664. In binary this is 11000100100111000.

An interesting property of this number is that it can be created entirely by concatenating strings which are repeated at least twice:

11  000  100100  111  000


The first few such numbers are $$\3,7,10,12,15,24,28,31,36,40,42, 43, 45,48,51,53,54,56,58,60,63,80,87,96,99,103,112,115,117,120,122,124,127\$$ (let me know if I've missed any as I worked these out by hand).

Your challenge is to calculate these. (Leading zeros don't count, e.g. 9 = 001001 is not part of the sequence.)

As with all challenges, you may either:

• Take a number $$\n\$$ and output the nth term
• Take a number $$\n\$$ and output the first n terms
• Take no input and output these forever

Here's a reference implementation courtesy of Bubbler

# Scoring

This is , shortest wins!

# Testcases

These are 0-indexed.

0 => 3
1 => 7
3 => 12
5 => 24
10 => 42
15 => 53
20 => 63
25 => 103

• looks like 54((110110)), 58((11)(1010)) are missing. Aug 10, 2021 at 10:58
• you realise that now you can never change your username again right?
– Jo King
Aug 10, 2021 at 13:33
• @Razetime Thanks! Aug 10, 2021 at 19:27
• @JoKing No, I can just rename the question Aug 10, 2021 at 19:27
• @LevelRiverSt 1001 cannot be formed by concatenating strings repeated twice or more (i.e. does not match the regex ^((.+)\2+)+$). 11 is not 1 1, but just 11 which contains one string that has 1 repeated twice. Aug 12, 2021 at 0:49 ## 14 Answers # Jelly, 12 11 bytes BŒṖŒɠṂ’ƊƇµ#  A full program that accepts a positive integer, $$\n\$$, from STDIN and prints a list of the first $$\n\$$ emanresu numbers. Try it online! ### How? BŒṖŒɠṂ’ƊƇµ# - Main Link: no arguments # - start with k=0 and count up, collecting the first n (from STDIN) k which are truthy under: µ - the monadic chain, f(k): B - convert (k) to binary ŒṖ - all partitions (of the binary representation of k) Ƈ - filter - keep those (partitions) which are truthy under: Ɗ - last three links as a monad, f(partition): Œɠ - run-lengths of equal elements (e.g. 101,101,1,1,1,0 -> 2,3,1) Ṃ - minimum ’ - decrement (vectorises) -> 0 is falsey, other numbers are truthy (a result of f(k) which is non-empty is truthy)  # Python 3, 78 71 bytes -7 thanks to m90, wasif, and ovs import re i=1 while[re.match('..((.+)\\2+)+$',bin(i))and print(i)]:i+=1


Try it online!

I feel like manually setting the index isn't optimal but idk how to avoid it in this situation.

Further optimizations:

Since bin(i) always prepends 0b to our string, and match always checks from the start, we can remove the slicing from [2:] and instead embed that in the regex.

By combining the match statement with an and for the print, it short circuits and only prints i if re.match returns something other than None.

And by wrapping the and statement in a list, it forces it to always be evaluated as true in our while condition.

• Improvements: You can remove the slicing and put the 0b in the regexp. The ^ can be removed since re.match only starts at the beginning of the string.
– m90
Aug 10, 2021 at 11:27
• 72 bytes (one from m90) Aug 10, 2021 at 11:43
• 71 bytes (based on wasif's suggestion)
– ovs
Aug 10, 2021 at 16:00
• I've added all your suggestions, really smart optimizations there. Aug 10, 2021 at 20:48
• @Jakque that doesn't seem to produce the same output, for example it misses 31. I'm not sure exactly what causes that, but I'd assume its overreplacing things. Aug 12, 2021 at 18:00

# Retina, 56 bytes

{Td10.1*$^0*$
1$& /^((.+)\2+)+$/&*\(1
01
+10
011
1


Try it online! Link is to verbose version of code. Outputs the infinite sequence. Explanation:

{


Repeat forever.

Td10.1*$ Increment the current binary value. ^0*$
1$&  If it overflows, carry the 1. /^((.+)\2+)+$/&


Is this an Emanresu number?

*\(


If so then print the result of the rest of the program but then restore the current binary value.

1
01
+10
011
1


Convert from binary to decimal.

# Brachylog, 13 bytes

ℕ≜{ḃ~cḅ∋₁ᵐ&!}


Try it online!

Generates numbers infinitely.

ℕ≜               Choose a nonnegative integer.
ḃ             Its binary representation
~c           can be partitioned such that
ḃ          if runs of equal partitions are grouped,
ᵐ       each group
∋₁        has a second element.
{       & }    Output that integer
!     once.


I had hoped to use j here, but it can't even get close.

for(n=1;;n++)/^((.+)\2+)+$/.test(n.toString(2))&&console.log(n)  Try it online! • Nice! v8 has print, so you can save a lot with that. Aug 10, 2021 at 10:35 # Perl 5, 45 bytes /^((.+)\2+)+$/&&say$.while$_=sprintf"%b",++$.  Try it online! # Jelly, 17 15 bytes Saved 2 bytes thanks to @Dudecoinheringaahing Takes an integer $$\n\$$ from STDIN and generates the first $$\n\$$ terms. This is probably twice as long as it should be... BŒṖ‘ḄŒɠ€ỊẸ€ẠṆø#  Try it online! • Oh no, Arnauld has started writing Jelly. Soon there will be no hiding from this golfing madman. (Cool stuff, nice to see you expanding your repertoire. Sorry, I don't have any useful feedback since I don't know Jelly.) Aug 10, 2021 at 16:06 • @Etheryte Well, I wrote my first Jelly answer almost exactly 4 years ago. But I haven't written many of them since then, that's for sure. :-p Aug 10, 2021 at 16:14 • I would've suggested ŒrṪ€€ $\to$ Œɠ€, but it looks like Jonathan might have beat me to it Aug 10, 2021 at 16:43 • @Dudecoinheringaahing Thanks anyway! (Will update later.) Aug 10, 2021 at 17:07 # Stax, 16 12 bytes ï├1mìsM0°ö≈  Run and debug it Prints the sequence forever. -4 bytes using the partitioning idea. # Japt, 20 bytes Outputs the first n terms. It's really annoying me that the RegEx takes up nearly ¾ of this solution but I can't seem to come up with a shorter, non-RegEx based one :\ È¤è"^((.+)%2+)+$"}jU


Try it

È¤è"^((.+)%2+)+$"}jU :Implicit input of integer U È :Function taking an integer as argument ¤ : To binary string è : Count "^((.+)%2+)+$"        :    RegEx /^((.+)\2+)+$/ } :End function jU :Get the first U integers that return a truthy value  # R, 85 81 bytes while(T<-T+1)grepl("^((.+)\\2+)+$",Reduce(paste0,T%/%2^(0:log2(T))%%2))&&print(T)


Try it online!

A regex-based solution. Prints values indefinitely.

Thanks to @pajonk for saving 4 bytes!

• Try it online! → "The permalink could not be decoded" Aug 11, 2021 at 19:00
• @KjetilS. Sorry truncated the link. Fixed now Aug 11, 2021 at 19:15
• Damn, too late. I have 82: Try it online! Aug 11, 2021 at 19:22
• @pajonk are you happy for me to use your Reduce? I can get 81 provided the print output from R is allowed. Aug 11, 2021 at 19:24
• Combined makes 81: Try it online! Aug 11, 2021 at 19:25

# 05AB1E, 16 bytes

∞ʒb.œ2ìεγ€g2@P}à


Outputs the infinite sequence.

Try it online.

Explanation:

∞              # Push an infinite list of positive integers: [1,2,3,...]
ʒ             # Filter this list by:
b            #  Convert the current integer to binary
.œ          #  Get all partitions of this binary string
2ì        #  Prepend a 2 before each part (this is necessary because γ will
#  ignore leading 0s, and thus incorrectly group "1" and "01" together)
ε       #  Map each partition to:
γ      #   Group adjacent equivalent elements together
€g    #   Get the length of each group
2@  #   Check for each length if it's >= 2
P #   Check if all are truthy (by taking the product)
}à      #  After the map: check if any partition is truthy (by taking the max)
# (after which the filtered list is output implicitly as result)


# Vyxalr, 23 bytes

λbvS∑^((.+)\\2+)+$r;ȯ  Try it Online! A juicy port of JavaScript. Man I do love me some regex in golfing languages. Takes n and outputs the first n terms. • Someone should invent a compressed regex golfing language Aug 10, 2021 at 10:52 • Retinaaaaaaaaaaaaaaaaa Aug 10, 2021 at 10:52 • @Razetime Retina sucks at sequence challenges though, since it has no repeat-until loops. – Neil Aug 10, 2021 at 12:27 # Vyxal, 12 bytes ≬bøṖ'ĠvLg‹;ȯ  Try it Online! Port of Jelly. ## How? ≬bøṖ'ĠvLg‹;ȯ ≬ # Next three elements as a lambda: b # Binary øṖ # Partitions ' # Filter Ġ # Group consecutive identical items vL # Length of each g # Minimum ‹ # Decrement ; # Close filter ȯ # Starting with x=0, count up and get the first input elements where f(x) is truth (where f is the lambda defined above)  • 11 Jun 10 at 5:14 # Julia 1.0, 65 bytes !i=replace(bitstring(i+=1),r"((.+)\2+)"=>"")>""||println(i),!i;!1  Try it online! • 58 is missing. 58=111010. Don't know why but some of the other answers have ^ and +$` at the start and end of the regex. Aug 11, 2021 at 19:13
• good catch! I might have to add it too Aug 11, 2021 at 19:24