Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0: 0 : 1 bit
- 1: 1 : 1 bit
- 2: 10 : 2 bits
- 3: 11 : 2 bits
- 4: 100 : 3 bits
- 5: 101 : 3 bits
- 1 => 1
- 2 => 1
- 3 => 1.3333333
- 4 => 1.5
- 5 => 1.8
- 6 => 2
- 7 => 2.1428571
- .Oml.B
- .Oml.BdUQ Filling in implict vars
- .O Average of list
- m UQ Map over [0..input)
- l Length of
- .B Binary string representation of int
- d Lambda var
- R’BFL÷
- R’BFL÷ Main monadic chain. Argument: n
- R yield [1, 2, ..., n]
- ’ decrement; yield [0, 1, ..., n-1]
- B convert to binary; yield [[0], [1], [1,0], [1,1], ...]
- F flatten list; yield [0, 1, 1, 0, 1, 1, ...]
- L length of list
- ÷ divide [by n]
- @(n)1+sum(fix(log2(1:n-1)))/n
- log2(1:n-1) % log2 of numbers in range [1..n-1]
- % why no 0? because log2(0) = -Inf :/
- fix( ) % floor (more or less, for positive numbers)
- sum( ) % sum... wait, didn't we miss a +1 somewhere?
- % and what about that missing 0?
- /n % divide by n for the mean
- 1+ % and add (1/n) for each of the n bit lengths
- % (including 0!)
- n->mean(ceil(log2([2;2:n])))
- q:ZlksG/Q
- % Implicitly grab input (N)
- q: % Create array from 1:N-1
- Zl % Compute log2 for each element of the array
- k % Round down to the nearest integer
- s % Sum all values in the array
- G % Explicitly grab input again
- / % Divide by the input
- Q % Add 1 to account for 0 in [0, ... N - 1]
- % Implicitly display the result
- :qBYszQG/
- :qBYszQG/
- : % take vector [1..n]
- q % decrement by 1 to get [0..n-1]
- B % convert from decimal to binary
- Ys % cumulative sum (fills in 0's after first 1)
- z % number of nonzero elements
- Q % increment by 1 to account for zero
- G % paste original input (n)
- / % divide for the mean
- Rl2Ċ»1S÷
- R 1 to n
- l2 log2
- Ċ ceiling
- »1 max of 1 and...
- S sum
- ÷ divided by n
- BL©2*2_÷+®
- æḟ2’Ḥ÷_BL$N
- float a(int n){int i=0,t=0;for(;i<n;)t+=Integer.toString(i++,2).length();return t/(n+0f);}
- lambda x:sum(len(bin(i))-2for i in range(x))/x
- f = lambda x: sum(len(bin(i))-2for i in range(x))/x
- print(f(6))
- # 2.0
- L<bJg¹/
- L< # range from 0..input-1
- b # convert numbers to binary
- J # join list of binary numbers into a string
- g # get length of string (number of bits)
- ¹/ # divide by input
- double f(int n){return Enumerable.Range(0,n).Average(i=>Convert.ToString(i,2).Length);}
- +/@:%~#@#:"0@i.
- range =: i.
- length =: #
- binary =: #:
- sum =: +/
- divide =: %
- itself =: ~
- of =: @
- ofall =: @:
- binarylength =: length of binary "0
- average =: sum ofall divide itself
- f =: average binarylength of range
- (+/1⌈(⌈2⍟⍳))÷⊢
- range ← ⍳
- log ← ⍟
- log2 ← 2 log range
- ceil ← ⌈
- bits ← ceil log2
- max ← ⌈
- fix0 ← 1 max bits
- sum ← +/
- total ← sum fix0
- self ← ⊢
- div ← ÷
- mean ← sum div self
- n$z1z[i1+2l$M$Y+]kz$:N.
- n$z Take number from input and store it in register (n)
- 1 Push 1 onto the stack
- z[ For loop that repeats n times
- i1+ Loop counter + 1
- 2l$M log_2
- $Y Ceiling
- + Add top two elements of stack
- ] Close for loop
- z$: Float divide by n
- N. Output as number and stop.
- n=>eval(`for(o=0,p=n;n--;o+=n.toString(2).length/p);o`)
- n => // anonymous function w/ arg `n`
- for( // loop
- o=0, // initalize bit counter to zero
- p=n // copy the input
- ;n-- // will decrease input every iteration, will decrease until it's zero
- ;o+= // add to the bitcounter
- n.toString(2) // the binary representation of the current itearations's
- .length // length
- /p // divided by input copy (to avergage)
- );o // return o variable
- |=
- r/@
- (^div (sun (roll (turn (gulf 0 (dec r)) xeb) add)) (sun r)):.^rq
- > %. 7
- |=
- r/@
- (^div (sun (roll (turn (gulf 0 (dec r)) xeb) add)) (sun r)):.^rq
- .~~~2.1428571428571428571428571428571428
- n=>(l=-~Math.log2(n))-(2**l-2)/n
- n=>(l=-~Math.log2(n))-((1<<l)-2)/n
- 11111111111111111111111
- 111111111111111100000000000000001111111
- 11111111000000001111111100000000111111110000000
- 111100001111000011110000111100001111000011110000111
- 11001100110011001100110011001100110011001100110011001
- 0101010101010101010101010101010101010101010101010101010
- ;r♂├Σl/
- ;r♂├Σl/
- ; duplicate input
- r push range(0, n) ([0, n-1])
- ♂├ map binary representation
- Σ sum (concatenate strings)
- l/ divide length of string (total # of bits) by n
- r♂├♂læ
- 0vVV1HV1-[2L_1+v+v]v1+V/N
- param($n)0..($n-1)|%{$o+=[convert]::ToString($_,2).Length};$o/$n
- for(1..<>){$u+=length sprintf"%b",$_;$n++}$u/=$n;say$u
- rd_,2fbs,/
- rd e# read input and convert to double
- _ e# duplicate
- , e# range from 0 to input minus 1
- 2fb e# convert each element of the array to binary
- s e# convert to string. This flattens the array
- , e# length of array
- e# swap
- / e# divide
- /uΜr0xdlBH
- /uΜr0xdlBH
- Μr0x map range 0..x
- dlBH over lengths of binary elements
- /u divide sum of this
- by implicit input (x)
- func f(n:Double)->Double{return n<1 ?1:f(n-1)+1+floor(log2(n))}
- f(N-1)/N
- %~[:+/#@#:"0@i.
- f =: %~[:+/#@#:"0@i.
- f 7
- 2.14286
- %~[:+/#@#:"0@i. Input is y
- i. Range from 0 to y-1.
- "0@ For each number in this range:
- #@ Compute the length of
- #: its base-2 representation.
- [:+/ Take the sum of the lengths, and
- %~ divide by y.
- (fn [n]
- (->
- (->>
- (range n) ;;Get numbers from 0 to N
- (map #(.bitLength (bigint %))) ;;Cast numbers to BigInt so bitLength can be used
- (apply +) ;;Sum the results of the mapping
- (inc)) ;;Increment by 1 since bitLength of 0 is 0
- (/ n))) ;;Divide the sum by N
Add Comment
Please, Sign In to add comment