Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Input: Ouput:
- 56432 8
- Input: Output:
- 45781254 11
- Input: Output:
- 0 0
- +/2|⌊⎕÷2*⍳32
- +/⎕⊤⍨32/2
- +/2|<.n%2^i.32
- +/2|<.56432%2^i.32
- 8
- +/2|<.45781254%2^i.32
- 11
- +/2|<.0%2^i.32
- 0
- [[->+<[->->>>+<<]>[->>>>+<<]<<<]>>>>[-<<<<+>>>>]<<<<]
- [ while n != 0
- [ div 2 loop
- -
- >+< marker for if/else
- [->->>>+<<] if n != 0 inc n/2
- >
- [->>>>+<<] else inc m
- <<<
- ]
- >>>> move n/2 back to n
- [-<<<<+>>>>]
- <<<<
- ]
- t,n=0,input()
- while n:t+=n%2;n/=2
- print t
- f=->u{u<1?0:u%2+f[u/2]}
- p f[gets.to_i]
- ~{.2%2/.}do]0-,
- b=lambda n:n and n%2+b(n/2)
- print b(input())
- $n=<>;while($n){$_+=$n%2;$n/=2}print
- $==<>;1while$_+=$=%2,$=/=2;say
- f(n,c){for(c=0;n;n/=2)c+=n%2;printf("%d",c);}
- (logcount x)
- [1]> (logcount 0)
- 0
- [2]> (logcount 1)
- 1
- [3]> (logcount 1024)
- 1
- [4]> (logcount 1023)
- 10
- [5]> (logcount 1234567890123456789012345678901234567890)
- 68
- for(n=prompt(a=0),j=1;j<=n;j*=2)for(i=j;i<=n;i+=2*j)n<i+j&&a++;alert(a)
- f n=sum[1|x<-[0..n],odd$n`div`2^x]
- main=interact$show.f.read
- void f(x){int i=0;for(;x;x/=2)i+=x%2;printf("%u",i);}
- for(n=prompt(o=0);n=n/2|0;o+=n%2);alert(o)
- main(int n,char **a){printf("%u",__builtin_popcount(atoi(a[1])))};
- let rec o=function 0->0|x->(x mod 2)+(o(x/2))
- object O extends App{def f(i:Int):Int=if(i>0)i%2+f(i/2)else 0
- print(f(args(0).toInt))}
- int f(string i){int k=to!int(i),r;while(k){if(k%2)r++;k/=2;}return r;}
- x = int(raw_input())
- s = 0
- while x:
- if x%2:
- s+=1
- x/=2
- print s
- > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
- 1: 56432
- 2:
- Read 1 item
- [1] 8
- > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
- 1: 45781254
- 2:
- Read 1 item
- [1] 11
- > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
- 1: 0
- 2:
- Read 1 item
- [1] 0
- > o(56432)
- [1] 8
- > o(45781254)
- [1] 11
- > o(0)
- [1] 0
- (echo obase=2;cat)|bc|tr -d '0 12'|wc -c
- let rec o x=if x=0 then 0 else (x mod 2) + (o (x/2))
- (define (find-ones n)
- (define (nbits n)
- (let nbits ([i 2])
- (if (< i n) (nbits (* i 2)) i)))
- (let f ([half (/ (nbits n) 2)] [i 0] [n n])
- (cond [(< half 2) i]
- [(< n i) (f (/ half 2) i (/ n 2))]
- [else (f (/ half 2) (+ i 1) (/ n 2))])))
- Count[n~IntegerDigits~2, 1]
- 0?[d2%rsi+li2/d0<x]dsxx+p
- $ dc -e '0?[d2%rsi+li2/d0<x]dsxx+p' <<< 127
- 7
- $ dc countones.dc <<< 1273434547453452352342346734573465732856238472384263456458235374653784538469120235
- 138
- import Data.Bits
- main=interact$show.popCount.read
- 0N[1~!?@2%{1+}2/])I
- 0 # push a 0 onto the stack
- N # read an integer from STDIN onto the stack
- [ # begin an infinite loop
- 1 # push a 1 onto the stack
- ~ # pop the 1 off the stack, and duplicate the top 1 items (i.e. the read number)
- ! # pop a number, push 1 if 0 or 0 otherwise (NOT)
- ? # pop a number, if the number is nonzero...
- @ # ... then break out of the infinite loop. Basically, break out when N reaches 0.
- 2 # push a 2 onto the stack
- % # pop number "a" off the stack, then number "b", and push b modulo a.
- { # rotate the stack left
- 1 # push a 1 onto the stack
- + # pop a and b, and push a + b (increment)
- } # rotate the stack right
- 2 # push a 2 onto the stack
- / # pop number "a" off the stack, then number "b", then push b / a (int)
- ] # repeat back to start of loop
- ) # shift the stack right, taking off the 0 and leaving only the result
- I # output the result as a number to STDOUT
- =LEN(A1)-LEN(SUBSTITUTE(A1,"1",""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement