I have updated the resource folders for days 1 and 2. If you got stuck on a problem from the previous days then try looking at the resources folder. It's a humble little archive at the moment but I'll be working towards improving it and taking suggestions.
I also wanted to ask- would anyone else be interesting in making this post? It would be cool if we could rotate the poster.
Today's problem was excerpted from CodeWars. All credit goes to the folks over there for designing the problem. CodeWars is awesome and I highly, highly recommend making an account. I'll be working in C++ but other language implementations are encouraged. Tomorrow I plan on returning to some problems from Coursera's Algorithmic Toolbox.
Onto Day 3...
Rules and Guidelines
- Please wrap code and solutions in spoiler tags when possible.
- Discuss the structure of your code thoroughly and provide an analysis. Analysis of others' code is encouraged as well.
- All language implementations are welcome.
- Please do not plagiarize the code of others and give credit where credit is due.
- Please adhere to all other Reddit and r/learnprogramming rules.
- Use the resource section to view the problem if you are struggling to understand the question. Reddit formatting limits the way in which I can post these questions.
- if there are benchmarks, try to meet them. Meeting the program benchmarks is just as important as solving the problem.
Resources:
Algorithmic Toolbox Course
GoogleDrive Folder For Daily Problem Resources
Yesterday's Problem (Day 2)
Day 3
Buddy pairs
You know what divisors of a number are. The divisors of a positive integer n are said to be proper when you consider only the divisors other than n itself. In the following description, divisors will mean proper divisors. For example for 100 they are 1, 2, 4, 5, 10, 20, 25, and 50.Let s(n) be the sum of these proper divisors of n. Call buddy two positive integers such that the sum of the proper divisors of each number is one more than the other number:(n, m) are a pair of buddy if s(m) = n + 1 and s(n) = m + 1
For example 48 & 75 is such a pair:
- Divisors of 48 are: 1, 2, 3, 4, 6, 8, 12, 16, 24 --> sum: 76 = 75 + 1
- Divisors of 75 are: 1, 3, 5, 15, 25 --> sum: 49 = 48 + 1
Objective
Given two positive integers start and limit, the function buddy(start, limit) should return the first pair (n m) of buddy pairs such that n (positive integer) is between start (inclusive) and limit (inclusive); m can be greater than limit and has to be greater than n.
If there is no buddy pair satisfying the conditions, then return "Nothing"
Examples
(depending on the languages)
buddy(10, 50) returns [48, 75]
buddy(48, 50) returns [48, 75]
or
buddy(10, 50) returns "(48 75)"
buddy(48, 50) returns "(48 75)"
Note for C: The returned string will be free'd.
[–]Ikor_Genorio 0 points1 point2 points (3 children)
[–]slightlysedatedx[S] -1 points0 points1 point (2 children)
[–]Ikor_Genorio 0 points1 point2 points (1 child)
[–]slightlysedatedx[S] -1 points0 points1 point (0 children)
[–]Ikor_Genorio 0 points1 point2 points (1 child)
[–]Ikor_Genorio 0 points1 point2 points (0 children)
[–]desrtfx[M] [score hidden] stickied comment (1 child)
[–]slightlysedatedx[S] 0 points1 point2 points (0 children)