Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenges
#30
(06-18-2024, 10:42 PM)bplus Wrote: 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. Smile

Here's my method that I've started testing with:  
Code: (Select All)
SCREEN _NEWIMAGE(800, 600, 32)
DIM ConInt(100) AS STRING

FOR i = 1 TO 100
    FOR j = 1 TO 100
        match = CheckMatch(j, i)
        IF match THEN ConInt(i) = ConInt(i) + STR$(j)
    NEXT
NEXT

FOR i = 1 TO 34
    PRINT i; ")"; ConInt(i)
NEXT
FOR i = 35 TO 67
    LOCATE i - 34, 30: PRINT i; ")"; ConInt(i)
NEXT
FOR i = 68 TO 100
    LOCATE i - 67, 60: PRINT i; ")"; ConInt(i)
NEXT

FUNCTION CheckMatch (start, limit)
    sum = start: inc = start
    DO
        inc = inc + 1
        sum = sum + inc
    LOOP UNTIL sum >= limit
    IF sum = limit THEN CheckMatch = -1
END FUNCTION

Short.  Simple.  Gives me the starting point to the numbers that you can consecutively add to, to make that number.

For example, at 15 it returns:  "1 4 7"
1 + 2 + 3 + 4 + 5 = 15
4 + 5 + 6 = 15
7 + 8 = 15

I'm not finding any numbers that can be found 15 different ways though.  The most I can come up with is 5 different matches to make the same consecutive number.

Or are you talking about a number that can be made from a string of 15 values?  I don't think that's possible either, as 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11  + 12 + 13 = 91.  Add more to it, and it becomes out of bounds ( > 100)



Oooohhhh....   Nevermind.  I can't read.  The limit was 1000, not 100.  LOL!!  My bad!

Still, the solution I have above holds up for us.  The limits just need to be increased, and you need a larger screen to print them all on, if you want to view them all at once!   Big Grin
Reply


Messages In This Thread
Challenges - by bplus - 04-27-2022, 05:21 PM
RE: Challenges - by Pete - 04-27-2022, 05:33 PM
RE: Challenges - by bplus - 04-27-2022, 05:38 PM
RE: Challenges - by Pete - 04-27-2022, 06:00 PM
RE: Challenges - by bplus - 04-27-2022, 06:08 PM
RE: Challenges - by bplus - 04-28-2022, 01:17 AM
RE: Challenges - by Dav - 04-28-2022, 01:26 AM
RE: Challenges - by Pete - 04-28-2022, 01:59 AM
RE: Challenges - by bplus - 05-04-2022, 01:36 AM
RE: Challenges - by Pete - 05-04-2022, 01:51 AM
RE: Challenges - by bplus - 05-04-2022, 01:57 AM
RE: Challenges - by Pete - 05-04-2022, 02:22 AM
RE: Challenges - by bplus - 05-04-2022, 04:10 PM
RE: Challenges - by bplus - 06-18-2022, 01:10 PM
RE: Challenges - by SierraKen - 06-18-2022, 11:32 PM
RE: Challenges - by bplus - 06-19-2022, 01:09 AM
RE: Challenges - by bplus - 03-26-2024, 11:37 PM
RE: Challenges - by CharlieJV - 03-30-2024, 12:02 AM
RE: Challenges - by SMcNeill - 03-27-2024, 12:20 AM
RE: Challenges - by SMcNeill - 03-27-2024, 12:32 AM
RE: Challenges - by bplus - 03-27-2024, 01:24 AM
RE: Challenges - by bplus - 03-30-2024, 02:53 PM
RE: Challenges - by CharlieJV - 03-30-2024, 03:39 PM
RE: Challenges - by bplus - 03-31-2024, 01:33 PM
RE: Challenges - by Petr - 03-31-2024, 02:00 PM
RE: Challenges - by SMcNeill - 03-31-2024, 02:18 PM
RE: Challenges - by Petr - 03-31-2024, 02:23 PM
RE: Challenges - by bplus - 03-31-2024, 03:28 PM
RE: Challenges - by bplus - 06-18-2024, 10:42 PM
RE: Challenges - by SMcNeill - 06-19-2024, 04:32 AM
RE: Challenges - by SMcNeill - 06-19-2024, 04:45 AM
RE: Challenges - by KingLeonidas - 06-19-2024, 09:42 AM
RE: Challenges - by bplus - 06-19-2024, 01:59 PM
RE: Challenges - by bplus - 06-21-2024, 07:31 PM
RE: Challenges - by bplus - 06-23-2024, 03:07 PM



Users browsing this thread: 1 Guest(s)