So, do I get the bonus point for the least iterations?
ps. I'd be tempted to ask him to reconsider if your script furnished a "proof" for the even number formula you employed.
-- tom
Alpha Software Mobile Development Tools: Alpha Anywhere | Alpha TransForm |
option strict 'dim all variables 'n1 = starting value , n2 = ending value (both inclusive) dim n1 as n = 0 dim n2 as n = 0 dim x1 as n = 0 dim x2 as n = 0 dim i as n = 0 dim add_even as n = 0 ' to add even numbers dim add_odd as n = 0 ' to add odd number (optional) dim msg as c="" n1 = 101 ' start value to add n2 = 302 ' end value to stop adding x1 = n1 x2 = n2 i = 1 if (mod(n1,2)=0) ' check if even n1=n1-1 'subtract one because by formula works with starting value as odd and ending as even end if if (mod(n2,2)=1) ' similiar to above reason n2=n2-1 end if if (mod(x1,2)=0) x1=x1+1 end if if (mod(x2,2)=1) x2=x2+1 end if for i = 1 to 1 add_even=((n2^2)-(n1^2)+(n2*2)+1)/4 'formula to add even values between n1 and n2 add_odd =((x2^2)-(x1^2)+(x1*2)-1)/4 'formula to add odd values between n1 and n2 next ui_msg_box("Total Iterations",i) ui_msg_box("Total of the even numbers",add_even) ui_msg_box("Total of the odd numbers",add_odd)
dim n1 as n
dim n2 as n
dim x1 as n
dim x2 as n
dim add_even as n = 0
dim add_odd as n = 0
dim msg as c=""
n1 = 101
n2 = 302
x1 = n1
x2 = n2
if (mod(n1,2)=0)
n1=n1-1
end if
if (mod(n2,2)=1)
n2=n2-1
end if
if (mod(x1,2)=0)
x1=x1+1
end if
if (mod(x2,2)=1)
x2=x2+1
end if
add_even=((n2^2)-(n1^2)+(n2*2)+1)/4
add_odd =((x2^2)-(x1^2)+(x1*2)-1)/4
?add_even+"<br/>"
?add_odd+""
msg=("Total iterations: "+x+" Total of the even numbers: "+sumx) ui_msg_box("Total Iterations",x) ui_msg_box("Total of the even numbers",sumx)
msg=("Total iterations: "+x+" Total of the even numbers: "+sumx) ui_msg_box("Total Iterations",x) ui_msg_box("Total of the even numbers",sumx)
option strict 'dim all variables 'x iteration variable, j number palce holder for start and end 'sumx total of even nunbers 'msg dim x as n=0 dim j as n dim sumx as n=0 dim msg as c="" for j=101 to 302 x=x+1 if mod(j,2)=0 sumx=sumx+j end if next msg=("Total iterations: "+x+" Total of the even numbers: "+sumx) ui_msg_box("Total Iterations",x) ui_msg_box("Total of the even numbers",sumx) ui_msg_box("Puzzle",msg)
option strict 'If you place the OPTION STRICT command at the top of a script then you must declare variables explicitly using the DIM command. dim entries_to_use as C = "" dim qx as N = 101 dim loops as N = 0 DIM SHARED varC_result as C dim ok_button_label as C = "&OK" 'Dimming all variables in one place can make them easier to locate FOR qx = if(mod(qx,2)=0,qx,qx+1) TO 302 step 2 'computed starting loop value, optional step parameter entries_to_use = entries_to_use+alltrim(str(qx))+crlf() loops = increment_value(loops) NEXT qx qx = *total(entries_to_use) 'The *TOTAL() function totals a list of numeric entries. 'xdialog follows to display values, The R directive makes the text in a Text Box read-only. varC_result = ui_dlg_box("Alpha Five",<<%dlg% {region} Loops:| [%r%.40loops]; Sum of Values:| [%r%.40qx]; {endregion}; {line=1,0}; {region} <*15=ok_button_label!OK> {endregion}; %dlg%)
option strict 'If you place the OPTION STRICT command at the top of a script then you must declare variables explicitly using the DIM command. dim entries_to_use as C = "" dim qx as N = 101 dim loops as N = 0 'Dimming all variables in one place can make them easier to locate TRACE.CLEAR() 'Clear the Trace window before writing text to it. WHILE qx < 303 IF mod(qx,2) = 0 'checks for even number entries_to_use = entries_to_use+alltrim(str(qx))+crlf() 'builds crlf() delimited string traceln("Even number "+alltrim(str(qx))+" current loop value "+alltrim(str(loops))) 'writes the number and current loop to the trace window END IF qx = qx + 1 'increments possible values to be summed variable loops = increment_value(loops) 'increments loop variable END WHILE qx = *total(entries_to_use) 'The *TOTAL() function totals a list of numeric entries. 'Note that there is nothing illegal about re-using a numeric variable for a second purpose traceln("Sum "+alltrim(str(qx))+" total loops "+alltrim(str(loops))) ui_msg_box("Note","Activate the Error tab of the next window to appear."+crlf()+"to see the sum of values and loop total.") A5_TOGGLE_TRACE_WINDOW() 'The A5_TOGGLE_TRACE_WINDOW() function opens the Trace window if it is closed, and closes it if it is open.
Leave a comment: