Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#J, 17 bytes

J, 17 bytes

(#@]$[,1#~<:@[)#]
  • (...) # ] everything in parens creates the string for J's built in "copy" verb. So, eg, if the left argument is 3, it creates the string 3 1 1 repeated as needed to equal the number of characters in the right arg ], which contains the string. Which is to say, # solves the problem directly, assuming we can give it the correct left argument: 4 should be 4 1 1 1 repeated, and so on.
  • Examining #@]$[,1#~<:@[, we see it uses J's shape verb $ in the middle -- that's the main verb of this phrase...
  • To the left of $ is #@], meaning the length # of the right arg ].
  • To the right of $ is [,1#~<:@[, a 5 verb train. The first train executed is...
  • 1#~<:@[, which means 1 copied #~ (passive form of copy) one less than <: the left arg [. This result is passed to the final fork:
  • [, ... meaning take the left arg, and append the result we just calculated, which is a string of 1s.

Try it online!

#J, 17 bytes

(#@]$[,1#~<:@[)#]
  • (...) # ] everything in parens creates the string for J's built in "copy" verb. So, eg, if the left argument is 3, it creates the string 3 1 1 repeated as needed to equal the number of characters in the right arg ], which contains the string. Which is to say, # solves the problem directly, assuming we can give it the correct left argument: 4 should be 4 1 1 1 repeated, and so on.
  • Examining #@]$[,1#~<:@[, we see it uses J's shape verb $ in the middle -- that's the main verb of this phrase...
  • To the left of $ is #@], meaning the length # of the right arg ].
  • To the right of $ is [,1#~<:@[, a 5 verb train. The first train executed is...
  • 1#~<:@[, which means 1 copied #~ (passive form of copy) one less than <: the left arg [. This result is passed to the final fork:
  • [, ... meaning take the left arg, and append the result we just calculated, which is a string of 1s.

Try it online!

J, 17 bytes

(#@]$[,1#~<:@[)#]
  • (...) # ] everything in parens creates the string for J's built in "copy" verb. So, eg, if the left argument is 3, it creates the string 3 1 1 repeated as needed to equal the number of characters in the right arg ], which contains the string. Which is to say, # solves the problem directly, assuming we can give it the correct left argument: 4 should be 4 1 1 1 repeated, and so on.
  • Examining #@]$[,1#~<:@[, we see it uses J's shape verb $ in the middle -- that's the main verb of this phrase...
  • To the left of $ is #@], meaning the length # of the right arg ].
  • To the right of $ is [,1#~<:@[, a 5 verb train. The first train executed is...
  • 1#~<:@[, which means 1 copied #~ (passive form of copy) one less than <: the left arg [. This result is passed to the final fork:
  • [, ... meaning take the left arg, and append the result we just calculated, which is a string of 1s.

Try it online!

added 793 characters in body
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

#J, 17 bytes

(#@]$[,1#~<:@[)#]
  • (...) # ] everything in parens creates the string for J's built in "copy" verb. So, eg, if the left argument is 3, it creates the string 3 1 1 repeated as needed to equal the number of characters in the right arg ], which contains the string. Which is to say, # solves the problem directly, assuming we can give it the correct left argument: 4 should be 4 1 1 1 repeated, and so on.
  • Examining #@]$[,1#~<:@[, we see it uses J's shape verb $ in the middle -- that's the main verb of this phrase...
  • To the left of $ is #@], meaning the length # of the right arg ].
  • To the right of $ is [,1#~<:@[, a 5 verb train. The first train executed is...
  • 1#~<:@[, which means 1 copied #~ (passive form of copy) one less than <: the left arg [. This result is passed to the final fork:
  • [, ... meaning take the left arg, and append the result we just calculated, which is a string of 1s.

Try it online!

#J, 17 bytes

(#@]$[,1#~<:@[)#]

Try it online!

#J, 17 bytes

(#@]$[,1#~<:@[)#]
  • (...) # ] everything in parens creates the string for J's built in "copy" verb. So, eg, if the left argument is 3, it creates the string 3 1 1 repeated as needed to equal the number of characters in the right arg ], which contains the string. Which is to say, # solves the problem directly, assuming we can give it the correct left argument: 4 should be 4 1 1 1 repeated, and so on.
  • Examining #@]$[,1#~<:@[, we see it uses J's shape verb $ in the middle -- that's the main verb of this phrase...
  • To the left of $ is #@], meaning the length # of the right arg ].
  • To the right of $ is [,1#~<:@[, a 5 verb train. The first train executed is...
  • 1#~<:@[, which means 1 copied #~ (passive form of copy) one less than <: the left arg [. This result is passed to the final fork:
  • [, ... meaning take the left arg, and append the result we just calculated, which is a string of 1s.

Try it online!

Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

#J, 17 bytes

(#@]$[,1#~<:@[)#]

Try it online!

AltStyle によって変換されたページ (->オリジナル) /