September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
16
Task/Van-der-Corput-sequence/Jq/van-der-corput-sequence-1.jq
Normal file
16
Task/Van-der-Corput-sequence/Jq/van-der-corput-sequence-1.jq
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# vdc(base) converts an input decimal integer to a decimal number based on the van der
|
||||
# Corput sequence using base 'base', e.g. (4 | vdc(2)) is 0.125.
|
||||
#
|
||||
def vdc(base):
|
||||
|
||||
# The helper function converts a stream of residuals to a decimal,
|
||||
# e.g. if base is 2, then decimalize( (0,0,1) ) yields 0.125
|
||||
def decimalize(stream):
|
||||
reduce stream as $d # state: [accumulator, power]
|
||||
( [0, 1/base];
|
||||
.[1] as $power | [ .[0] + ($d * $power), $power / base] )
|
||||
| .[0];
|
||||
|
||||
if . == 0 then 0
|
||||
else decimalize(recurse( if . == 0 then empty else ./base | floor end ) % base)
|
||||
end ;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
def round(n):
|
||||
(if . < 0 then -1 else 1 end) as $s
|
||||
| $s*10*.*n | if (floor%10)>4 then (.+5) else . end | ./10 | floor/n | .*$s;
|
||||
|
||||
range(2;6) | . as $base | "Base \(.): \( [ range(0;11) | vdc($base)|round(1000) ] )"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
$ jq -n -f -c -r van_der_corput_sequence.jq
|
||||
Base 2: [0,0.5,0.25,0.75,0.125,0.625,0.375,0.875,0.063,0.563,0.313]
|
||||
Base 3: [0,0.333,0.667,0.111,0.444,0.778,0.222,0.556,0.889,0.037,0.37]
|
||||
Base 4: [0,0.25,0.5,0.75,0.063,0.313,0.563,0.813,0.125,0.375,0.625]
|
||||
Base 5: [0,0.2,0.4,0.6,0.8,0.04,0.24,0.44,0.64,0.84,0.08]
|
||||
Loading…
Add table
Add a link
Reference in a new issue