Back to Recipes Homepage
 Recipe: Sawtooth function Created by Crashguard303 71 1514 3.833335 Your rating: None Average: 3.8 (6 votes) Used 48 times with an average impact of 843 points.

# Profile

Name: Sawtooth function 2593 Fri, 05/28/2010 - 04:19 Fri, 05/28/2010 - 11:19 When dealing with random values, this function trims positive and negative values to your desired range. This example trims all incoming values to a scale from 1 to 10.

# Best For

Offline
Joined: 09/18/2009
Groups: SETI.Germany
Score Impact

I still don't get why this recipe creates a score impact, although it only outputs some text to show how the function works and doesn't do any changes on the puzzle itself.
If you know why, tell me, please.

Offline
Joined: 09/18/2009
Groups: SETI.Germany
More...

Note that this function intendedly doesn't work symmetric (similar to the sinus-function, which also isn't symmetric at the y-axis) to keep the "waveform" homogenous on the x-axis.
If you want a symmetric output, use absolute values as function-input.

Offline
Joined: 09/18/2009
Groups: SETI.Germany
That's how the code does look like

function Sawtooth(x,range) -- returns values between only 1 and range
x2=x
if x2>0 then
x2=((x2-1)%range)+1
else
x2=range-(-x2%range)
end
return x2
end

for k=15,-15,-1 do
l=Sawtooth(k,10)
print (k," ",l)
end