Skip to main content
added 1061 characters in body
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 5 bytes

KΣK+1 

Try it online!

Repeated twice!

Repeated thrice!

Explanation

I admitIt's quite difficult to construct a repeatable program in Husk. Because the type system forbids a function that can be applied to itself, I have no idea why it works yetto somehow allow the first part to evaluate to a function, and the remainder to evaluate to a value, and the types of existing built-ins are designed to prevent this kind of ambiguity. I'll figure it out The tokens of the program are

  • K, which constructs a constant function. K a b is equivalent to a.
  • Σ, which takes an integer n and returns the nth triangular number.
  • +, which adds two numbers.
  • 1, which is the literal 1.

The original program is interpreted like this:

 K Σ (K+) 1 == Σ 1 == 1 

The (K+) is a nonsensical function that gets eaten by the first K.

The twice repeated program is interpreted like this:

 K Σ (K+1KΣK+) 1 == Σ 1 == 1 

The function in parentheses is again eaten by the first K.

The thrice repeated program is interpreted like this:

 K (Σ (K (+1) (KΣK+) 1)) (KΣK+1) == Σ (K (+1) (KΣK+) 1) == Σ ((+1) 1) == Σ (+1 1) == Σ 2 == 3 

Husk, 5 bytes

KΣK+1 

Try it online!

Repeated twice!

Repeated thrice!

I admit I have no idea why it works yet. I'll figure it out.

Husk, 5 bytes

KΣK+1 

Try it online!

Repeated twice!

Repeated thrice!

Explanation

It's quite difficult to construct a repeatable program in Husk. Because the type system forbids a function that can be applied to itself, I have to somehow allow the first part to evaluate to a function, and the remainder to evaluate to a value, and the types of existing built-ins are designed to prevent this kind of ambiguity. The tokens of the program are

  • K, which constructs a constant function. K a b is equivalent to a.
  • Σ, which takes an integer n and returns the nth triangular number.
  • +, which adds two numbers.
  • 1, which is the literal 1.

The original program is interpreted like this:

 K Σ (K+) 1 == Σ 1 == 1 

The (K+) is a nonsensical function that gets eaten by the first K.

The twice repeated program is interpreted like this:

 K Σ (K+1KΣK+) 1 == Σ 1 == 1 

The function in parentheses is again eaten by the first K.

The thrice repeated program is interpreted like this:

 K (Σ (K (+1) (KΣK+) 1)) (KΣK+1) == Σ (K (+1) (KΣK+) 1) == Σ ((+1) 1) == Σ (+1 1) == Σ 2 == 3 
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 5 bytes

KΣK+1 

Try it online!

Repeated twice!

Repeated thrice!

I admit I have no idea why it works yet. I'll figure it out.