Skip to content

Instantly share code, notes, and snippets.

@rafaelcastrocouto
Created July 20, 2021 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcastrocouto/d2fed205e7a1db38f7f4b72b05f98395 to your computer and use it in GitHub Desktop.
Save rafaelcastrocouto/d2fed205e7a1db38f7f4b72b05f98395 to your computer and use it in GitHub Desktop.
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