Sign in to follow this  
Followers 0
mesale0077

Consecutive Numbers Collection

8 posts in this topic

exam:

2+4+0+1+1+9+7+9= 33 and 3+3 = 6 like it or

0+2+0+6+1+9+8+4= 30 and 3+0= 3 this code; but dont work

thank you now

Local $len = StringLen('02061984')
Local $var,$var_1=''
for $aa= 1 to $len
$var = StringMid('02061984', $aa, 1)
$var_1=$var_1+number($var)
next
local $ee= StringLen($var_1)
$aa=''
$var__2=''
$var_3=''
for $aa= 1 to $ee
$var_3 = StringMid($var_1, $ee, 1)
$var__2=$var__2+number($var_3)
next
msgbox(0,"",$var__2); 3

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Spot the difference?

Local $len = StringLen('02061984')
Local $var,$var_1=''
for $aa= 1 to $len
    $var = StringMid('02061984', $aa, 1)
    $var_1=$var_1+number($var)
next

local $ee= StringLen($var_1)
$aa=''
$var__2 = ''
$var_3 = ''
for $aa = 1 to $ee
    $var_1 = String($var_1)
    $var_3 = StringMid($var_1, $aa, 1)
    $var__2 = $var__2 + number($var_3)
next
msgbox(0,"",$var__2); 3
Edited by czardas

Share this post


Link to post
Share on other sites

thank you czardas

this your code worked

Local $len = StringLen('02061984')
Local $var,$var_1=''
for $aa= 1 to $len
    $var = StringMid('02061984', $aa, 1)
    $var_1=$var_1+number($var)
next
local $ee= StringLen($var_1)
$aa=''
$var__2 = ''
$var_3 = ''
for $aa = 1 to $ee
    $var_1 = String($var_1)
    $var_3 = StringMid($var_1, $aa, 1)
    $var__2 = $var__2 + number($var_3)
next
msgbox(0,"",$var__2); 3

Share this post


Link to post
Share on other sites

local $hh= GUICtrlRead($Input1)
Local $len = StringLen($hh)
Local $var,$var_1=''
for $aa= 1 to $len
    $var = StringMid($hh, $aa, 1)
    $var_1=$var_1+number($var)
next
local $ee= StringLen($var_1)
$aa=''
$var__2 = ''
$var_3 = ''
for $aa = 1 to $aa
    $var_1 = String($var_1)
    $var_3 = StringMid($var_1, $aa, 1)
    $var__2 = $var__2 + number($var_3)
next

thank you

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

also woking if after first step string len = 3

MsgBox(262144, '', Total('2+4+0+1+1+9+7+9'))
MsgBox(262144, '', Total('02061984'))
;
Func Total($tstr)
    Local $tmp1, $tmp2 = 0
    $tstr = StringRegExpReplace($tstr, "[" & StringRegExpReplace($tstr, "[0123456789]", "") & "]", "")
    If StringLen($tstr) <= 1 Then Return $tstr
    $tmp1 = StringSplit($tstr, "", 1)
    For $idx = 1 To $tmp1[0]
        $tmp2 += $tmp1[$idx]
    Next
    $tstr = Total($tmp2)
    If StringLen($tstr) <= 1 Then Return $tstr
EndFunc   ;==>Total
Edited by SandelPerieanu

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I bet there's a way to make the SRER do the addition, but I couldn't figure that out so went with an Execute() and "+" characters.

$str = '02061984'

While $str > 9
    $str = Execute(StringRegExpReplace($str, "(d)B", "1+"))
WEnd

MsgBox(0, "", $str)
Edited by Spiff59

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0