Testing your math and programming skills

Testing your math and programming skills

Math problems can easily be very hard. Finding some math programming tasks that are simple enough to be finished in a short time, yet interesting enough in the meantime is not that easy. Today I’ve found another one. Here it is:

Given two random balls on a snooker table, write an algorithm that will make one ball hit the other one after bouncing off twice from the sides of the snooker table. Mark down the trace that it should travel to make the hit.

There should be a bit of physics knowledge there (the rule in reflection), but to truly solve the problem beautifully, the math skill is a must.

To make it easy, the result is shown in text based. Suppose the snooker table is 80 by 60, so the snooker table, the balls and the trace should be drawn within a 80 by 60 characters space. Here are two examples:

##################################O#############################################
#                                O O                                           #
#                               O   O                                          #
#                               O   O                                          #
#                              O     O                                         #
#                             O       O                                        #
#                            O         O                                       #
#                           O           O                                      #
#                           O           O                                      #
#                          O             O                                     #
#                         O               O                                    #
#                        O                 O                                   #
#                       O                   O                                  #
#                       O                   O                                  #
#                      O                     O                                 #
#                     O                       O                                #
#                    O                         O                               #
#                   O                           O                              #
#                   O                           O                              #
#                  O                             O                             #
#                 O                               O                            #
#                O                                 O                           #
#               O                                   O                          #
#               O                                   O                          #
#              O                                     O                         #
#             O                                       O                        #
#            O                                         O                       #
#           O                                           O                      #
#           O                                           O                      #
#          O                                             O                     #
#         O                                               O                    #
#        O                                                 O                   #
#       O                                                   O                  #
#       O                                                   O                  #
#      O                                                     O                 #
#     O                                                       O                #
#    O                                                         O               #
#   O                                                           O              #
#   O                                                           O              #
#  O                                                             O             #
# O                                                               O            #
#O                                                                 O           #
O                                                                   O          #
O                                                                   O          #
#O                                                                   O         #
# O                                                                   O        #
#  O                                                                   O       #
#   O                                                                   O      #
#   O                                                                   X      #
#    O                                                                         #
#     O                                                                        #
#      O                                                                       #
#       O                                                                      #
#       O                                                                      #
#        O                                                                     #
#         O                                                                    #
#          O                                                                   #
#           X                                                                  #
#                                                                              #
################################################################################

and a partial one:

#############################O##################################################
#                         O    O                                               #
#                       O         O                                            #
#                    O              O                                          #
#                  O                   O                                       #
#               O                        O                                     #
#             O                             O                                  #
#          O                                  O                                #
#        O                                       O                             #
#     O                                            O                           #
#   O                                                 O                        #
#O                                                      O                      #
#O                                                         O                   #
#   O                                                        O                 #
#     O                                                         X              #
#        O                                                                     #
#          O                                                                   #
#             O                                                                #
#               O                                                              #
#                 X                                                            #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
...

Advertisements

One thought on “Testing your math and programming skills

  1. Pingback: Answer to the math programming question | SF-Xpt's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s