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 4 - A bug riddled riddle

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

  • Tom Cone Jr
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Very nice! Exceptionally succinct and efficient. Good work.

    Leave a comment:


  • jeb richardson
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Puzzle 4 Attempt.

    puz4.txt

    Leave a comment:


  • MoGrace
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Which is no doubt where I belong!

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Pratik, very nice!

    Robin, you've lost your seat in the front row of the class, and have been exiled to corner in the back of the classroom.

    Leave a comment:


  • MoGrace
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    I've never known a fly or a mosquito to fly anywhere at a consistent rate or straight path - so I swatted them both and therefore have no example to offer.

    Leave a comment:


  • pmanandhar
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    OK Prof. PickyPicky.. ' My professor who loves to take off points...

    Code:
            fly = 0               ' initialize variables
    	mosquito = 0
    	min = 1
    	
    	for i=1 to 9999                      ' 99 is any arbitrary number (should be at least 720- that's 12 mins )
    		fly = (1/360) + fly      ' 360 degress in a circle so to check the position after every second
    		if fly>1 then               ' check if fly completed on circle.
    		    fly=fly-1
    		end if
    		mosquito = (1/240) + mosquito   ' same logic as fly (above)
    		if mosquito>1 then 
    		    mosquito=mosquito-1
    		end if
    		if mod(i,60)=0           ' check their position after every min
    			ui_msg_box("After "+min+" minute:","Mosquito and Fly are at "+ltrim(str(mosquito * 360))+" and "+ltrim(str(fly * 360))+" (in degrees)position respectively.")  ' output in a message box
    			min=min+1
    		end if
    		if fly = mosquito then   ' check if their position is same
    		    ui_msg_box("Puzzle 4 solved","Finally they meet after: "+(i/60)+" minutes")
    		    exit for
    		end if
    	next
    This is the first time I used in code page in Alpha Five.. Thanks to all your rules and requirements...

    Watch out for student Stewie...
    Last edited by pmanandhar; 06-07-2011, 10:05 AM.

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Pratik, we'll be doing our puzzles and exercises using scripts that must run from the code page of the Alpha Five control panel (or from events occurring in a desktop application), not from a web page. I hope you will find them helpful and interesting even though not web based. ok?

    Leave a comment:


  • pmanandhar
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Thanks Lenny for your comment. I did had the code from an A5W page and ui_msg_boz() quite didn't worked so had to use "?".

    Leave a comment:


  • DaveM
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Your approach could be used by NASCAR to predict how long it might take one car to overtake another
    Nascar and many racers do that constantly. Given a known lap time for car a and and given lap time for car b, It is not hard to figure out, especially if you know how many 1000's of a secong car b is behind. BUT It is one thing to catch and another to pass. Remember, I won over 200 short track races.

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Here's my own solution:

    Code:
    'Date Created: 05-Jun-2011 03:50:20 PM
    'Last Updated: 05-Jun-2011 04:46:14 PM
    'Created By  : Tom Cone Jr
    'Updated By  : Tom Cone Jr
    '
    'Puzzle 4 - A bug riddled riddle
    '
    'Courtesy:  Creative Computing Magazine
    '
    'A fly and a mosquito start together to circle a building,
    'but the fly circles the building in six minutes, while
    'the mosquito circles the building in four.  How many
    'minutes will elapse before the faster mosquito passes 
    'the slower fly?
    
    
    ' Each trip around the building traverses a circle.
    ' Assume traveling in same direction.
    ' There are 360 degrees in a circle.  On each lap each
    '    bug travels through 360 degrees.
    ' On each trip around the building the position
    '    of each "bug" will range from 0 to 360.
    ' If we subtract 360 for each completed lap we can determine
    '    the current location on the 360 degree circle
    ' The mosquito will pass the fly when their
    '     positions on the "circle" (i.e. number of degrees)
    '     are the same.
    
    ' The int() function truncates the decimal portion of a number
    '     and returns the remaining integer.  We'll use it here
    '     to subtract 360 on each lap.
    
    Function Posn_Mosquito as N (min as N)
    	' This is a local function.  Can be located anywhere in the script.
    	
    	' Compute the current position of the mosquito on a 360 degree circle
    	' Return the answer as an integer, omitting (truncating) any decimals
    	'
    	' (min * 360 / 4) gives us the number of degrees traveled.  i.e.
    	'     4 min returns 360 degrees
    	'     8 min returns 720 degrees (twice around the circle)
    	
    	' int(min / 4) gives us the number of completed laps, i.e.
    	'     3 min returns zero
    	'     6 min returns 1
    	
    	' int(min / 4) * 360 gives us the number of degrees travelled in 
    	'     completed circles.  Knowing this permits us to subtract
    	'     the degrees in completed laps to find the position in the 
    	'     current lap
    	
    	Posn_Mosquito = int((min * 360 / 4) - int(min / 4) * 360)
    	
    end function
    
    Function Posn_Fly as N (min as N)
    	' Another local function.  The logic is the same as the previous.
    	' Formula adjusted because fly takes 6 minutes to travel 360 degrees.
    	' Function returns the current position of the fly on a 360 degree circle.
    	
    	Posn_Fly = int((min * 360 / 6) - int(min /6) * 360)
    	
    end function
    
    for i = 1 to 24		'arbitary range.  Limits set by experimentation.
    	' Let i be the number of minutes of flying time.
    	' Compute the current position of both bugs.  Stop when they are 
    	' at the same place on the circle.
    	
    	' Display results at end of each minute
    	trace.writeln("At the end of minute: " + ltrim(str(i))+" Mosquito position: " + ltrim(str(Posn_Mosquito(i)) + " Fly position: " + Posn_Fly(i)))	
    	if Posn_Mosquito(i) = Posn_fly(i) then
    	    exit for	'stop flying.  Mosquito has caught up to the slower fly.
    	end if
    next i
    
    ' Display the answer.  Notice the numeric variable "i" is converted to character data type
    '   before concatenated with other text.
    msgbox("Puzzle 4","It will take " + ltrim(str(i)) + " minutes for the mosquito to pass the fly.")
    end

    Leave a comment:


  • Mbuso
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    havent read Lenny F. in a while,,, big brother still watching i c :-)

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Thanks, Lenny.

    I'll approach the throne with no little trepidation, and gently inform Prof. Pickypicky that he's been spending too much time in desktop land. Pray for me.

    -- tom

    Leave a comment:


  • Lenny Forziati
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Originally posted by Tom Cone Jr View Post
    c) the "?" symbol is useful when coding in the Interactive Window, but it's not the correct way to write character strings to the trace window. Pickypicky is curious why the question mark is used here as the first character in several lines. You might check the help file for information on the trace.writeln() method. It's far more useful in scripts that will be running from the code page of your Alpha Five control panel.
    It looks like Pratik has posted code from an A5W page, based on the HTML tags included in the output. If that's the case, ? is the correct way to create the output, and the trace window is not accessible.

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    Thanks, Pratik.

    The source of all wisdom, our fearless scorekeeper, "Ignatious A. Pickypicky", offers the following comments & questions for your enlightenment:

    a) the Ui_msg_box() function call in line 27 throws an error. It's missing a required parameter.

    b) the absence of explanatory comments is noted. Tsk tsk. Pickypicky thinks you can do better. The logic in your For ... Next code block
    produces the correct result, but it's not clear why.

    c) the "?" symbol is useful when coding in the Interactive Window, but it's not the correct way to write character strings to the trace window. Pickypicky is curious why the question mark is used here as the first character in several lines. You might check the help file for information on the trace.writeln() method. It's far more useful in scripts that will be running from the code page of your Alpha Five control panel.

    Thanks for the submittal. Hope you enjoyed the puzzle.

    -- tom

    ps. I'll be posting my own solution later today. I hope Pickypicky is in a good frame of mind when he checks it out.

    Leave a comment:


  • pmanandhar
    replied
    Re: Programming Puzzle 4 - A bug riddled riddle

    I had similar idea to Peter but made some changes. I was wondering if we could use do..while loop so that we don' t have to do for i= 1 to 10000000000000 or some any number... I could do that in C programming but don't know here. I'm kinda new here... I should give credit to Peter as I used some of his code but added other things to make complete
    Code:
           ' defining all the variables
            dim fly as n = 0
    	dim mosquito as n = 0
    	dim i as n = 0
    	dim min as n = 0
    	fly = 0
    	mosquito = 0
    	min = 1
    	for i=1 to 9999             ' starting a loop to capture the position of both mosquito and fly at each second
    		fly = (1/360) + fly  ' position of fly after next second
    		if fly>1 then          
    		    fly=fly-1
    		end if
    		mosquito = (1/240) + mosquito
    		if mosquito>1 then 
    		    mosquito=mosquito-1
    		end if
    		if mod(i,60)=0      ' check if 1 min is passed
    			? "After "+min+" minute:<br/>"
    			?"Fly is at: "+ fly * 360 +"degrees from starting position<br/>"
    			? "Mosquito is at: "+ mosquito * 360 +"degrees from starting position<br/>"
    			min=min+1
    		end if
    		if fly = mosquito then   ' check if their position is same
    		    ? "<br/>Finally they meet after "+(i/60)+" minutes"
    		    exit for      ' if the pass then exit loop
    		end if
    	next
    Also, I have a question as to how can we get rid of decimal places in calculation. Like (1/3)*3 could be 0.999999 instead of 1..
    Last edited by pmanandhar; 06-06-2011, 03:05 PM.

    Leave a comment:

Working...
X