Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Number of non zero digits in 2^n base 3
<canvas></canvas>
<a href="https://oeis.org/A130693">Related OEIS decription</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.1/chart.min.js"></script>
<script>
const n = 1000;
var data=[], powers=[], labels=[];
for (let x=2; x<n; x++) {
let p = BigInt(Math.pow(2,x));
let digits = p.toString(3);
let sum = 0;
for (let i=0; i<digits.length; i++) {
let d = Number(digits[i]);
if (d != 1 && d != 2 && d != 4 && d != 8)
sum++
}
labels.push(x);
powers.push(p);
data.push(sum);
}
// plot
var ctx = document.querySelector('canvas').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'digits in ',
data: data
}]
},
options: {
plugins: {
tooltip: {
callbacks: {
label: function(context) {
return context.parsed.y+' '+
context.dataset.label+' '+
powers[context.parsed.x].toString(3);
}
}}}}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment