Faucon's Posts
Nairaland Forum › Faucon's Profile › Faucon's Posts
1 (of 1 pages)
Problem For absurd reasons, Dayo must take the first exit on the right each time his car arrives at a roundabout. You are given the coordinates of the roundabout, and a list of coordinates representing the different destinations of the roundabout's exits. The car arrives at the roundabout from the first of these destinations in the list. Write a function that returns the coordinates of the exit destination that corresponds, from Dayo's point of view, to the first exit of the roundabout. Clarifications The statement of this problem appears to have caused some confusion. One may have thought that the configuration of the roundabout was fixed to that described by the drawing. Perhaps others did not understand what "the first right" meant? In fact, it had to be understood that the problem involved a "star" geometric figure, which contained: - a centre point R (the roundabout), an entry point E, and exit points Pi; these points are given as input and vary from one test to another; - segments [RE] and [RPi] (where i is between 1 and the number of exits). You had to find the point Pi such that the exit segment [RPi] was the closest to the right of the entry segment [RE], that is to say it was necessary to minimise the oriented angle ^ERPi This being a geometry problem involving angles, it might be expected that trigonometry would be required to calculate angles. It is not so. A first step could be to divide all the points among four lists according to their position in relation to the roundabout (left, down, right or up, see image attached). Note that there can be a maximum of just one point exactly above the roundabout because two roads never overlap. Same for below. We note then that to list them in an anticlockwise manner, we can consider them by increasing slope within the same class. Thus, in the right class of the attached image, the slope of the line passing through the roundabout and (3,2) is (2-1)/(3-1) = 1/2 while the slope of the line passing through the roundabout and (2,-1) is (-1-1)/(2-1) = -2. So (2,-1) is before (3,2) in a counterclockwise order. Similar reasoning applies to the left class. Once the left and right classes are sorted (the other two do not need to be sorted because they contain at most one element), we get all the points in order by considering the points to the left, then below, then to the right, then above. It only remains to determine where the entry is and return the next vertex (so plus 1 modulo n + 1 in case the entry would be at the end of the list of n + 1 points) In Python def roundabout(x0, y0, n, coords): |
I think this first challenge was a success. Thanks to everyone who participated and congrats to the winner Kaylhey20. More people should participate in the upcoming ones. Seeing as man like Kaylhey20 completed this challenge in less than 2 hours perhaps I should revise the difficulty going forward ? ![]() I would answer it in 2 posts, first the quiz section and then the problem section. I will use Python to answer all questions Quiz 1. We denote "A in base b": Ab. What is the result, in base 10, of 102 + 108 + 1016? Note only the value in base 10, without specifying the base. Answer: This question is intended to warm your fingers to put you in a good position to attack the following exercises. This was meant to be a simple 1-2 line(s) solution but you guys went above what I expected and that's great. b = 0b10 + 0o10 + 0x10That's it, I used the Python notations for base 2 (0b), 8 (0o) and 16 (0x) and we read the answer in base 10: 26 2. Which of these dates cannot be represented using a timestamp on a UNIX system? a. 2 March 1969 b. 2 December 1970 c. 13 January 1997 d. 25 August 1991 e. I don't know Answer: The correct answer is 2 March 1969. Indeed, a timestamp is a positive integer representing the number of seconds elapsed between January 1, 1970 at midnight UTC and the date to be represented. 3. If you write all the numbers from 1 to 999 in a row by separating the numbers by points (1.2.3.4.5.6.7.8.9.1.0.1.1.1.2 ...), how many points will be immediately surrounded by odd numbers? a = ''.join(str(i) for i in range(1, 1000)) 4. What is the 1000th integer that has the number of 1's as a prime number in its binary representation? Reminder: 1 is not first. The number 1 in the binary representation is also called the Hamming weight, or also the population count. An integer whose population count is a prime number is called a pernicious number. The list of pernicious numbers is available in the encyclopedia of integer sequences online under the reference http://oeis.org/A052294 . A Python solution using the pyprime library looks like this: import pyprimes 5. What is the biggest whole number strictly lower than 421337 that generates the longest Collatz conjecture? def collatz_length(x): |
Kaylhey20:Cheers |
gbolly1151:I'm glad you liked it. More to come soon... But before that, I'll post my own answers with explanations tomorrow. |
Kaylhey20:I have replied your PM please check. |
Kaylhey20:Congratulations, you're the first to answer all the questions correctly. How long did it take you to answer all the questions? I will PM you for your £50 prize. |
gbolly1151:Your approach to the 4th question is not correct. To help you out a bit the sequence is 3,5,6. Refactor your code a bit and use print statements to see where you're going wrong. That's all I can say for now. |
gbolly1151 and Kaylhey20 both of you are getting very close. But which of you would arrive first ? ![]() Kaylhey20 use the hashtag sign to format your code properly or write your code inside "["code"][\code]" (remove quotes) It would come out like this
|
No one is late to the party still. Also with the new info I have got, I have decided to extend the deadline to November 20. I'll update the main post. |
I was expecting more answers to be coming in right about this time, what's happening? |
@ANTONINEUTRON Good going man on being the first to show some result. Don't throw in the towel yet. 1. It's not correct. Please look at the bases for each number. Sorry I didn't format it correctly at first. Also pay attention to the curly brackets, I had to restructure them before running your code. 2. You're right but care to tell us why? 3. It's not correct 4. I'm asking for the 1000th integer that has the number of 1's as a prime number in its binary representation. 5. Your approach is not entirely wrong but you're incorrect. You're close though. 6. Yeah sure. I'm also quite interested to see how people will solve it. I used a naive approach and probably someone may come up with something better. |
First Challenge Please post all the answers to the questions in one go, it will be easier for me and everyone else to go through and will avoid having to collate pieces of your answers in the thread. Only the second question under Quiz doesn’t require you to code your answer. As for which programming language to use, preferably C, Java or Python but you’re free to use whichever you’re comfortable with. There is only 1 winner. First to get all answers correctly before November 20 by 23:59 PM wins £50. I’ll send it to the winner’s PayPal account if they have one or the equivalent in Naira to their Nigerian account. Quiz 1. We denote "A in base b": Ab. What is the result, in base 10, of 102 + 108 + 1016? Note only the value in base 10, without specifying the base. 2. Which of these dates cannot be represented using a timestamp on a UNIX system? a. 2 March 1969 b. 2 December 1970 c. 13 January 1997 d. 25 August 1991 e. I don't know 3. If you write all the numbers from 1 to 999 in a row by separating the numbers by points (1.2.3.4.5.6.7.8.9.1.0.1.1.1.2 ...), how many points will be immediately surrounded by odd numbers? 4. What is the 1000th integer that has the number of 1's as a prime number in its binary representation? Reminder: 1 is not first. 5. What is the biggest whole number strictly lower than 421337 that generates the longest Collatz conjecture? Problem Subject Dayo's car has a technical problem: his right turn signal is constantly working, impossible to stop. Wanting to respect the rules of the road, he decides to always take the first right. Being equipped with a state-of-the-art car model with an integrated navigation assistant, Dayo asks you to write an application that tells him which direction to take when he arrives at a roundabout. You are given the coordinates of the roundabout, and a list of coordinates representing the different destinations of the roundabout exits. The car arrives at the roundabout from the first of these destinations in the list. Write a function that returns the coordinates of the destination of the exit that corresponds, from Dayo's point of view, to the first exit of the roundabout. Input The Input will include: • on the first line, the X, Y coordinates of the roundabout, separated by a space; • on the second line, the number N of exits on the roundabout; • on the third line, the coordinates X1, Y1 of the part of the road in which the car arrives, separated by a space; • on the following N - 1 lines, the coordinates Xi, Yi of the destinations of each of the exits, separated by a space. Output You will display in your output: • the coordinates of the destination of the exit corresponding to the first exit of the roundabout. Constraints • 2 ≤ N ≤ 10,001; • each coordinate is a whole number and between -10,000 and 10,000; • the coordinates all lead to different directions: the roads (the right segments from the roundabout to their destinations) do not overlap. Runtime constraints Maximum memory usage: 5000 kilobytes Maximum execution time: 500 milliseconds Input/output samples Sample input 1 1 4 1 0 1 2 0 1 2 1 Sample output 2 1 Note Refer to image.
|
ANTONINEUTRON:first challenge coming in less than an hour |
stanliwise:To stimulate things here and ascertain people's approach to solving problems and reward occasionally. Perhaps scout for future projects I may have. |
stanliwise:no you have to say something now ![]() |
I want to use this as a medium to be posting regular programming challenges to stimulate our brains and just for fun. Perhaps you can use this as an opportunity to improve your problem-solving skills and to improve your skills in an existing or a new programming language. To spice things up, occasionally there will be challenges with deadlines in which money can be won. There can only be 1 winner and it will be the first person to answer all the problems in the challenge correctly. You’ll receive the money through PayPal or bank transfer You can submit your answers in any programming language but obviously I’d prefer C, Java or Python only because it’s easier for me. I will be publishing the first set of challenges once I’m done finalising the questions. This one will have somebody winning £50 if the correct answers are put forward within 5 days. Before I send out the first challenge, I’d give some time to answer any questions or provide more clarifications if required. |
asiwajusirkay:Lol you'd think so right? I to think most of these buildings go back to the early 14th century or even earlier |
NIFES:You can't quite do that online. Just make sure when do visit VFS, you make them aware it's for a mother and daughter. |
Research Go back to the drawing board and start with a business plan in step-by-step detail. Study everything you can get your hands on regarding this business model. Practice and experiment with both the modeling styles of Ebay and Amazon...what I mean is, learn to buy and sell on both platforms and take notes of your successes and failures each and every one. Sleep with these two 24/7/365...dream, practice, study...and never let anyone tell you it's an impossible endeavor...because it's not! Development Start with an MVP A version that just has enough functionality so you're able to launch it to your first users. You should try to eliminate as much waste as possible, both spending lots of money and spending lots of time before the launch are forms of waste. Choose between using a CMS or starting from scratch. For CMS, you can go with Drupal, Magento or WordPress. Start with a CMS first as it's takes less time to develop, once you have lots of money (could be through revenue or investor), you should redo the website from scratch using any web tech ie. Python with Django, Ruby with rails, JavaScript framework. Issues you might face The biggest issue with a site the size of Amazon/Ebay is just the sheer size of things. Writing a website that can scale to the number of users who are simultaneously connecting to the site is a major technical challenge in its own right. On top of that you'll need to know how to write code that can scale in terms of being able to add new features without breaking stuff etc... You would need a large team of very skilled and very experienced programmers a long time and a lot of money to make, but don't worry by this stage you should have lots of it. |
1 (of 1 pages)

