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

Golfed 1 byte
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

tinylisp, 46(削除) 46 (削除ここまで) 45 bytes

(d F(q((N)(i(l N 1)()0(c(F(s N 1))(c(F(s N 2))(

Try it online! Try it online!

A function submission that takes an integer and returns a list:

  • The empty tree is represented by the empty list ()0
  • A nonempty tree is represented by a two-element list containing its left and right subtrees

Ungolfed

Recursively implements the definition: if N is less than 1, returns the empty list;0; otherwise, constructs a list containing the results of two recursive calls, one for N-1 and one for N-2.

(load library)
(def F
 (lambda (N)
 (if (less? N 1)
 ()0
 (cons
 (F (- N 1))
 (cons
 (F (- N 2))
 ())))))

tinylisp, 46 bytes

(d F(q((N)(i(l N 1)()(c(F(s N 1))(c(F(s N 2))(

Try it online!

A function submission that takes an integer and returns a list:

  • The empty tree is represented by the empty list ()
  • A nonempty tree is represented by a two-element list containing its left and right subtrees

Ungolfed

Recursively implements the definition: if N is less than 1, returns the empty list; otherwise, constructs a list containing the results of two recursive calls, one for N-1 and one for N-2.

(load library)
(def F
 (lambda (N)
 (if (less? N 1)
 ()
 (cons
 (F (- N 1))
 (cons
 (F (- N 2))
 ())))))

tinylisp, (削除) 46 (削除ここまで) 45 bytes

(d F(q((N)(i(l N 1)0(c(F(s N 1))(c(F(s N 2))(

Try it online!

A function submission that takes an integer and returns a list:

  • The empty tree is represented by 0
  • A nonempty tree is represented by a two-element list containing its left and right subtrees

Ungolfed

Recursively implements the definition: if N is less than 1, returns 0; otherwise, constructs a list containing the results of two recursive calls, one for N-1 and one for N-2.

(load library)
(def F
 (lambda (N)
 (if (less? N 1)
 0
 (cons
 (F (- N 1))
 (cons
 (F (- N 2))
 ())))))
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

tinylisp, 46 bytes

(d F(q((N)(i(l N 1)()(c(F(s N 1))(c(F(s N 2))(

Try it online!

A function submission that takes an integer and returns a list:

  • The empty tree is represented by the empty list ()
  • A nonempty tree is represented by a two-element list containing its left and right subtrees

Ungolfed

Recursively implements the definition: if N is less than 1, returns the empty list; otherwise, constructs a list containing the results of two recursive calls, one for N-1 and one for N-2.

(load library)
(def F
 (lambda (N)
 (if (less? N 1)
 ()
 (cons
 (F (- N 1))
 (cons
 (F (- N 2))
 ())))))

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