Skip to main content
Official DSO link
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

tinylisp 2, 46 bytes

(d F(\(S(I 1))(? S(c(] I S)(F([ I S)(* I 2)))( 

Try It Online!Try It Online!

Ungolfed & commented

(def segments (lambda ; Function (S (I 1)) ; Takes two args: a string, and a number defaulting to 1 (if S ; If the string is nonempty: (cons ; Prepend (take I S) ; the first I characters of S (segments ; to the result of a recursive call on (drop I S) ; All but the first I characters of S (* I 2))) ; I times 2 nil))) ; Else, empty list 

tinylisp 2, 46 bytes

(d F(\(S(I 1))(? S(c(] I S)(F([ I S)(* I 2)))( 

Try It Online!

Ungolfed & commented

(def segments (lambda ; Function (S (I 1)) ; Takes two args: a string, and a number defaulting to 1 (if S ; If the string is nonempty: (cons ; Prepend (take I S) ; the first I characters of S (segments ; to the result of a recursive call on (drop I S) ; All but the first I characters of S (* I 2))) ; I times 2 nil))) ; Else, empty list 

tinylisp 2, 46 bytes

(d F(\(S(I 1))(? S(c(] I S)(F([ I S)(* I 2)))( 

Try It Online!

Ungolfed & commented

(def segments (lambda ; Function (S (I 1)) ; Takes two args: a string, and a number defaulting to 1 (if S ; If the string is nonempty: (cons ; Prepend (take I S) ; the first I characters of S (segments ; to the result of a recursive call on (drop I S) ; All but the first I characters of S (* I 2))) ; I times 2 nil))) ; Else, empty list 
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

tinylisp 2, 46 bytes

(d F(\(S(I 1))(? S(c(] I S)(F([ I S)(* I 2)))( 

Try It Online!

Ungolfed & commented

(def segments (lambda ; Function (S (I 1)) ; Takes two args: a string, and a number defaulting to 1 (if S ; If the string is nonempty: (cons ; Prepend (take I S) ; the first I characters of S (segments ; to the result of a recursive call on (drop I S) ; All but the first I characters of S (* I 2))) ; I times 2 nil))) ; Else, empty list