Function to multiply all digits in a number (Multiplication Persistence Test) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Function to multiply all digits in a number (Multiplication Persistence Test)

13 May 2019, 11:39

I would like to have the shortest function (script) to multiply all digits in a given number string. For example, in the case of 1234567, the result would be 1*2*3*4*5*6*7 (5040). I have some ideas but all of them involve splitting the string from right or left one at a time and saving each position (digit) and then multiply them all together, but this would become a very long process and seems to me not the best way.
Last edited by carno on 13 May 2019, 14:38, edited 5 times in total.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Function to multiply all digits in a number string  Topic is solved

13 May 2019, 11:49

Hallo,
try:

Code: Select all

Number = 1234567
Result = 1
Loop, Parse, Number
	Result *= A_LoopField
MsgBox,% Result
Klarion
Posts: 176
Joined: 26 Mar 2019, 10:02

Re: Function to multiply all digits in a number string

13 May 2019, 12:26

have to consider some/many ifs.
if 7, 8, 9, 10 ?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Function to multiply all digits in a number string

13 May 2019, 12:52

Code: Select all

for each, digit in StrSplit(string := 1234567), result := 1
	result *= digit
MsgBox % result
@Klarion
10 is fine, not a digit
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: Function to multiply all digits in a number string

13 May 2019, 14:00

Rohwedder wrote:
13 May 2019, 11:49
Hallo,
try:

Code: Select all

Number = 1234567
Result = 1
Loop, Parse, Number
	Result *= A_LoopField
MsgBox,% Result
Thank you all very much and my special thanks to Rohwedder! This solved my Multiplication Persistence problem using AHK. :D
Multiplication Persistence of a number refers to total number of steps required to multiply the digits of a number until the result is a single digit. The current world record is number 277777788888899 with the persistence of 11. Other numbers have equal persistence of 11 but this number is the shortest number with the biggest currently-known persistence! Thank you again for providing this beautiful function. :ugeek: The current search has gone as far as 233 digits and the current conjecture is that you will never beat 11. It will be a major breakthrough if someone could find a number with the Multiplication Persistence of 12.

Code: Select all

#NoEnv
#SingleInstance Force

InputBox, Number, Enter a Number, Prompt, , 250, 100, , , , , 277777788888899
If ErrorLevel = 1
ExitApp

;Number = 277777788888899

Loop {
Steps++
;MsgBox % MP(Number)
If (MP(Number) > 9) {
Number := MP(Number)
Continue
}
Else
Break
}
MsgBox % Steps

MP(Number)
{
Result = 1
Loop, Parse, Number
	Result *= A_LoopField
Return Result
}
Klarion
Posts: 176
Joined: 26 Mar 2019, 10:02

Re: Function to multiply all digits in a number (Multiplication Persistence Test)

13 May 2019, 20:53

very effective way to waste somebody else's precious time
by Oxford dictionary digit means Any of the numerals from 0 to 9.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy and 176 guests