Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
27
Task/Van-der-Corput-sequence/Ada/van-der-corput-sequence.adb
Normal file
27
Task/Van-der-Corput-sequence/Ada/van-der-corput-sequence.adb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Main is
|
||||
package Float_IO is new Ada.Text_IO.Float_IO (Float);
|
||||
function Van_Der_Corput (N : Natural; Base : Positive := 2) return Float is
|
||||
Value : Natural := N;
|
||||
Result : Float := 0.0;
|
||||
Exponent : Positive := 1;
|
||||
begin
|
||||
while Value > 0 loop
|
||||
Result := Result +
|
||||
Float (Value mod Base) / Float (Base ** Exponent);
|
||||
Value := Value / Base;
|
||||
Exponent := Exponent + 1;
|
||||
end loop;
|
||||
return Result;
|
||||
end Van_Der_Corput;
|
||||
begin
|
||||
for Base in 2 .. 5 loop
|
||||
Ada.Text_IO.Put ("Base" & Integer'Image (Base) & ":");
|
||||
for N in 1 .. 10 loop
|
||||
Ada.Text_IO.Put (' ');
|
||||
Float_IO.Put (Item => Van_Der_Corput (N, Base), Exp => 0);
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
end Main;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
def vdc (n, base=2)
|
||||
str = n.to_s(base).reverse
|
||||
str.to_i(base) / (base ** str.size)
|
||||
end
|
||||
|
||||
(2..5).each do |base|
|
||||
puts "Base #{base}: " + Array.new(10){|i| vdc(i,base)}.join(", ")
|
||||
end
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
function vdc(integer n, atom base)
|
||||
atom vdc, denom, rem
|
||||
vdc = 0
|
||||
denom = 1
|
||||
while n do
|
||||
denom *= base
|
||||
rem = remainder(n,base)
|
||||
n = floor(n/base)
|
||||
vdc += rem / denom
|
||||
end while
|
||||
return vdc
|
||||
end function
|
||||
|
||||
for i = 2 to 5 do
|
||||
printf(1,"Base %d\n",i)
|
||||
for j = 0 to 9 do
|
||||
printf(1,"%g ",vdc(j,i))
|
||||
end for
|
||||
puts(1,"\n\n")
|
||||
end for
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
function vdc(n) {
|
||||
const bits = [...n.toString(2)].toReversed();
|
||||
const exps = [...Array(bits.length).keys()].map(x => -x);
|
||||
let res = 0;
|
||||
for (let i = 0; i < bits.length; i++) {
|
||||
res += bits[i] * 2 ** (exps[i] - 1);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
console.log([...Array(10).keys()].map(vdc).join(" "));
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
MODULE VanDerCorput; (* show members of the van der Corput sequence *)
|
||||
(* in various bases - translated from the C sample *)
|
||||
IMPORT Out;
|
||||
|
||||
(* returns the gcd of a and b *)
|
||||
PROCEDURE gcd( a, b : INTEGER ) : INTEGER;
|
||||
VAR n, p, q : INTEGER;
|
||||
BEGIN
|
||||
p := a;
|
||||
q := b;
|
||||
WHILE p # 0 DO n := p; p := q MOD p; q := n END
|
||||
RETURN q
|
||||
END gcd ;
|
||||
|
||||
(* returns the numerator and denominator of the nth member of *)
|
||||
(* the van der Corput sequence in the specified base *)
|
||||
PROCEDURE vc( nth, base : INTEGER; VAR n, d : INTEGER );
|
||||
VAR p, q, g : INTEGER;
|
||||
BEGIN
|
||||
p := 0; q := 1; n := nth;
|
||||
WHILE n # 0 DO
|
||||
p := p * base;
|
||||
INC( p, n MOD base );
|
||||
q := q * base;
|
||||
n := n DIV base
|
||||
END;
|
||||
(* return the numerator and denominator reduced by their gcd *)
|
||||
g := gcd( p, q );
|
||||
n := p DIV g;
|
||||
d := q DIV g
|
||||
END vc;
|
||||
|
||||
PROCEDURE task;
|
||||
VAR i, b, n, d : INTEGER;
|
||||
BEGIN
|
||||
FOR b := 2 TO 5 DO
|
||||
Out.String( "base " );Out.Int( b, 0 );Out.String( ":" );
|
||||
FOR i := 0 TO 9 DO
|
||||
vc( i, b, n, d );
|
||||
IF n = 0 THEN
|
||||
Out.String( " 0" )
|
||||
ELSE
|
||||
Out.String( " " );Out.Int( n, 0 );
|
||||
Out.String( "/" );Out.Int( d, 0 )
|
||||
END
|
||||
END;
|
||||
Out.Ln
|
||||
END
|
||||
END task ;
|
||||
|
||||
BEGIN
|
||||
task
|
||||
END VanDerCorput.
|
||||
12
Task/Van-der-Corput-sequence/R/van-der-corput-sequence.r
Normal file
12
Task/Van-der-Corput-sequence/R/van-der-corput-sequence.r
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
num_bits <- function(n) ifelse(log2(n)%%1==0,
|
||||
1+log2(n),
|
||||
ceiling(log2(n)))
|
||||
|
||||
vdc <- function(n){
|
||||
if(n==0) return(0)
|
||||
inds <- 1:num_bits(n)
|
||||
vdc_raw <- intToBits(n)[inds]
|
||||
sum(as.numeric(vdc_raw)*(2^-inds))
|
||||
}
|
||||
|
||||
sapply(0:9, vdc)
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
'http://rosettacode.org/wiki/Van_der_Corput_sequence
|
||||
'Van der Corput Sequence fucntion call = VanVanDerCorput(number,base)
|
||||
|
||||
Base2 = "0" : Base3 = "0" : Base4 = "0" : Base5 = "0"
|
||||
Base6 = "0" : Base7 = "0" : Base8 = "0" : Base9 = "0"
|
||||
|
||||
l = 1
|
||||
h = 1
|
||||
Do Until l = 9
|
||||
'Set h to the value of l after each function call
|
||||
'as it sets it to 0 - see lines 37 to 40.
|
||||
Base2 = Base2 & ", " & VanDerCorput(h,2) : h = l
|
||||
Base3 = Base3 & ", " & VanDerCorput(h,3) : h = l
|
||||
Base4 = Base4 & ", " & VanDerCorput(h,4) : h = l
|
||||
Base5 = Base5 & ", " & VanDerCorput(h,5) : h = l
|
||||
Base6 = Base6 & ", " & VanDerCorput(h,6) : h = l
|
||||
l = l + 1
|
||||
Loop
|
||||
|
||||
WScript.Echo "Base 2: " & Base2
|
||||
WScript.Echo "Base 3: " & Base3
|
||||
WScript.Echo "Base 4: " & Base4
|
||||
WScript.Echo "Base 5: " & Base5
|
||||
WScript.Echo "Base 6: " & Base6
|
||||
|
||||
'Van der Corput Sequence
|
||||
Function VanDerCorput(n,b)
|
||||
k = RevString(Dec2BaseN(n,b))
|
||||
For i = 1 To Len(k)
|
||||
VanDerCorput = VanDerCorput + (CLng(Mid(k,i,1)) * b^-i)
|
||||
Next
|
||||
End Function
|
||||
|
||||
'Decimal to Base N Conversion
|
||||
Function Dec2BaseN(q,c)
|
||||
Dec2BaseN = ""
|
||||
Do Until q = 0
|
||||
Dec2BaseN = CStr(q Mod c) & Dec2BaseN
|
||||
q = Int(q / c)
|
||||
Loop
|
||||
End Function
|
||||
|
||||
'Reverse String
|
||||
Function RevString(s)
|
||||
For j = Len(s) To 1 Step -1
|
||||
RevString = RevString & Mid(s,j,1)
|
||||
Next
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue