Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

r/dailyprogrammer

members
online
Best
Open sort options
Change post view

Community highlights


[2023-05-19] Challenge #400 [Intermediate] Practical Numbers [2023-05-19] Challenge #400 [Intermediate] Practical Numbers

Background

Apractical number is a positive integer N such that all smaller positive integers can be represented as sums of distinct divisors of N. For example, 12 is a practical number because all the numbers from 1 to 11 can be expressed as sums of the divisors of 12, which are 1, 2, 3, 4, and 6. (Wikipedia.) However, 10 is not a practical number, because 4 and 9 cannot be expressed as a sum of 1, 2, and 5. For more detailed explanation and examples, seethis recent Numberphile video.

Challenge

Write a function that returns whether a given positive integer is a practical number.

practical(1) => truepractical(2) => truepractical(3) => falsepractical(10) => falsepractical(12) => true

You should be able to handle numbers up to 10,000 efficiently. The sum of all practical numbers up to 10,000 inclusive is 6,804,107. Test your code by verifying this value.

Optional bonus challenge

Consider the numbers X in the range 1 to 10,000 inclusive. The sum of all X such that 1019 + X is a practical number is 1,451,958. Find the sum of all X such that 1020 + X is a practical number. I found the sectionCharacterization of practical numbers in the Wikipedia article useful here.

I do not have any plans to resume posting here regularly. I just saw the Numberphile video and thought it would make a good challenge.


⚔️ Full Blown RPG in your browser: No Downloads ❌ Just Click and Go! ✅
⚔️ Full Blown RPG in your browser: No Downloads ❌ Just Click and Go! ✅

hero-wars.com
Play Now

[2021-07-19] Challenge #399 [Easy] Letter value sum [2021-07-19] Challenge #399 [Easy] Letter value sum

Challenge

Assign every lowercase letter a value, from 1 fora to 26 forz. Given a string of lowercase letters, find the sum of the values of the letters in the string.

lettersum("") => 0lettersum("a") => 1lettersum("z") => 26lettersum("cab") => 6lettersum("excellent") => 100lettersum("microspectrophotometries") => 317

Optional bonus challenges

Usethe enable1 word list for the optional bonus challenges.

  1. microspectrophotometries is the only word with a letter sum of 317. Find the only word with a letter sum of 319.

  2. How many words have an odd letter sum?

  3. There are 1921 words with a letter sum of 100, making it the second most common letter sum. What letter sum is most common, and how many words have it?

  4. zyzzyva andbiodegradabilities have the same letter sum as each other (151), and their lengths differ by 11 letters. Find the other pair of words with the same letter sum whose lengths differ by 11 letters.

  5. cytotoxicity andunreservedness have the same letter sum as each other (188), and they have no letters in common. Find a pair of words that have no letters in common, and that have the same letter sum, which is larger than 188. (There are two such pairs, and one word appears in both pairs.)

  6. The list of word{ geographically, eavesdropper, woodworker, oxymorons } contains 4 words. Each word in the list has both a different number of letters, and a different letter sum. The list is sorted both in descending order of word length, and ascending order of letter sum. What's the longest such list you can find?

(This challenge is a repost ofChallenge #52 [easy], originally posted byu/rya11111 in May 2012.)

It's been fun getting a little activity going in here these last 13 weeks. However, this will be my last post to this subreddit for the time being. Here's hoping another moderator will post some challenges soon!


[2021-07-12] Challenge #398 [Difficult] Matrix Sum [2021-07-12] Challenge #398 [Difficult] Matrix Sum

Example

Consider this 5x5 matrix of numbers:

123456789   752880530   826085747  576968456   721429729173957326   1031077599  407299684  67656429    965491941048156299  663035648   604085049  1017819398  325233271942914780   664359365   770319362  52838563    720059384472459921   662187582   163882767  987977812   394465693

If you select 5 elements from this matrix such that no two elements come from the same row or column, what is the smallest possible sum? The answer in this case is 1099762961 (123456789 + 96549194 + 663035648 + 52838563 + 163882767).

Challenge

Find the minimum such sum when selecting 20 elements (one from each row and column) ofthis 20x20 matrix. The answer is a 10-digit number whose digits sum to 35.

There's no strict runtime requirement, but you must actually run your program all the way through to completion and get the right answer in order to qualify as a solution: a program that will eventually give you the answer is not sufficient.

Optional Bonus

What's the smallest sum you can find forthis 97x97 matrix? It's okay to give a result that's not optimal in this case. If you want to prove that you found a certain sum, you can you post the indices of each element you selected from each row in order. For the 5x5 example, for instance, you could post[0,4,1,3,2].

(This challenge is a repost ofChallenge #67 [difficult], originally posted byu/oskar_s in June 2012. See that post for the formula to algorithmically generate the matrices if you prefer to do it that way.)



[8]
ページ先頭

©2009-2026 Movatter.jp