Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
PROGRAM ROOT_MEAN_SQUARE
|
||||
BEGIN
|
||||
N=10
|
||||
FOR I=1 TO N DO
|
||||
S=S+I*I
|
||||
END FOR
|
||||
X=SQR(S/N)
|
||||
PRINT("Root mean square is";X)
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(define (rms xs)
|
||||
(sqrt (// (for/sum ((x xs)) (* x x)) (length xs))))
|
||||
|
||||
(rms (range 1 11))
|
||||
→ 6.2048368229954285
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function QuadraticMean(array() As Double) As Double
|
||||
Dim length As Integer = Ubound(array) - Lbound(array) + 1
|
||||
Dim As Double sum = 0.0
|
||||
For i As Integer = LBound(array) To UBound(array)
|
||||
sum += array(i) * array(i)
|
||||
Next
|
||||
Return Sqr(sum/length)
|
||||
End Function
|
||||
|
||||
Dim vector(1 To 10) As Double
|
||||
For i As Integer = 1 To 10
|
||||
vector(i) = i
|
||||
Next
|
||||
|
||||
Print "Quadratic mean (or RMS) is :"; QuadraticMean(vector())
|
||||
Print
|
||||
Print "Press any key to quit the program"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fun main(as: [n]f64): f64 =
|
||||
sqrt64 ((reduce (+) 0.0 (map (**2.0) as)) / f64(n))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
1, 10 rep (i)
|
||||
i i | (v) ;
|
||||
0
|
||||
1, 10 rep (i)
|
||||
i dup mult +
|
||||
]
|
||||
10 div
|
||||
sqrt
|
||||
print
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
define rms(a::staticarray)::decimal => {
|
||||
return math_sqrt((with n in #a sum #n*#n) / decimal(#a->size))
|
||||
}
|
||||
rms(generateSeries(1,10)->asStaticArray)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import morfa.base;
|
||||
import morfa.functional.base;
|
||||
|
||||
template <TRange>
|
||||
func rms(d: TRange): float
|
||||
{
|
||||
var count = 1;
|
||||
return sqrt(reduce( (a: float, b: float) { count += 1; return a + b * b; }, d) / count);
|
||||
}
|
||||
|
||||
func main(): void
|
||||
{
|
||||
println(rms(1 .. 11));
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import math
|
||||
|
||||
proc qmean(num): float =
|
||||
for n in num:
|
||||
result += n*n
|
||||
result = sqrt(result / float(num.len))
|
||||
|
||||
echo qmean([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0])
|
||||
|
|
@ -0,0 +1 @@
|
|||
10 seq map(#sq) sum 10.0 / sqrt .
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
function rms(sequence s)
|
||||
atom sqsum = 0
|
||||
for i=1 to length(s) do
|
||||
sqsum += power(s[i],2)
|
||||
end for
|
||||
return sqrt(sqsum/length(s))
|
||||
end function
|
||||
|
||||
? rms({1,2,3,4,5,6,7,8,9,10})
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
long ll_x, ll_y, ll_product
|
||||
decimal ld_rms
|
||||
|
||||
ll_x = 1
|
||||
ll_y = 10
|
||||
DO WHILE ll_x <= ll_y
|
||||
ll_product += ll_x * ll_x
|
||||
ll_x ++
|
||||
LOOP
|
||||
ld_rms = Sqrt(ll_product / ll_y)
|
||||
|
||||
//ld_rms value is 6.20483682299542849
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
nums = [1,2,3,4,5,6,7,8,9,10]
|
||||
sum = 0
|
||||
decimals(5)
|
||||
see "Average = " + average(nums) + nl
|
||||
|
||||
func average number
|
||||
for i = 1 to len(number)
|
||||
sum = sum + pow(number[i],2)
|
||||
next
|
||||
x = sqrt(sum / len(number))
|
||||
return x
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
func rms(a) {
|
||||
Math.sqrt(a.map{.**2}.sum / a.len);
|
||||
}
|
||||
|
||||
say rms(1..10);
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
@let {
|
||||
; using a composition and a fork (like you would do in J)
|
||||
rms1 ^(@sqrt @(@sum / #) *^@sq)
|
||||
|
||||
; using a function with a named argument
|
||||
rms2 &a @sqrt ~/ #a @sum !*^@sq a
|
||||
|
||||
[[
|
||||
!rms1 @to 10
|
||||
!rms2 @to 10
|
||||
]]
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
(defun quadratic-mean (xs)
|
||||
(sqrt
|
||||
(/
|
||||
(apply +
|
||||
(mapcar (lambda (x) (expt x 2)) xs))
|
||||
(length xs))))
|
||||
|
||||
; define a RANGE function, for testing purposes
|
||||
|
||||
(defun range (x y)
|
||||
(if (< x y)
|
||||
(cons x (range (+ x 1) y))))
|
||||
|
||||
; test QUADRATIC-MEAN
|
||||
|
||||
(print (quadratic-mean (range 1 11)))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def rms: length as $length
|
||||
| if $length == 0 then null
|
||||
else map(. * .) | add | sqrt / $length
|
||||
end ;
|
||||
|
|
@ -0,0 +1 @@
|
|||
rms
|
||||
Loading…
Add table
Add a link
Reference in a new issue