Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 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. ,.
  20.  
  21. +/2|<.n%2^i.32
  22.  
  23. +/2|<.56432%2^i.32
  24. 8
  25. +/2|<.45781254%2^i.32
  26. 11
  27. +/2|<.0%2^i.32
  28. 0
  29.  
  30. [[->+<[->->>>+<<]>[->>>>+<<]<<<]>>>>[-<<<<+>>>>]<<<<]
  31.  
  32. [ while n != 0
  33. [ div 2 loop
  34. -
  35. >+< marker for if/else
  36. [->->>>+<<] if n != 0 inc n/2
  37. >
  38. [->>>>+<<] else inc m
  39. <<<
  40. ]
  41. >>>> move n/2 back to n
  42. [-<<<<+>>>>]
  43. <<<<
  44. ]
  45.  
  46. t,n=0,input()
  47. while n:t+=n%2;n/=2
  48. print t
  49.  
  50. f=->u{u<1?0:u%2+f[u/2]}
  51. p f[gets.to_i]
  52.  
  53. ~{.2%2/.}do]0-,
  54.  
  55. f(n,c){for(c=0;n;n/=2)c+=n%2;printf("%d",c);}
  56.  
  57. b=lambda n:n and n%2+b(n/2)
  58. print b(input())
  59.  
  60. $n=<>;while($n){$_+=$n%2;$n/=2}print
  61.  
  62. $==<>;1while$_+=$=%2,$=/=2;say
  63.  
  64. void f(x){int i=0;for(;x;x/=2)i+=x%2;printf("%u",i);}
  65.  
  66. 0?[d2%rsi+li2/d0<x]dsxx+p
  67.  
  68. $ dc -e '0?[d2%rsi+li2/d0<x]dsxx+p' <<< 127
  69. 7
  70. $ dc countones.dc <<< 1273434547453452352342346734573465732856238472384263456458235374653784538469120235
  71. 138
  72.  
  73. (logcount x)
  74.  
  75. [1]> (logcount 0)
  76. 0
  77. [2]> (logcount 1)
  78. 1
  79. [3]> (logcount 1024)
  80. 1
  81. [4]> (logcount 1023)
  82. 10
  83. [5]> (logcount 1234567890123456789012345678901234567890)
  84. 68
  85.  
  86. 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)
  87.  
  88. f n=sum[1|x<-[0..n],odd$n`div`2^x]
  89. main=interact$show.f.read
  90.  
  91. let rec o=function 0->0|x->(x mod 2)+(o(x/2))
  92.  
  93. object O extends App{def f(i:Int):Int=if(i>0)i%2+f(i/2)else 0
  94. print(f(args(0).toInt))}
  95.  
  96. int f(string i){int k=to!int(i),r;while(k){if(k%2)r++;k/=2;}return r;}
  97.  
  98. x = int(raw_input())
  99. s = 0
  100. while x:
  101. if x%2:
  102. s+=1
  103. x/=2
  104. print s
  105.  
  106. > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
  107. 1: 56432
  108. 2:
  109. Read 1 item
  110. [1] 8
  111. > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
  112. 1: 45781254
  113. 2:
  114. Read 1 item
  115. [1] 11
  116. > o=function(n){h=n%/%2;n%%2+if(h)o(h)else 0};o(scan())
  117. 1: 0
  118. 2:
  119. Read 1 item
  120. [1] 0
  121.  
  122. > o(56432)
  123. [1] 8
  124. > o(45781254)
  125. [1] 11
  126. > o(0)
  127. [1] 0
  128.  
  129. let rec o x=if x=0 then 0 else (x mod 2) + (o (x/2))
  130.  
  131. (define (find-ones n)
  132. (define (nbits n)
  133. (let nbits ([i 2])
  134. (if (< i n) (nbits (* i 2)) i)))
  135. (let f ([half (/ (nbits n) 2)] [i 0] [n n])
  136.     (cond [(< half 2) i]
  137. [(< n i) (f (/ half 2) i (/ n 2))]
  138. [else (f (/ half 2) (+ i 1) (/ n 2))])))
  139.  
  140. Count[n~IntegerDigits~2, 1]
  141.  
  142. =LEN(A1)-LEN(SUBSTITUTE(A1,"1",""))
  143.  
  144. for(n=prompt(o=0);n=n/2|0;o+=n%2);alert(o)
  145.  
  146. int b(Long a){return a.bitCount(a);}
  147.  
  148. Prompt X
  149. 0→S
  150. While X
  151. S+remainder(2,X→S
  152. int(X/2→X
  153. End
  154. S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement