Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. Input: Ouput:
  2.  
  3. 56432 8
  4.  
  5.  
  6. Input: Output:
  7.  
  8. 45781254 11
  9.  
  10.  
  11. Input: Output:
  12.  
  13. 0 0
  14.  
  15. +/2|⌊⎕÷2*⍳32
  16.  
  17. +/⎕⊤⍨32/2
  18.  
  19. +/2|<.n%2^i.32
  20.  
  21. +/2|<.56432%2^i.32
  22. 8
  23. +/2|<.45781254%2^i.32
  24. 11
  25. +/2|<.0%2^i.32
  26. 0
  27.  
  28. [[->+<[->->>>+<<]>[->>>>+<<]<<<]>>>>[-<<<<+>>>>]<<<<]
  29.  
  30. [ while n != 0
  31. [ div 2 loop
  32. -
  33. >+< marker for if/else
  34. [->->>>+<<] if n != 0 inc n/2
  35. >
  36. [->>>>+<<] else inc m
  37. <<<
  38. ]
  39. >>>> move n/2 back to n
  40. [-<<<<+>>>>]
  41. <<<<
  42. ]
  43.  
  44. t,n=0,input()
  45. while n:t+=n%2;n/=2
  46. print t
  47.  
  48. f=->u{u<1?0:u%2+f[u/2]}
  49. p f[gets.to_i]
  50.  
  51. ~{.2%2/.}do]0-,
  52.  
  53. b=lambda n:n and n%2+b(n/2)
  54. print b(input())
  55.  
  56. $n=<>;while($n){$_+=$n%2;$n/=2}print
  57.  
  58. $==<>;1while$_+=$=%2,$=/=2;say
  59.  
  60. f(n,c){for(c=0;n;n/=2)c+=n%2;printf("%d",c);}
  61.  
  62. (logcount x)
  63.  
  64. [1]> (logcount 0)
  65. 0
  66. [2]> (logcount 1)
  67. 1
  68. [3]> (logcount 1024)
  69. 1
  70. [4]> (logcount 1023)
  71. 10
  72. [5]> (logcount 1234567890123456789012345678901234567890)
  73. 68
  74.  
  75. 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)
  76.  
  77. f n=sum[1|x<-[0..n],odd$n`div`2^x]
  78. main=interact$show.f.read
  79.  
  80. void f(x){int i=0;for(;x;x/=2)i+=x%2;printf("%u",i);}
  81.  
  82. for(n=prompt(o=0);n=n/2|0;o+=n%2);alert(o)
  83.  
  84. main(int n,char **a){printf("%u",__builtin_popcount(atoi(a[1])))};
  85.  
  86. let rec o=function 0->0|x->(x mod 2)+(o(x/2))
  87.  
  88. object O extends App{def f(i:Int):Int=if(i>0)i%2+f(i/2)else 0
  89. print(f(args(0).toInt))}
  90.  
  91. int f(string i){int k=to!int(i),r;while(k){if(k%2)r++;k/=2;}return r;}
  92.  
  93. x = int(raw_input())
  94. s = 0
  95. while x:
  96. if x%2:
  97. s+=1
  98. x/=2
  99. print s
  100.  
  101. > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
  102. 1: 56432
  103. 2:
  104. Read 1 item
  105. [1] 8
  106. > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
  107. 1: 45781254
  108. 2:
  109. Read 1 item
  110. [1] 11
  111. > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
  112. 1: 0
  113. 2:
  114. Read 1 item
  115. [1] 0
  116.  
  117. > o(56432)
  118. [1] 8
  119. > o(45781254)
  120. [1] 11
  121. > o(0)
  122. [1] 0
  123.  
  124. (echo obase=2;cat)|bc|tr -d '012'|wc -c
  125.  
  126. let rec o x=if x=0 then 0 else (x mod 2) + (o (x/2))
  127.  
  128. (define (find-ones n)
  129. (define (nbits n)
  130. (let nbits ([i 2])
  131. (if (< i n) (nbits (* i 2)) i)))
  132. (let f ([half (/ (nbits n) 2)] [i 0] [n n])
  133.     (cond [(< half 2) i]
  134. [(< n i) (f (/ half 2) i (/ n 2))]
  135. [else (f (/ half 2) (+ i 1) (/ n 2))])))
  136.  
  137. Count[n~IntegerDigits~2, 1]
  138.  
  139. 0?[d2%rsi+li2/d0<x]dsxx+p
  140.  
  141. $ dc -e '0?[d2%rsi+li2/d0<x]dsxx+p' <<< 127
  142. 7
  143. $ dc countones.dc <<< 1273434547453452352342346734573465732856238472384263456458235374653784538469120235
  144. 138
  145.  
  146. import Data.Bits
  147. main=interact$show.popCount.read
  148.  
  149. 0N[1~!?@2%{1+}2/])I
  150.  
  151. 0 # push a 0 onto the stack
  152. N # read an integer from STDIN onto the stack
  153. [ # begin an infinite loop
  154. 1 # push a 1 onto the stack
  155. ~ # pop the 1 off the stack, and duplicate the top 1 items (i.e. the read number)
  156. ! # pop a number, push 1 if 0 or 0 otherwise (NOT)
  157. ? # pop a number, if the number is nonzero...
  158. @ # ... then break out of the infinite loop. Basically, break out when N reaches 0.
  159. 2 # push a 2 onto the stack
  160. % # pop number "a" off the stack, then number "b", and push b modulo a.
  161. { # rotate the stack left
  162. 1 # push a 1 onto the stack
  163. + # pop a and b, and push a + b (increment)
  164. } # rotate the stack right
  165. 2 # push a 2 onto the stack
  166. / # pop number "a" off the stack, then number "b", then push b / a (int)
  167. ] # repeat back to start of loop
  168. ) # shift the stack right, taking off the 0 and leaving only the result
  169. I # output the result as a number to STDOUT
  170.  
  171. =LEN(A1)-LEN(SUBSTITUTE(A1,"1",""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement