Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Programming Puzzle 1 - Simple Loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: Programming Puzzle 1 - Simple Loop

    Thinking outside the box, are we, now?

    Pratik, your solution gets the correct result. However, our fearless scorekeeper, "Ignatious A. Pickypicky", has deducted points for (a) the absence of explanatory comments; and (b) the failure to display the computed results in a message box. Care to try again? Maybe you'll catch Pickypicky in a better mood!

    Comment


      #17
      Re: Programming Puzzle 1 - Simple Loop

      hi tom,
      I wasn't really worried about the points but now you said it so I made some changes with comments, loop and message box. So, do I get the bonus point for the least iterations.
      HTML Code:
      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)

      Comment


        #18
        Re: Programming Puzzle 1 - Simple Loop

        So, do I get the bonus point for the least iterations?
        Sorry, no. By stepping out of the bounds created for the exercse you've earned the careful attention of our venerable scorekeeper, Prof. Pickypicky. He will be keeping a sharp eye on your future puzzle submittals!

        ps. I'd be tempted to ask him to reconsider if your script furnished a "proof" for the even number formula you employed.

        -- tom

        Comment


          #19
          Re: Programming Puzzle 1 - Simple Loop

          hey tom,
          I am new to this forum and don't know what you and your "Prof. Pickypicky" is talking about. Maybe I'm little careless that even in my classes I rarely got an A (instead A- or B+) even though I get the job done. I don't know what proof are you asking and i don't know how to proof ?? I am good in math so I just took some time and came up with this formula. Now if you are interested as how I came up with this formula then I can explain but still its little complicated to explain. you can try using different values in n1 and n2 several times. That works so is that considered "proof"??

          Comment


            #20
            Re: Programming Puzzle 1 - Simple Loop

            Pratik,

            I was mostly pulling your leg. Trying to be facetious. No mathematical proof is necessary. Thanks for contributing to this thread. I look forward to your answers on other puzzles in the future. -- tom

            Comment


              #21
              Re: Programming Puzzle 1 - Simple Loop

              Nice job Pratik! When I posted my original solution I was pretty sure there had to be some way to do it without any iterations but didn't have the time to work it out. And seeing your solution - probably not the ability either.

              Comment


                #22
                Re: Programming Puzzle 1 - Simple Loop

                upon a realisation that my input attracts no response other than anonymous respondents through email and private messages. No harm in posting another version, yet in attempt to contribution in a speedier progress for a would be alpha fellow.

                regards,
                Attached Files
                -MbusoNgcongo
                INFOMAS (Information Systems)
                [email protected]

                Comment


                  #23
                  Re: Programming Puzzle 1 - Simple Loop

                  Mbuso,

                  Very nice! Thinking outside the box. Your solution does not use a loop, but is ingenious nevertheless. In your algorithm you adjust the end points of the number range, then compute both the number of "even" terms and the avg over the entire range. Multiplying them together you get the sum. Very clever, grasshopper! Prof. Pickypicky will be watching you closely, too!

                  Comment


                    #24
                    Re: Programming Puzzle 1 - Simple Loop

                    ...Very clever, grasshopper!...
                    *blushing* ...

                    with a slight modification the same can be applied to calculate sum of equal contributions made in to investment or loan repayment. Which indeed, can also be done the snaky route (loop:-)
                    -MbusoNgcongo
                    INFOMAS (Information Systems)
                    [email protected]

                    Comment


                      #25
                      Re: Programming Puzzle 1 - Simple Loop

                      CALocklin - Its not that difficult and you definitely have the ability (maybe not time). It took me a while to figure out the logic and formula. I saw Mbuso's logic too and its way easier than the way I was doing. His logic was to get the start and end numbers to be even. Then, get the average (easy to calculate), and times no. of even numbers which is (N+1)/2.. That's it.. brilliant..
                      I was also thinking similiar but the question wanted to calcuate from 101 -302. So wanted the input to be starting -odd and ending- even numbers. I did it for adding odd numbers which made little complications.

                      Comment


                        #26
                        Re: Programming Puzzle 1 - Simple Loop

                        thanx pmanandhar.
                        interesting to read your work since you have a taste for math, and background in cpp, as seen in flyPuzzle :-)
                        -MbusoNgcongo
                        INFOMAS (Information Systems)
                        [email protected]

                        Comment


                          #27
                          Re: Programming Puzzle 1 - Simple Loop

                          Code:
                          OPTION strict
                          dim sum as N
                          'defining sum variable as Number. Sum will be used to get the total sum of the even number through the range.
                          dim qx as N
                          'defining qx variable as Number. QX will be used as the loop.
                          dim lnum as N
                          'defining lnum variable as Number. Lnum will be used to get the total times the loop was done.
                          sum=0
                          lnum=0
                          FOR qx = 102 TO 302 step 2
                          	'starting the loop. Stating loop is is going to be ran from 102 to 302. 'Step 2' defines the number to increase by after each loop.
                          	sum=sum+qx
                          	'equation that gets the value for each loop cycle(each QX) and eventually will add them together.
                          	lnum=lnum+1
                          	'equation that sets the first loop to 1. The second loop to 2. The third loop to 3, etc.
                          next
                          'goes to next part of loop(next QX).
                          message="The sum of the even numbers through the range 102-302 is: "+sum
                          message2="The number of times the code was iterated through the loop was: "+lnum
                          ui_msg_box("Jeb's Calculation",message +crlf()+message2)
                          Last edited by jeb richardson; 08-03-2011, 04:06 PM.

                          Comment


                            #28
                            Re: Programming Puzzle 1 - Simple Loop

                            Jeb, good try. Prof. Ignatious Pickypicky has several comments for your elucidation (his word, not mine!)

                            1) The pound symbol on the "Next" line throws an error. It doesn't belong.

                            2) The message box fails to display because the variables "message" and "message2" haven't been declared,
                            and OPTION STRICT is on.

                            3) The professor's eyes aren't what they used to be. Consider formatting your scripts so they're easier
                            to read. (Example below to give you some ideas).

                            4) It's not necessary to comment every line. Some things will always be obvious when you come back to
                            the script years later. Others will not. The latter is what must be documented / commented.

                            5) It's customary to indent lines inside a code block / loop structure.

                            Code:
                            [FONT=Courier New]OPTION strict		
                            
                            'recommend DIMing all vars at the top
                            dim sum as N		'defining sum variable as Number. Sum will be used to get the 
                            			'total sum of the even number through the range.
                            dim qx as N		'defining qx variable as Number. QX will be used as the loop.
                            dim lnum as N		'defining lnum variable as Number. Lnum will be used to get the 
                            			'total times the loop was done.
                            dim qx as N		'loop counter (index)
                            dim message as C 	'text string for message box
                            dim message2 as C	'ditto
                            
                            
                            sum=0		'giving the sum variable a value of zero.
                            lnum=0		'giving the lnum variable a value of zero.
                            
                            for qx = 102 to 302 step 2	'starting the loop. Stating loop is is going to be 
                            				'ran from 102 to 302. 'Step 2' defines the number 
                            				'to increase by after each loop.
                            
                            	sum=sum+qx	'equation that gets the value for each loop cycle(each QX) and 
                            			'eventually will add them together.
                            
                            	lnum=lnum+1	'equation that sets the first loop to 1. The second loop to 2. 
                            			'The third loop to 3, etc.
                            
                            next	'goes to next part of loop(next QX).
                            
                            dim message as C
                            dim message2 as C
                            
                            'assigning the total sum message for the pop up message.
                            message="The sum of the even numbers through the range 102-302 is: "+ltrim(str(sum))
                            
                            'assigning the total lnum or total times the loop was done, for the pop up message.
                            message2="The number of times the code was iterated through the loop was: "+ltrim(str(lnum))
                            
                            ui_msg_box("Jeb's Calculation",message +crlf()+message2)	'message box that gives 
                            					'the results of the calculation. LNUM and SUM[/FONT]
                            .

                            Comment


                              #29
                              Re: Programming Puzzle 1 - Simple Loop

                              Code:
                              OPTION strict
                              
                              dim first as N		'Starting number
                              dim last as N		'Ending number
                              dim total as N		'For final total
                              dim count as N		'To count the number of times this code is run, but it won't be that important as you will see.
                              
                              count = 0		'Starting counter at 0
                              
                              first = 102		'Starting point
                              last = 302		'Ending point
                              
                              total = ( ( first + last ) * ( last - first ) ) / 4
                              			'By adding in the first and last numbers I am figuring out a standard number for the math
                              			'and by subtracting the last and first from eachother, I am counting the total of the 
                              			'numbers between the first and last.  Since I am adding in both first and last numbers,
                              			'I only need to figure in half of those numbers, and since only even numbers are counted,
                              			'I need only half of those numbers still.  So I divide the total by 4.  
                              			'logically it should have divided the (last-first) before being multiplied, but the result is the same.
                              
                              count = count + 1	'Adding to the counter
                              
                              			'Results:
                              ui_msg_box( " Total" , total ,UI_ATTENTION_SYMBOL )	
                              
                              			'Number of times the formula had to be run:
                              ui_msg_box( "Times Run" , count , UI_ATTENTION_SYMBOL )
                              Admittedly I am cheating here by not using a loop.
                              Last edited by The Mage; 10-04-2011, 06:09 PM.

                              Comment


                                #30
                                Re: Programming Puzzle 1 - Simple Loop

                                As I am very new to xbasic my version to puzzle 1 is simple, but I believe it gets the job done.
                                Would appreciate any comments that may be needed or helpful.

                                Now to see if I can find Puzzle 2.

                                'Date Created: 09-Nov-2011 05:23:03 PM
                                'Last Updated: 10-Nov-2011 08:12:35 AM
                                'Created By : T. E. Reese
                                'Updated By : T. E. Reese
                                option strict

                                dim target_num as n = 0 'used to determine if number is even
                                dim i as n = 0
                                dim result as n = 0 'result adds the total of the even numbers
                                dim num_loops as n = 0 'counts the number of interations

                                for i = 302 to 101 step-2
                                num_loops = num_loops + 1
                                target_num = i
                                if mod(target_num,2)= 0 then
                                result=result+target_num
                                end if
                                next i

                                ui_msg_box("Program Puzzle One","The answeres are Sum = "+ alltrim(str(result))+" Loops = "+alltrim(str(num_loops)))

                                end

                                Comment

                                Working...
                                X