9
kiki
1y

And you’re here wasting your time on storypoints and unit tests

Comments
  • 13
    Of course it will terminate for every input.

    1) The Collatz problem is about n > 0 only, but n <= 0 will be caught in the while condition and terminate right away.

    2) All starting values up to 2^68 have been tested (as of 2020 btw.) to converge to the final 4,2,1 cycle, thus hitting the termination condition. Meanwhile, the int data type is at least 16 bits, usually 32 bits, but even long long int with 64 bits would be covered.
  • 1
    It might be different if an implementation went for int as 128 bits, but that doesn't exist and won't exist because int with more than 32 bits would run into trouble how to define the C99+ portable data types.

    int as 32 bits allows int8_t as typedef with signed char, int16_t as short int, and int32_t as int. int with 64 bits or more would leave a definition hole here.
  • 1
    @Fast-Nop and also the conjecture is most probably converging for any positive integer anyway.
  • 1
    @iiii That's the part that is proven only for up to 2^68 (or more since 2020), not for the general case.
  • 1
    @Fast-Nop empirically proven, yes. There's no general proof, but the trend is quite obvious.

    Though there are interesting examples of conjectures which seem to be stable for some input but behave quite different for other inputs.
  • 7
    @iiii Cf. the "turkey fallacy" where the turkey reaches the maximum of feeling safe right before Thanksgiving, and then it will get butchered.
  • 1
    Wouldn't it throw an out of range exception in modern implementations of c ?

    There was a time I remember if you added 1 to int.max you got int.min...

    In some language.
  • 0
    Oh goddamn
    Please something new !!!!
  • 2
    @AvatarOfKaine C doesn't have exceptions, and while signed integer overflow is undefined behaviour, the compiler won't be able to use this to optimise the loop condition away, given that negative values might be passed to the function.

    If you get an overflow, that would make the Collatz calculation incorrect, but the question was only whether the program terminates.
  • 3
    I tried it and it takes 15 min to finish all numbers until maxint (2³¹)
  • 2
    @Fast-Nop well it seems like there would be specific cases where it would.

    what is the behavior of 3*int.max +1 ?

    does it suddenly become a number in a different part of the positive range or does it end up as int.min ?

    if thats the case it terminates.

    if the number passed is negative, it terminates.

    that's just my quick analysis of it.

    if the language in question does not do range checking some programming languages i remember if you say have a signed word value...

    so its range is something like -32512 to 32512 if you add 1 to 32512 in something like good old fashion borland pascal IF I REMEMBER, it ends up yielding -32512.

    I don't know the multiplicative behavior.

    I think answering this question in the case of c is knowing how the internal behavior of numbers is built into the finished native product. or even maybe in assembler.

    what happens when you add 1 to 255 or do a mul 3 on a register containing 255 ?
  • 0
    @Fast-Nop i mean i'm just thinking aloud.

    see. it kind of matters the internal behavior.

    if you wrote this in c# you'd get an exception.
  • 2
    @AvatarOfKaine Interesting point. The main issue here is that int is used, not unsigned int. It might indeed be that a signed int multiplication with overflow could yield a wrong, but still positive number. That would depend on what exactly the underlying CPU is doing.
  • 0
    @Fast-Nop you know, i just made an idiotic point.

    i totally didn't look at the code.
  • 0
    @Fast-Nop you need to consider the behavior where maxmimum values are concerned.

    but if even negative or even or 0 it always terminates.

    the only leftover question is what happens when it receives a value like 1/3*int.max
  • 0
    @cafecortado and the results ?
  • 0
    this is something that kind of pisses me off actually.

    if i were actively on the job i'd usually spot something like i just said.

    but if not i do what i sometimes do and scan over things without thinking.
  • 0
    and yeah i know i know this was already posted.
  • 0
    also out of curiosity i looked it up.

    that isn't actually what collatz conjecture seems to be about, because of the while loop condition.

    its n!=1
  • 0
    thanks for the priming technique.
  • 0
    almost like it was made for the overconfident programmer to have him skim over quick, say that's stupid, look at it again after making a half valid point, feel stupid, and look closer then compare the code to the article on something noone ever heard of and say OH AND HEY, THERE'S A CODE ERROR.
  • 0
    anddddd REDEMPTION lol eg self esteem protection.
  • 0
    I'm reading this and i don't see why.

    also it doesn't say anything about only positive integers, it can be handed negative too which would make sense given the 3n+1

    ... except no i was right the first time it wouldn't...

    -1 * 3 = -3+1=-2/2=-1.....

    ugghhhhhh take my pain away.
  • 1
    @AvatarOfKaine The Collatz conjecture is that all starting values eventually end up in the 4,2,1 cycle, and the termination condition checks for 1.
  • 0
    @Fast-Nop yeah it would seem to be true.

    are people still debating this ?
  • 1
    @Fast-Nop yeah you mean eventually after you apply the two operations enough you either end up with a 4 or a 2 and that divides in 2 to be 1 right ?
  • 0
    @AvatarOfKaine Correct, so the termination condition basically is the Collatz conjecture.
  • 0
    @Fast-Nop you know i'm sitting here rereading our interactions.

    and i'm thinking.

    i have had no opportunity to really do anything that isn't pointless in so many years.

    everything costs money that would provide me with novel experience and people steal everything that matters from me.

    photos, reminders of emotions and things i found interesting, mercilessly just stolen.

    they drive everyone crazy.

    its a paradox really.

    on one hand stifling creativity and reducing the things released doens't create a haystack but it also stops our culture in its tracks, while people being allowed to rewrite things to make it about some trashy numeric culture programs people neurologically thus limiting individuality.

    what's the point ?

    I would think travel and personal growth would be important but they started robbing me of every creative attempt i ever made, which has to be practiced to be better.
  • 0
    @Fast-Nop i just don't understand because we're all going to die. we're all going to get old, why make pockets of depravity and degeneration and why trap me with it ?

    I hate these creatures.

    I hate people who select things just to make some stupid consistent numeric repetition.
  • 0
    @Fast-Nop it is however laughable that people would choose specific combinations over and over again and think they were speaking in a secret code or shielding themselves from consequence.
  • 0
    @AvatarOfKaine no results, I just executed the above function like it was a black box XD.
    But yes, the overflow happening there will surely cause bad results for many input numbers
  • 0
    like there favorites.

    42

    22

    23

    21

    20

    13

    14

    17

    16

    7

    9

    5

    4

    1

    6
  • 0
    or doubled entries like

    2020

    0790

    0360
  • 0
    and the ones they're afraid of like 19
  • 0
    @Fast-Nop hey... hey...

    BROWN RED BROWN ON TOP OF A GRAY BACKGROUND RUN PEON RUN !
  • 0
  • 0
    *points with his right finger at you both and a gleam in his eye and stamps his right foot* lmmfao
  • 0
    Don't actually do whatever that bullshit means btw
  • 0
    Anyway point is
    This is an example
    Take something vague
    Make some strangely likely illogical point in some weird symbolic way
    It's what they were frequently doing because they trained certain people to go crazy to a ten digit numeric code
  • 0
    Which really is nonsensical

    And creates nothing but confusion until personal bias solidifies reactions and actions into predicable cyclical crazy behavior
  • 0
    I don't think this idiot shit was supposed to be adapted into a lifestyle

    I don't think it existed before American cinema in a big way except in prostitution rings
  • 0
    @Fast-Nop course I heard many different explanations and the interpretations seems individualized
  • 0
  • 2
    Well. The Collatz conjecture is just one concrete example that mathematics themselves are an undecidable problem anyway.
Add Comment