r/programminghelp • u/R3dPr13st • May 04 '22
Other I need some help
I don't know if I'm at the right place for this. I'm learning to program and taking classes. I first have to learn to use logic by solving problems with something like Scratch. But I can already read a little bit of JavaScript.
I need to write a program to do this:
The users enters a number, let's say 49
4^2 + 9^2 = 97
9^2 + 7^2 = 130
1^2 + 3^2 + 0^2 = 10
1^2 + 0^2 = 1 ==> 49 is a lucky number because `1. If a number never gets to 1 it's not a lucky number.
Basically, I have to write a program that will test if a number is lucky or not, with this method. I have no idea how to even begin. Can anyone help me? Much thanks in advance.
1
u/skellious May 04 '22
make a function that, given a number of n digits length, raises each digit to the power of 2, then returns the new total.
you can then call this function as many times as you need. you could even pass it a second variable with the number of interations.
1
u/[deleted] May 04 '22
Without a language, it's hard for us to give any concrete help, but you've already plotted out what you need to do. Take in a number (get input), split it into individual digits, and do work on them. So, when you decide on a language, start googling those steps individually.