function sigma (n, p)
{
for (var i = 0; i < p; i ++) {
var result = n + p
}
return result
}
def sigma_rec (n, p, i)
{
var result = n + p, i ++: return unless i == p
sigma_rec(n,p,i)
}
Is this a competition to find the least efficient way to implement addition? A for loop is a nice thought, but it really needs at least one non-tail-recursive call and a few leaked data structures. It's also probably worth throwing in some actual complicated operations rather than just adding n+p p times.function sigma (n, p) { for (var i = 0; i < p; i ++) { var result = n + p } return result }
To be fair, it is more complex than that. If p is less than or equal to 0, you get a runtime error due to an undefined variable. I'd hesitate to just perform an addition, just in case that is an intended feature.just adding n+p p times.
Depends on what you're doing with the recursion (how many recursive calls performed per call of itself). One recursive call, perhaps implementing the equivalent of a for loop, would yield the same complexity, O(n).what is O time of recursion
Depending on what you actually wrote, the compiler may optimize away trivial loops.in ruby and C it's not that bad, but a few nanoseconds
result = clamp(round(221.3 + bnc() div player_pos),0.1,221321) if player_pos == last_pos
function bnc()
{
var rnd = 321765123 div (current_time + 1) % 20; return rnd
}
yes indeedDepends on what you're doing with the recursion (how many recursive calls performed per call of itself). One recursive call, perhaps implementing the equivalent of a for loop, would yield the same complexity, O(n).
function bnc_empty()
{
var rnd = 321765123 div (time) % 256; return rnd
}
function rng(i,n)
{
random_n = bnc_empty()
return (random_n % power(n,i)) + 4
}