+ 1
Display Equations? (pure js only)
https://code.sololearn.com/W9QNxKefinfV/?ref=app Lets assume the input for this is 135 I want this to display the exponents as equations. So, for 135 I'd want it to display this: 1*1 3*3 5*5*5 or this if you really want to 1*1+3*3+5*5*5 Maybe a for loop can do this. I dunno. And remember, the actual number is unknown. 135 was just an example number.
9 odpowiedzi
0
okay so this was only tested on 135 and isnt writing 1 * 1 as the final exponent but its 1AM here and i dont have time to write this like I want to but it is at least a good start for you.
<script>
let exponents = [];
function getExp(Input){
let num = parseInt(Input);
for(let i = 0; i <= num; i++){
if(i * i >= num){
let exp;
if(i == num){
exp = i;
}else{
exp = i - 1;
}
exponents.push(exp + '*' + exp);
num = num - (exp * exp);
i = 1;
}
if(num === 1){
break;
}
}
}
getExp(135);
document.write(exponents);
</script>
0
I couldn't get it to write 1*1 either. We'll figure something out eventually lol
0
A number is called disarium if the sum of each digit powered to it's position in the number is equal to the number itself.
This is what that would look like. For all examples, I will be using the number 135. 135 is a disarium number because:
1^1+3^2+5^3=135
135 = 135
My program takes an input and decides weather it is disarium or not.
Right now, the output is this
True
1^1+3^2+5^3
1+9+125=135
I need the output to look like this
True
1^1+3^2+5^3
1*1=1
3*3=9
5*5*5=125
1+9+125=135
0
ooooh i wasnt aware thats what you were going for. its sloppy but i typed it on my phone, it works though:
function power(NumberToConvert){
let sum = 0;
let input = String(NumberToConvert);
for(x = 0; x < input.length; x++){
let num = input[x];
sum += Math.pow(parseInt(num), x + 1);
}
if(sum == parseInt(input)){
let string = '';
let string2 = '';
string += 'true'
for(let x = 0; x < input.length; x++){
string += '<br>';
string += input[x] + '^' + input[x] + '=' + Math.pow(parseInt(input[x]), x + 1);
string2 += Math.pow(parseInt(input[x]), x + 1);
if(x != input.length - 1){
string2 += ' + ';
}else{
string2 += ' = ' + sum;
}
}
return string + '<br>' + string2;
}else{
return false;
}
0
Brandon
Can I ask you to add that to my code and post it here?
I won't have time to do it for a bit.
0
im about to go in to work and wont be able to until later tonight
0
I'm about to go to work too. I guess we'll see who gets to it first. Lol
0
Oh!
If you get to it before me, can you include comments? I'd like to know how it works.
0
will do but that is a function, literally drop it in your script somewhere globally and all you have to do is call it and pass the number you want to check as an argument.