Skip to main content
added 41 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

MathGolf, 12 11 bytes

hâΣÆïó‼<≥;] 

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output, basically \$\log_2(length+1)\$ manually:

 # (e.g. input = "abcdefghijklmno") h # Push the length of the (implicit) input-string # → 15 â # Convert it to a binary list # → [1,1,1,1] Σ # Sum this list of 1-bits # → 4 

Step 2: Actually split the input into the power of 2 parts:

Æ # Loop in the range [0,value], # using 5 characters as inner code-block: ï # Push the current 0-based loop-index ó # Pop and convert it to 2 to the power this index ‼ # Apply the next two operators separately on the current stack: < # Slice to substring [0,val) ≥ # Slice to substring [val,length) ; # After the loop: discard the trailing no-op part ] # Wrap all correct parts on the stack into a list # (after which the entire stack is output implicitly as result) 

MathGolf, 12 11 bytes

hâΣÆïó‼<≥;] 

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output:

 # (e.g. input = "abcdefghijklmno") h # Push the length of the (implicit) input-string # → 15 â # Convert it to a binary list # → [1,1,1,1] Σ # Sum this list of 1-bits # → 4 

Step 2: Actually split the input into the power of 2 parts:

Æ # Loop in the range [0,value], # using 5 characters as inner code-block: ï # Push the current 0-based loop-index ó # Pop and convert it to 2 to the power this index ‼ # Apply the next two operators separately on the current stack: < # Slice to substring [0,val) ≥ # Slice to substring [val,length) ; # After the loop: discard the trailing no-op part ] # Wrap all correct parts on the stack into a list # (after which the entire stack is output implicitly as result) 

MathGolf, 12 11 bytes

hâΣÆïó‼<≥;] 

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output, basically \$\log_2(length+1)\$ manually:

 # (e.g. input = "abcdefghijklmno") h # Push the length of the (implicit) input-string # → 15 â # Convert it to a binary list # → [1,1,1,1] Σ # Sum this list of 1-bits # → 4 

Step 2: Actually split the input into the power of 2 parts:

Æ # Loop in the range [0,value], # using 5 characters as inner code-block: ï # Push the current 0-based loop-index ó # Pop and convert it to 2 to the power this index ‼ # Apply the next two operators separately on the current stack: < # Slice to substring [0,val) ≥ # Slice to substring [val,length) ; # After the loop: discard the trailing no-op part ] # Wrap all correct parts on the stack into a list # (after which the entire stack is output implicitly as result) 
deleted 70 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

MathGolf, 1212 11 bytes

h╥(âΣÆïó‼<≥]hâΣÆïó‼<≥;] 

Try it online.Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output, minus 1:

  # (e.g. input = "abcdefghijklmno") h  # Push the length of the (implicit) input-string   # → 15 ╥  # Go to the highest power of 2 below this length # → 8 (  # Decrease this by 115   # → 7 â â # Convert it to a binary list   # → [1,1,1,1] Σ Σ  # Sum this list of 1-bits   # → 34 

Step 2: Actually split the input into the power of 2 parts:

Æ  # Loop in the range [0,value],   # using 5 characters as inner code-block: ï  # Push the current 0-based loop-index ó  # Pop and convert it to 2 to the power this index ‼  # Apply the next two operators separately on the current stack: <  # Slice to substring [0,val) ≥  # Slice to substring [val,length) ];  # After the loop: wrapdiscard the trailing no-op part ]  # Wrap all valuescorrect parts on the stack into a list   # (after which the entire stack is output implicitly as result) 

MathGolf, 12 bytes

h╥(âΣÆïó‼<≥] 

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output, minus 1:

 # (e.g. input = "abcdefghijklmno") h # Push the length of the (implicit) input-string   # → 15 ╥  # Go to the highest power of 2 below this length # → 8 (  # Decrease this by 1   # → 7  â # Convert it to a binary list # → [1,1,1] Σ # Sum this list of 1-bits # → 3 

Step 2: Actually split the input into the power of 2 parts:

Æ # Loop in the range [0,value], # using 5 characters as inner code-block: ï # Push the current 0-based loop-index ó # Pop and convert it to 2 to the power this index ‼ # Apply the next two operators separately on the current stack: < # Slice to substring [0,val) ≥ # Slice to substring [val,length) ] # After the loop: wrap all values on the stack into a list # (after which the entire stack is output implicitly as result) 

MathGolf, 12 11 bytes

hâΣÆïó‼<≥;] 

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output:

  # (e.g. input = "abcdefghijklmno") h  # Push the length of the (implicit) input-string # → 15 â # Convert it to a binary list   # → [1,1,1,1] Σ   # Sum this list of 1-bits   # → 4 

Step 2: Actually split the input into the power of 2 parts:

Æ  # Loop in the range [0,value],   # using 5 characters as inner code-block: ï  # Push the current 0-based loop-index ó  # Pop and convert it to 2 to the power this index ‼  # Apply the next two operators separately on the current stack: <  # Slice to substring [0,val) ≥  # Slice to substring [val,length) ;  # After the loop: discard the trailing no-op part ]  # Wrap all correct parts on the stack into a list   # (after which the entire stack is output implicitly as result) 
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

MathGolf, 12 bytes

h╥(âΣÆïó‼<≥] 

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output, minus 1:

 # (e.g. input = "abcdefghijklmno") h # Push the length of the (implicit) input-string # → 15 ╥ # Go to the highest power of 2 below this length # → 8 ( # Decrease this by 1 # → 7 â # Convert it to a binary list # → [1,1,1] Σ # Sum this list of 1-bits # → 3 

Step 2: Actually split the input into the power of 2 parts:

Æ # Loop in the range [0,value], # using 5 characters as inner code-block: ï # Push the current 0-based loop-index ó # Pop and convert it to 2 to the power this index ‼ # Apply the next two operators separately on the current stack: < # Slice to substring [0,val) ≥ # Slice to substring [val,length) ] # After the loop: wrap all values on the stack into a list # (after which the entire stack is output implicitly as result)