Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,495 members, 7,823,158 topics. Date: Friday, 10 May 2024 at 04:55 AM

A Thread For Competitive Programming - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / A Thread For Competitive Programming (1836 Views)

Competitive Programming / Thread For Competitive Programming / A Thread For Tutorial On Python Programming (2) (3) (4)

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

Re: A Thread For Competitive Programming by logicDcoder(m): 8:49pm On Feb 01, 2021
Question 1 and 3 Solved

Observation: Only even numbers can be perfect!

SUPREMOTM 404Dev iAmChidiebere mention others please!

1 Like

Re: A Thread For Competitive Programming by SUPREMOTM: 4:26pm On Feb 02, 2021
QUESTION 1
LANGUAGE JavaScript
IDE: Visual Studio Code



Since no factor of a number can be greater than half of the number, besides itself, I made the loop control variable have a maximum value of half the number.

So as to be able to test the function with valid perfect numbers, I had to also create a function that gets all the perfect numbers from 1 to 100000, the function returned 4 numbers.

The results of the tests are displayed on Chrome browser console window.

1 Like

Re: A Thread For Competitive Programming by logicDcoder(m): 10:04pm On Feb 02, 2021
SUPREMOTM:
QUESTION 1
LANGUAGE JavaScript
IDE: Bracket



Since no factor of a number can be greater than half of the number, besides itself, I made the loop control variable have a maximum value of half the number.

So as to be able to test the function with valid perfect numbers, I had to also create a function that gets all the perfect numbers from 1 to 100000, the function returned 4 numbers.

The results of the tests are displayed on Chrome browser console window.

I really learnt something here kudos boss!
Re: A Thread For Competitive Programming by Excallibur(m): 12:22am On Feb 03, 2021
number 1 in python

Re: A Thread For Competitive Programming by iAmChidiebere: 6:52am On Feb 03, 2021
logicDcoder:
[Week 2 Questions]

1: In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number. Write a function | isPerfectNumber( ) | that checks if a number is a perfect number or not return True if it's a perfect number and False if it's not.
https://en.wikipedia.org/wiki/Perfect_number

2: Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper divisors of 6 are 1, 2, and 3.) A pair of amicable numbers constitutes an aliquot sequence of period 2. It is unknown if there are infinitely many pairs of amicable numbers.
Simple Example : (220,284) 220 is divisible by {1,2,4,5,10,11,20,22,44,55,110 } <- Sum = 284 and 284 is divisible by -> 1,2,4,71,142 and the Sum of that is. Yes right you probably expected it 220. Write a function (AmicableNumbers(int startValue, int StopValue) ) that finds all the amicable numbers in the range Start-value -> Stop-value and also time the function inother to know the time it took to find the pairs of numbers!

https://en.wikipedia.org/wiki/Amicable_numbers

3: Spice up Number 1 question by finding the Odd, Even and Prime perfect numbers in a custom range example: 1 -> 1000, 1000 -> 3000. What do you observe?
Honorable Mentions: SUPREMOTM iAmChidiebere 404Dev
GOOD LUCK!


Question 1.
Python

Re: A Thread For Competitive Programming by iAmChidiebere: 7:12am On Feb 03, 2021
Question 2
Java

1 Like

Re: A Thread For Competitive Programming by iAmChidiebere: 7:20am On Feb 03, 2021
SUPREMOTM:
QUESTION 1
LANGUAGE JavaScript
IDE: Bracket



Since no factor of a number can be greater than half of the number, besides itself, I made the loop control variable have a maximum value of half the number.

So as to be able to test the function with valid perfect numbers, I had to also create a function that gets all the perfect numbers from 1 to 100000, the function returned 4 numbers.

The results of the tests are displayed on Chrome browser console window.
Nice one boss!... used same thought.
Re: A Thread For Competitive Programming by iAmChidiebere: 7:21am On Feb 03, 2021
logicDcoder:
Question 1 and 3 Solved

Observation: Only even numbers can be perfect!

SUPREMOTM 404Dev iAmChidiebere mention others please!
Nice one guy.
Re: A Thread For Competitive Programming by iAmChidiebere: 7:22am On Feb 03, 2021
Number 3....
when nepa brings light
Re: A Thread For Competitive Programming by iAmChidiebere: 7:26am On Feb 03, 2021
Excallibur:
number 1 in python
Nice bro... Can be more efficient though

1 Like

Re: A Thread For Competitive Programming by Excallibur(m): 10:33am On Feb 03, 2021
iAmChidiebere:

Nice bro... Can be more efficient though
Thanks bro

1 Like

Re: A Thread For Competitive Programming by logicDcoder(m): 12:03pm On Feb 03, 2021
iAmChidiebere:
Question 2
Java
Kudos boss!

1 Like

Re: A Thread For Competitive Programming by logicDcoder(m): 12:04pm On Feb 03, 2021
iAmChidiebere:
Number 3....
when nepa brings light
I can't wait ooo
Re: A Thread For Competitive Programming by iAmChidiebere: 4:38pm On Feb 03, 2021
logicDcoder:

I can't wait ooo
In a bit boss
Re: A Thread For Competitive Programming by iAmChidiebere: 6:06pm On Feb 03, 2021
iAmChidiebere:
Number 3....
when nepa brings light
Python
1st image: Redundant comments for the sake of newbies
2nd image: Reduced comments. More tidy
3rd image: Execution


Cc: logicDcoder

1 Like

Re: A Thread For Competitive Programming by SUPREMOTM: 12:12am On Feb 04, 2021
QUESTION 2
LANGUAGE: Javascript
IDE: Visual Studio Code
Chrome browser console is used to test the function.


1. First, I create a while loop with values ranging from the the lower parameter to the higher parameter of the function.

2. For each of the values of the control variable in the while loop, I get the sum of its factors (otherNumber); then I reverse the process immediately (I get the sum of the factor of otherNumber (testForAmicability) and check to see if it is equal to the loop control variable(startValue)).

3. If the test performed in 2 above shows the two numbers are equal, I append the two values to the return value of the function (AmicableResult);

4. I increment the loop control variable by 1 and repeat the steps (2 and 3 above).

Re: A Thread For Competitive Programming by SUPREMOTM: 12:14am On Feb 04, 2021
QUESTION 1
LANGUAGE: C#
IDE: Visual Studio

Pseudocode: Mostly same as for JavaScript

I created a function GetPerfectNumbers( ), so as to have an idea of the numbers that should return true.

I created a function IsPerfectNumber( ) that takes the number to test as an argument. If the test number is a perfect number, it returns true.

I made it into a desktop application, so, after several test numbers are typed in a textbox, separated by commas and the button is clicked, the boolean values representing the return value of the function for each of the numbers is displayed beside the number.

Re: A Thread For Competitive Programming by SUPREMOTM: 12:18am On Feb 04, 2021
QUESTION 2
LANGUAGE: C#
IDE: Visual Studio

Pseudocode: Mostly same as for JavaScript

Whenever the button is clicked, the function AmicableNumbers( ) is invoked and the list of amicable numbers in the specified range is written to a notepad file on my desktop.

Re: A Thread For Competitive Programming by logicDcoder(m): 4:07pm On Feb 04, 2021
iAmChidiebere:

Python
1st image: Redundant comments for the sake of newbies
2nd image: Reduced comments. More tidy
3rd image: Execution


Cc: logicDcoder
Nice one boss. grin
Re: A Thread For Competitive Programming by iAmChidiebere: 7:36pm On Feb 04, 2021
logicDcoder:

Nice one boss. grin
Thanks boss
Re: A Thread For Competitive Programming by logicDcoder(m): 8:01am On Feb 05, 2021
Week 2 -> Bonus Problem:
Honorable Mentions: SUPREMOTM iAmChidiebere 404Dev Excallibur

Re: A Thread For Competitive Programming by iAmChidiebere: 2:12pm On Feb 05, 2021
logicDcoder:
Week 2 -> Bonus Problem:
Honorable Mentions: SUPREMOTM iAmChidiebere 404Dev Excallibur
PYTHON

Pseudo-code

Check if the acc balance is enough to make 1 minute of call.
If it can't, return 0.
Otherwise, set the number of minutes to 1 and subtract the call rate from the acc balance

Next, check if the money left in the acc balance can make up to 9 minutes of call, using the call rate for 2nd to 10th minute.
If it can't, check how many minutes it can then make, add it to the number of minutes, and then, return the summed value.
Otherwise, increase the number of minutes by 9, and then subtract the call rate for 9 minutes from the acc balance.

Next, use the call rate for 11th minute and above to get the amount of minutes that the remaining acc balance can make and add it to the number of minutes previously calculated.
Return the summed value.

Re: A Thread For Competitive Programming by SUPREMOTM: 10:19pm On Feb 05, 2021
Week2 Bonus Question
Language: Javascript
Google Chrome console is used for testing the function.

First calculate the amount of money needed to make calls for 10 minutes, store it in a variable, cost10.

After that, there are only 2 conditions to check for in this order.

1. Is your account balance greater than cost10? If yes, the time is (your balance minus cost for first 10 minutes divided by the charges for 11th minute and above) plus 10. ==>time2

2. Is your account balance greater than or equal to the cost for a minute of call? If yes, the time is (your balance minus cost for 1st minute divided by the charges for 2nd to 10th minute) plus 1. ==>time1

If it doesn't satisfy any of the two conditions above, you have 0.

(1) (2) (Reply)

C# Programmer's Club / Thread closed. / Nairaland Programming Contest (8-Puzzle)

(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. 32
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.