python (65.1k questions)
javascript (44.2k questions)
reactjs (22.7k questions)
java (20.8k questions)
c# (17.4k questions)
html (16.3k questions)
r (13.7k questions)
android (12.9k questions)
Rewriting a common function using tail-end recursion
I've been trying to tinker with this code to rewrite a "repeat" function using tail-end recursion but have gotten a bit stuck in my attempts.
(define (repeat n x)
(if (= n 0)
'()
...
Schultzie67
Votes: 0
Answers: 1
Why does @tailrec not permit this function?
I want to do ln(N!) in Scala with tailrec
@tailrec
final def recursiveLogN(n: Int): Double = {
if (n <= 1) {
return 0
}
Math.log(n) + recursiveLogN(n - 1)
}
The compile er...
aristotll
Votes: 0
Answers: 1
Using python to implement the tail recursion function
For a function p(0) = 10000, p(n) = p(n-1) + 0.02*p(n-1),
the code should be like this:
def p(n,v=10000):
if n == 0:
return v
else:
return p(n-1,1.02*v)
But if p(0) = 10000,...
kongguyinzhe
Votes: 0
Answers: 3
change the recursive function to tail recursive
def singlesR(xs):
if xs != [] :
return [[xs[0]]] + singlesR(xs[1:])
else :
return []
<recursive function>
How to change to a tail recursive function?
#result value
singlesR([1,2,...
minjun kim
Votes: 0
Answers: 2