Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
30
Task/Population-count/EasyLang/population-count.easy
Normal file
30
Task/Population-count/EasyLang/population-count.easy
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
func popcnt x .
|
||||
while x > 0
|
||||
r += x mod 2
|
||||
x = x div 2
|
||||
.
|
||||
return r
|
||||
.
|
||||
proc show3 . .
|
||||
write "3^n:"
|
||||
bb = 1
|
||||
for i = 1 to 30
|
||||
write " " & popcnt bb
|
||||
bb *= 3
|
||||
.
|
||||
print ""
|
||||
.
|
||||
proc show s$ x . .
|
||||
write s$
|
||||
while n < 30
|
||||
if popcnt i mod 2 = x
|
||||
n += 1
|
||||
write " " & i
|
||||
.
|
||||
i += 1
|
||||
.
|
||||
print ""
|
||||
.
|
||||
show3
|
||||
show "evil:" 0
|
||||
show "odious:" 1
|
||||
34
Task/Population-count/Ol/population-count.ol
Normal file
34
Task/Population-count/Ol/population-count.ol
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
(define (popcount n)
|
||||
(let loop ((n n) (c 0))
|
||||
(if (= n 0)
|
||||
c
|
||||
(loop (>> n 1)
|
||||
(if (eq? (band n 1) 0) c (+ c 1))))))
|
||||
(print (popcount 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253))
|
||||
|
||||
|
||||
(define thirty 30)
|
||||
|
||||
(display "popcount:")
|
||||
(for-each (lambda (i)
|
||||
(display " ")
|
||||
(display (popcount (expt 3 i))))
|
||||
(iota thirty 0))
|
||||
(print)
|
||||
|
||||
(define (evenodd name test)
|
||||
(display name) (display ":")
|
||||
(for-each (lambda (i)
|
||||
(display " ")
|
||||
(display i))
|
||||
(reverse
|
||||
(let loop ((n 0) (i 0) (out '()))
|
||||
(if (= i thirty)
|
||||
out
|
||||
(if (test (popcount n))
|
||||
(loop (+ n 1) (+ i 1) (cons n out))
|
||||
(loop (+ n 1) i out))))))
|
||||
(print))
|
||||
|
||||
(evenodd "evil" even?)
|
||||
(evenodd "odius" odd?)
|
||||
68
Task/Population-count/Run-BASIC/population-count.basic
Normal file
68
Task/Population-count/Run-BASIC/population-count.basic
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
function tobin$(num)
|
||||
bin$ = ""
|
||||
if num = 0 then bin$ = "0"
|
||||
|
||||
while num >= 1
|
||||
num = num / 2
|
||||
X$ = str$(num)
|
||||
D$ = "": F$ = ""
|
||||
|
||||
for i = 1 to len(X$)
|
||||
L$ = mid$(X$, i, 1)
|
||||
if L$ <> "." then
|
||||
D$ = D$ + L$
|
||||
else
|
||||
F$ = F$ + right$(X$, len(X$) - i)
|
||||
exit for
|
||||
end if
|
||||
next i
|
||||
|
||||
if F$ = "" then B$ = "0" else B$ = "1"
|
||||
bin$ = bin$ + B$
|
||||
num = val(D$)
|
||||
wend
|
||||
B$ = ""
|
||||
for i = len(bin$) to 1 step -1
|
||||
B$ = B$ + mid$(bin$, i, 1)
|
||||
next i
|
||||
tobin$ = B$
|
||||
end function
|
||||
|
||||
function population(number)
|
||||
popul = 0
|
||||
|
||||
'digito$ = tobin$(number)
|
||||
'print tobin$(number)
|
||||
for i = 1 to len(tobin$(number))
|
||||
popul = popul + val(mid$(tobin$(number), i, 1))
|
||||
next i
|
||||
population = popul
|
||||
end function
|
||||
|
||||
sub evilodious limit, tipo
|
||||
i = 0
|
||||
cont = 0
|
||||
|
||||
while 1
|
||||
eo = (population(i) mod 2)
|
||||
if (tipo and eo = 1) or ((not(tipo) and not(eo)) = 1) then
|
||||
cont = cont + 1: print i; " ";
|
||||
end if
|
||||
i = i + 1
|
||||
if cont = limit then exit while
|
||||
wend
|
||||
end sub
|
||||
|
||||
print "Pop cont (3^x): ";
|
||||
for i = 0 to 14
|
||||
print population(3 ^ i); " ";
|
||||
next i
|
||||
|
||||
print
|
||||
print "Evil numbers: ";
|
||||
call evilodious 15, 0
|
||||
|
||||
print
|
||||
print "Odious numbers: ";
|
||||
call evilodious 15, 1
|
||||
end
|
||||
17
Task/Population-count/SETL/population-count.setl
Normal file
17
Task/Population-count/SETL/population-count.setl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program population_count;
|
||||
print([popcount(3**n) : n in [0..29]]);
|
||||
print([n : n in [0..59] | evil n]);
|
||||
print([n : n in [0..59] | odious n]);
|
||||
|
||||
op evil(n);
|
||||
return even popcount n;
|
||||
end op;
|
||||
|
||||
op odious(n);
|
||||
return odd popcount n;
|
||||
end op;
|
||||
|
||||
op popcount(n);
|
||||
return +/[[n mod 2, n div:=2](1) : until n=0];
|
||||
end op;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue