[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 218 KB, 960x720, nuaoc.jpg [View same] [iqdb] [saucenao] [google]
2953788 No.2953788 [Reply] [Original]

There is a function or a way to do that?:

If I enter 356 ($n = 356) it will do this: 356 (3*5*6 = 90) -> 90 (9*0 = 0) -> 0. Of course I want all the results (90 and 0, no only 0). Ideas?

>> No.2953800

What mountain is that
i want to spend the rest of my life on that awesome mountain

>> No.2953813

Notch resides here

>> No.2953817

>>2953800
this

>> No.2953818

Check amount of digits, divide by power of 10 that has same amount of digits and truncate to get one of the digits.

>> No.2953824

>>2953817
>>2953800

Not OP, but that looks like a mesa, not a mountain. Probably one of the ones in the Andes that inspired the Professor Challenger 'Lost World' stories.

>> No.2953826

>>2953788
What the fuck am I reading?

>> No.2953833
File: 15 KB, 692x224, screenshot_2011-04-26_21:04:53.png [View same] [iqdb] [saucenao] [google]
2953833

>> No.2953876

>>2953833
Oh, title said PHP.
Well then, here's a pseudocode conversion of the Mathematica code above.

1. Create an array of the integer digits of your number
2. Multiply the array values
3. Check if you've gotten a new number
3.1 If new number, put it on a stack (i.e. an array in PHP) and repeat from 1 with your new number
3.2 else break

>> No.2953911

i don't know php, but you can do this pretty easily using the rounding functions of excel

>> No.2953928

>>2953876

and do every step by step!!!?? I want it automatic!!

>> No.2953936

>>2953928
Well then code it, it's less than ten lines

>> No.2953942
File: 36 KB, 640x480, 1303836813596.jpg [View same] [iqdb] [saucenao] [google]
2953942

>>2953928
wat

>> No.2953993

>>2953788

def nomnom(number)
number_array = number.to_s.scan(/./)
output = 1
number_array.each {|n| output = n.to_i*output}
return output
end

a = nomnom(356)
p a
p nomnom(a)


Dunno how to do it in your moon language though.

>> No.2954071

>php

fuck dat shit

vector<int> *dodatshit(int n) {

vector<int> *t=new vector<int>;

do
{
t->push_back(1);

do
{
t->back() *= (n - 10*(n/10));
n /= 10;
} while (n > 0);

} while ((n=t->back()) > 9);

return t;
}

>> No.2954145

>php

fuck that shit

vector<int> *dodatshit(int n) {

vector<int> *t=new vector<int>;

do {
t->push_back(1);

do {
t->back() *= (n - 10*(n/10));
} while ((n /= 10) > 0);

} while ((n=t->back()) > 9);

return t;
}