₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,030 members, 8,419,999 topics. Date: Thursday, 04 June 2026 at 09:09 AM

Toggle theme

Faucon's Posts

Nairaland ForumFaucon's ProfileFaucon's Posts

1 (of 1 pages)

ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 12:54pm On Nov 20, 2019
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):
xd, yd = coords[0] # Start
left = []
right = []
up = []
down = []

for x, y in coords:
if x < x0:
left.append((x, y))
elif x > x0:
right.append((x, y))
elif y > y0:
up.append((x, y))
else:
down.append((x, y))
left.sort(key=lambda(x, y): float(y - y0) / (x - x0)) # Sort by increasing slope
right.sort(key=lambda(x, y): float(y - y0) / (x - x0))
ordered_points = left + down + right + up
for i in range(n):
if ordered_points[i] == (xd, yd): # Found the entry
x, y = ordered_points[(i + 1) % (n + 1)]
return'%d %d' % (x, y)


x0, y0 = map(int, raw_input().split())
n = int(raw_input())
coords = []
for _ in range(n):
coords.append(map(int, raw_input().split()))

print(roundabout(x0, y0, n, coords))
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 5:41pm On Nov 19, 2019
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 ? tongue

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 + 0x10
print(b)
# result: 26
That'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))
# create two iterators, the second a character ahead of the first
left = iter(a)
right = iter(a)
next(right)
print(sum(g in '13579' and d in '13579' for g, d in zip(left, right)))
# result : 775


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

n = 0
i = 0
while i != 1000:
n += 1
if pyprimes.isprime(bin(n).count('1')):
i += 1
print(n)
# result : 1990


5. What is the biggest whole number strictly lower than 421337 that generates the longest Collatz conjecture?
def collatz_length(x):
cl = 1
while x > 1:
cl += 1
if x % 2 == 0:
x = x / 2
else:
x = 3 * x + 1
return cl


print(max((collatz_length(n), n) for n in range(1, 421338)))

collatz_length(421337)
# result : 410011
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 11:30am On Nov 19, 2019
Kaylhey20:
Thanks, @faucon .

I've received the payment.
Cheers
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 10:29pm On Nov 18, 2019
gbolly1151:
I really learn alot from this challenge let it keep coming @faucon
I'm glad you liked it. More to come soon...

But before that, I'll post my own answers with explanations tomorrow.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 10:27pm On Nov 18, 2019
Kaylhey20:
About an hour and 30 minutes, but the last one took the longest time.
I have replied your PM please check.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 7:29pm On Nov 18, 2019
Kaylhey20:
Thanks, @faucon.

I have updated it, but are the answers correct.
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.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 5:25pm On Nov 18, 2019
gbolly1151:
Here is my answers,i will be updating them as i will be solving them

I am coding in python

1.

def A_base_B(num):
num[0]=str(num[0])
AbaseB=0
for i in range(len(num[0])):
value=int(num[0][len(num[0])-(i+1)])*(num[1]**i)
AbaseB += value
return AbaseB

if __name__== '__main__':
a=[ '10' , 2 ] # 10 base 2
b=[ '10' , 8 ] # 10 base 8
c=[ '10' , 16 ] # 10 base 16

#collect the base numbers into a list

base=[ a,b,c ]

#result of addition of a,b,c
result=0

for i in base:
r=A_base_B(i)
result += r
print(result)


Output : 26

2. The answer is (a) UNIX timestamp system start with 1,January 1970 , all dates before that will result in negative value


3.

numbers = ' '
for num in range(1,1000):
numbers += str(num)

numbers=list(numbers)

point_count = 0
odd_num = 0

for odd in range(1,len(numbers)):
numbers[odd] = int(numbers[odd])
if numbers [odd] == 1 or numbers[odd]%2 == 1:
if numbers [odd - 1] == odd_num:
point_count += 1
odd_num = numbers [odd]

print(point_count)


Output: 775

4.
I am trying to analyze is this way, the 1st integer number with 1's as prime number in its binary is 3, the 2nd integer is 7

The this code will work for the 1000th integer



def prime(num):
if num > 1:
for i in range(2,num//2):
if (num % i) == 0:
return False
break
else: return True
else: return False

#target is the nth term of prime with 1's in its binary
def n_term(target=1):
binary = '0b'
count = 0
while count < target:
binary += '1'
deci=int(binary,2)
if prime(deci):
count += 1
return deci

print(n_term())



Got into an inifinite loop for valves greater than 8 on my PC

For output of 1st,2nd and 3rd integer The output are 3,7,31 respectively
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.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 11:26am On Nov 18, 2019
gbolly1151 and Kaylhey20 both of you are getting very close. But which of you would arrive first ? wink

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


#include <iostream>

// Define a generic STUB template
#define STUB(function_name) int function_name() { \
std::cerr << "FIXME: Finish " #function_name << std::endl; \
return -1; \
}

// Use our STUB template to define stubs for two functions
STUB(GetUserNum)
STUB(ComputeAvg)

int main()
{
// Calling one of the stubs
std::cout << "There are " << GetUserNum() << " users.";
return 0;
}
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 12:48pm On Nov 17, 2019
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.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 10:07pm On Nov 16, 2019
I was expecting more answers to be coming in right about this time, what's happening?
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 4:57pm On Nov 14, 2019
@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.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op):
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.

ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 11:34am On Nov 13, 2019
ANTONINEUTRON:
wen are u posting the first challenge
first challenge coming in less than an hour
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 11:45pm On Nov 12, 2019
stanliwise:
What's your aim?, why are we submitting codes to you? Why are you paying us?
To stimulate things here and ascertain people's approach to solving problems and reward occasionally. Perhaps scout for future projects I may have.
ProgrammingRe: Regular Programming Challenges With The Odd Money To Win by faucon(op): 6:29pm On Nov 12, 2019
stanliwise:
let me nor say anything.
no you have to say something now tongue
ProgrammingRegular Programming Challenges With The Odd Money To Win by faucon(op): 3:32pm On Nov 12, 2019
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.
TravelRe: My France Picture Gallery by faucon(m): 5:34pm On Oct 08, 2019
asiwajusirkay:
the cathedral is so gigantic, how did they manage to build this and other gigantic buildings in nantes... I guess those who built it were giants �
Lol you'd think so right? I to think most of these buildings go back to the early 14th century or even earlier
TravelRe: Securing Visa To France, Applying From Nigeria... by faucon(m): 5:07pm On Oct 08, 2019
NIFES:
Good morning all.
Please how can I make a group application for a mother and her daughter?
Your assistance will be highly appreciated .
Thank you.
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.
ProgrammingRe: What Does It Take To Develop An Ecommerce Site Like Ebay & Amazon by faucon(m): 3:10pm On Mar 29, 2017
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)