Skip to main content
added 3 characters in body
Source Link
Galen Ivanov
  • 21.2k
  • 3
  • 24
  • 61

Red, 5253 bytes

f: func[n][i: 0 until[0 >>= n: n -(1.0 /(i: i + 1))]i]

Try it online!Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- whenever we need the value of the i parameter.

Red, 52 bytes

f: func[n][i: 0 until[0 > n: n -(1.0 /(i: i + 1))]i]

Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- whenever we need the value of the i parameter.

Red, 53 bytes

f: func[n][i: 0 until[0 >= n: n -(1.0 /(i: i + 1))]i]

Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- whenever we need the value of the i parameter.

deleted 14 characters in body
Source Link
Galen Ivanov
  • 21.2k
  • 3
  • 24
  • 61

Red, 52 bytes

f: func[n][i: 0 until[0 > n: n -(1.0 /(i: i + 1))]i]

Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- and to use it whenever we nnedneed the value of the i parameter.

Red, 52 bytes

f: func[n][i: 0 until[0 > n: n -(1.0 /(i: i + 1))]i]

Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- and to use it whenever we nned the value of the i parameter.

Red, 52 bytes

f: func[n][i: 0 until[0 > n: n -(1.0 /(i: i + 1))]i]

Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- whenever we need the value of the i parameter.

Source Link
Galen Ivanov
  • 21.2k
  • 3
  • 24
  • 61

Red, 52 bytes

f: func[n][i: 0 until[0 > n: n -(1.0 /(i: i + 1))]i]

Try it online!

Simple iterative solution.

Red, 78 bytes

f: func[n /a i][either a[either n > 0[f/a n -(1.0 / i)i + 1][i - 1]][f/a n 1]]

Try it online!

I know this is way longer than other recursive solutions, but I wanted to post it because of the fact that Red functions have fixed arity. In order to simulate default values for the additional parameters, we need to use a refinement - here it's /a- and to use it whenever we nned the value of the i parameter.