|
Post by bplus on Jun 18, 2024 23:31:21 GMT
What numbers between 1 and 1000 can NOT be expressed as the sum of consecutive integers? ie 15 = 7 + 8 18 = 5 + 6 + 7 so neither one of these are in the set of numbers that can NOT be expressed as a sum of consecutive integers. BONUS: one number can be expressed 15 different ways as a sum of consecutive numbers what is it and list the ways. ![:)](//storage.proboards.com/forum/images/smiley/smiley.png)
|
|
|
Post by bplus on Jun 20, 2024 18:13:41 GMT
no takers yet? two people have answered correctly on another forum.
hint: 1 + 2 + 3... + n = n(n+1)/2 so sum of first 100 pos integers = 100 * 101 / 2 = 50 * 101 = 5050
|
|
|
Post by bplus on Jun 21, 2024 8:50:14 GMT
1+2 = 3 2+3 = 5 3+4 = 7 ...
so all 2 consecutive number sums are odd.
1+2+3 = 6 2+3+4 = 9 3+4+5 = 12 ...
so every other 3 consecutive number sums are even = 3n n starts at 2
if 2 consecutive sums are even so likely then 4 consecutive sums 1+2+3+4 = 10 2+3+4+5 = 14 3+4+5+6 = 18 ...
yeah 2 consecutives already took out all these numbers
so what's interesting to us is sum of odd number consecutive integers
|
|
|
Post by bplus on Jun 24, 2024 17:05:42 GMT
if anyone takes a stab at this i will post my code solution for us to compare methods, so after you ![:)](//storage.proboards.com/forum/images/smiley/smiley.png)
|
|
Aaditya Parashar
Full Member
![*](//storage.proboards.com/forum/images/stars/star.png) ![*](//storage.proboards.com/forum/images/stars/star.png)
Just somebody with an abnormal coding routine.
Posts: 124
|
Post by Aaditya Parashar on Jun 25, 2024 4:47:17 GMT
What numbers between 1 and 1000 can NOT be expressed as the sum of consecutive integers? ie 15 = 7 + 8 18 = 5 + 6 + 7 so neither one of these are in the set of numbers that can NOT be expressed as a sum of consecutive integers. BONUS: one number can be expressed 15 different ways as a sum of consecutive numbers what is it and list the ways. ![:)](//storage.proboards.com/forum/images/smiley/smiley.png) By reading following posts, Even Numbers I think?
|
|
|
Post by bplus on Jun 25, 2024 14:02:05 GMT
the numbers that can not be expressed as a sum of cosecutive numbers are all even but 1 and there are only 10 of them from 1 to 1000.
reviewing my hints, i see that i mis-spoke here;
the sum of 2 consecutive numbers are always ODD (not even) so they take out all odd numbers after 1, ie 1 is the only odd number of the 10.
so since 2 consecutives are always odd 4 consecutive will always be even odd + odd = even
but 4 consecutive numbers leave holes, they don't cover all even numbers, 6 consecutive numbers take out a few more and 8 a few more. that gives me an idea to code what numbers do to 2, 3, 4, 5... consecutives take out first before a previous sum took out that number.
|
|
Aaditya Parashar
Full Member
![*](//storage.proboards.com/forum/images/stars/star.png) ![*](//storage.proboards.com/forum/images/stars/star.png)
Just somebody with an abnormal coding routine.
Posts: 124
|
Post by Aaditya Parashar on Jun 25, 2024 14:12:22 GMT
What numbers between 1 and 1000 can NOT be expressed as the sum of consecutive integers? ie 15 = 7 + 8 18 = 5 + 6 + 7 so neither one of these are in the set of numbers that can NOT be expressed as a sum of consecutive integers. BONUS: one number can be expressed 15 different ways as a sum of consecutive numbers what is it and list the ways. ![:)](//storage.proboards.com/forum/images/smiley/smiley.png) By the word 'consecutive integers', do you mean consecutive positive integers? If not then there wouldn't be any answer. I think some of them are 1, 2, 4, 8, I can't figure out many of them. Is this correct?
|
|
|
Post by bplus on Jun 25, 2024 14:19:58 GMT
consecutive means n, n+1, n+2, n+3...
and yes positive integers only
and yes 1, 2, 4, 8 does start the list, which is a sequence we should be quite familiar with from converting binary numbers but it would be nice to confirm in code that the sequence continues up through 1000.
one number is hit 15 times by different sets of consecutive numbers, what is it and all the ways consecutive add to it? (that was the bonus question)
|
|
Aaditya Parashar
Full Member
![*](//storage.proboards.com/forum/images/stars/star.png) ![*](//storage.proboards.com/forum/images/stars/star.png)
Just somebody with an abnormal coding routine.
Posts: 124
|
Post by Aaditya Parashar on Jun 26, 2024 8:05:17 GMT
The code, took a while to think though: $Console:Only DefLng A-Z Print "List of numbers which cannot be the sum of consecutive integers:["; For K = 1 To 1000 Count = 0 For I = 1 To 1000 Sum = 0 For J = I To K - 1 Sum = Sum + J If Sum >= K Then Exit For Next J If Sum = K Then Count = Count + 1 Next I If Count = 0 Then Print K; Next K Print "]" 'Loops to check the number which has 15 different possible 'SUM' combinations For K = 1 To 1000 Count = 0 For I = 1 To 1000 Sum = 0 For J = I To K - 1 Sum = Sum + J If Sum >= K Then Exit For Next J If Sum = K Then Count = Count + 1 Next I If Count >= 15 Then Number = K Next K Print "The number"; Number; "has 15 Combinations:" For I = 1 To 1000 Sum = 0 For J = I To Number - 1 Sum = Sum + J: If Sum >= Number Then Exit For Next J If Sum = Number Then C = C + 1 Print C; ":"; I; "+...+"; J; "="; Number End If Next I Somehow it works
|
|
|
Post by bplus on Jun 26, 2024 14:29:40 GMT
AP That's it, you got it!
here is my coded solution based on this equation the sum of m consecutives is m*n + m*(m - 1)/2 where n is start integer
_Title "Sums of consecutive numbers" ' find the numbers between 1 and 1000 that can not be expressed as a sum of a consecutive number.
' ie the sum of 2 consecutives is 2n + 1 from n + (n + 1) ' the sum of 3 3n + 3 from n + (n + 1) + (n + 2) ' the sum of 4 4n + 6 from n + (n + 1) + (n + 2) + (n + 3) ' the sum of 5 5n + 10 from n + (n + 1) + (n + 2) + (n + 3) + (n + 4) ' ... ' the sum of m consecutives is m*n + m*(m - 1)/2 $Console:Only Width 140 Dim numbers(1 To 1000) As Integer m = 2 n = 1 While m < 50 x = m * n + m * (m - 1) / 2 While x < 1001 'Print m, n, x, "zzz..." 'Sleep numbers(x) = numbers(x) + 1 n = n + 1 x = m * n + m * (m - 1) / 2 Wend m = m + 1 n = 1 Wend Print: Print "And the numbers that can not be expressed as a sum of consecutive integers are:" top = 1 For i = 1 To 1000 If numbers(i) > top Then top = numbers(i) If numbers(i) = 0 Then Print i; Next
' !!! result ONLY powers of 2 can not be a sum of consecutive numbers !!! Print: Print: Print "what numbers can be expressed"; top; "ways?" For i = 1 To 1000 If numbers(i) = top Then save = i: Print i, Next
' !!! result 945 is expressed 15 different ways !!!
Print: Print: Print "Here is the list of ways for consecutive numbers to sum to"; save consecSets (save)
Sub consecSets (n) For i = 2 To 50 o = n - i * (i - 1) / 2 If o Mod i = 0 And o > 0 Then count = count + 1 j = o \ i Print count; ":"; ts$(j); "+"; tot = j For k = 1 To i - 1 tot = tot + j + k If k = i - 1 Then Print ts$(j + k); " = "; ts$(tot) Else Print ts$(j + k); "+"; Next End If Next End Sub
Function ts$ (n) ts$ = _Trim$(Str$(n)) End Function
|
|