Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,953 members, 7,828,353 topics. Date: Wednesday, 15 May 2024 at 08:42 AM

Regular Programming Challenges With The Odd Money To Win - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Regular Programming Challenges With The Odd Money To Win (2368 Views)

Has Anyone Experienced Challenges With Data Migration During A Dynamics 365 Sale / Codewars.com Coding Challenges / New To Python, Gurus Please Help Solve These Challenges. Thanks. (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: Regular Programming Challenges With The Odd Money To Win by faucon(m): 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.

1 Like

Re: Regular Programming Challenges With The Odd Money To Win by Kaylhey20: 1:12am On Nov 19, 2019
Thanks, @faucon .

I've received the payment.

1 Like

Re: Regular Programming Challenges With The Odd Money To Win by gbolly1151(m): 7:18am On Nov 19, 2019
faucon:

I'm glad you liked it. More to come soon...

But before that, I'll post my own answers with explanations tomorrow.

Looking forward to that
Re: Regular Programming Challenges With The Odd Money To Win by faucon(m): 11:30am On Nov 19, 2019
Kaylhey20:
Thanks, @faucon .

I've received the payment.

Cheers
Re: Regular Programming Challenges With The Odd Money To Win by faucon(m): 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

1 Like

Re: Regular Programming Challenges With The Odd Money To Win by faucon(m): 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))
Re: Regular Programming Challenges With The Odd Money To Win by OutOfTheAshes(m): 10:13pm On Nov 21, 2019
Refactor your codes.

(1) (2) (Reply)

Anyone Currently Focusing On Data Structures And Algorithms? / Facial Recognition Using Matlab / I'm Tired Of Life

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 74
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.