Skip to main content
Commonmark migration
Source Link

#Retina, 36 29 bytes

Retina, 36 29 bytes

7 bytes thanks to Martin Ender.

.+ $* (?!(11+)\1*$(?<=^\1+)). 

Try it online!

Explanation

There are two stages (commands).

First stage

.+ $* 

It is a simple regex substitution, converting the input to that many ones.

For example, 5 would be converted to 11111.

Second stage

(?!(11+)\1*$(?<=^\1+)). 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.

#Retina, 36 29 bytes

7 bytes thanks to Martin Ender.

.+ $* (?!(11+)\1*$(?<=^\1+)). 

Try it online!

Explanation

There are two stages (commands).

First stage

.+ $* 

It is a simple regex substitution, converting the input to that many ones.

For example, 5 would be converted to 11111.

Second stage

(?!(11+)\1*$(?<=^\1+)). 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.

Retina, 36 29 bytes

7 bytes thanks to Martin Ender.

.+ $* (?!(11+)\1*$(?<=^\1+)). 

Try it online!

Explanation

There are two stages (commands).

First stage

.+ $* 

It is a simple regex substitution, converting the input to that many ones.

For example, 5 would be converted to 11111.

Second stage

(?!(11+)\1*$(?<=^\1+)). 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.

deleted 39 characters in body
Source Link
Leaky Nun
  • 50.6k
  • 6
  • 115
  • 291

#Retina, 3636 29 bytes

7 bytes thanks to Martin Ender.

.+ $*1:$&$*$* (?=.+:)(?!(11+)\1*:\1+$\1*$(?<=^\1+)). 

Try it online!Try it online!

Explanation

There are two stages (commands).

First stage

.+ $*1:$&$*$* 

It is a simple regex substitution, converting the input to that many ones, followed by a colon, followed by that many ones again.

For example, 5 would be converted to 11111:11111.

Second stage

(?=.+:)(?!(11+)\1*:\1+$\1*$(?<=^\1+)). 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.

#Retina, 36 bytes

.+ $*1:$&$* (?=.+:)(?!(11+)\1*:\1+$) 

Try it online!

Explanation

There are two stages (commands).

First stage

.+ $*1:$&$* 

It is a simple regex substitution, converting the input to that many ones, followed by a colon, followed by that many ones again.

For example, 5 would be converted to 11111:11111.

Second stage

(?=.+:)(?!(11+)\1*:\1+$) 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.

#Retina, 36 29 bytes

7 bytes thanks to Martin Ender.

.+ $* (?!(11+)\1*$(?<=^\1+)). 

Try it online!

Explanation

There are two stages (commands).

First stage

.+ $* 

It is a simple regex substitution, converting the input to that many ones.

For example, 5 would be converted to 11111.

Second stage

(?!(11+)\1*$(?<=^\1+)). 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.

Source Link
Leaky Nun
  • 50.6k
  • 6
  • 115
  • 291

#Retina, 36 bytes

.+ $*1:$&$* (?=.+:)(?!(11+)\1*:\1+$) 

Try it online!

Explanation

There are two stages (commands).

First stage

.+ $*1:$&$* 

It is a simple regex substitution, converting the input to that many ones, followed by a colon, followed by that many ones again.

For example, 5 would be converted to 11111:11111.

Second stage

(?=.+:)(?!(11+)\1*:\1+$) 

This regex tries to match the positions which satisfy the condition (co-prime with input), and then return the number of matches.