Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Population-count/UNIX-Shell/population-count.sh
Normal file
33
Task/Population-count/UNIX-Shell/population-count.sh
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
popcount() {
|
||||
local -i n=$1
|
||||
(( n < 0 )) && return 1
|
||||
local ones=0
|
||||
while (( n > 0 )); do
|
||||
(( ones += n%2 ))
|
||||
(( n /= 2 ))
|
||||
done
|
||||
echo $ones
|
||||
}
|
||||
|
||||
popcount_3s=()
|
||||
n=1
|
||||
for (( i=0; i<30; i++ )); do
|
||||
popcount_3s+=( $(popcount $n) )
|
||||
(( n *= 3 ))
|
||||
done
|
||||
echo "powers of 3 popcounts: ${popcount_3s[*]}"
|
||||
|
||||
evil=()
|
||||
odious=()
|
||||
n=0
|
||||
while (( ${#evil[@]} < 30 || ${#odious[@]} < 30 )); do
|
||||
p=$( popcount $n )
|
||||
if (( $p%2 == 0 )); then
|
||||
evil+=( $n )
|
||||
else
|
||||
odious+=( $n )
|
||||
fi
|
||||
(( n++ ))
|
||||
done
|
||||
echo "evil nums: ${evil[*]:0:30}"
|
||||
echo "odious nums: ${odious[*]:0:30}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue