« first day (3897 days earlier)      last day (1275 days later) » 

00:00
there is always someone here
00:34
though we are arguably now in a less populated timezone.
I too roam the rooms in search of some human interaction to fight the overwhelming dread of existence, and find this time of day a bit bleak
 
1 hour later…
01:38
@tripleee I was trying to convert that sh cookie format to something that python can recognize in requests.get(cookies=)
I'm not quite sure how I acclimate to Jon's new avatar. Jon, did you take a turn towards the less sneaky ninjaesque?
Took me a while to get used to it as well
02:09
hello
02:29
Hello,
I am looking to contribute to any github public repo if anyone needs a contributor. I have too much free time. I prefer projects that are not too popular (i.e. would prefer up-and-coming projects instead rather than an already popular repo with thousands of stars).
Thank you
@Deepak I understand that you have not, in any way, sollicited my advice, but I can't help but react here. I believe you have better chance of finding an open-source project to contribute to by finding what skills you are really good at, then find a project that could benefit from those.
@FélixAdriyelGagnon-Grenier Yes, but I have a hard time finding a up-and-coming project . Most projects I notice are already established, which I don't really feel inclined to assist.
well, maybe you can start by deciding on a language. I see you've asked for open-source projects in the PHP chat as well.
... anyway I'll spur out my thoughts, because I realize I am not being completely honest with my answers : when reading your original message, I have a very adverse feeling. It reads like you can do everything in any language on any project in the world.
I have respectful doubts about that.
I'm sure you mean well, but it might help to state clearly your intent here @Deepak. Do you want to contribute so that you have something to show to potential employers? Do you want to learn some language by participating in an open-source project? Do you want to employ your skills in a particular language?
03:24
i see. thanks for the feedback. yeah i just realised i did come accross that way. my bad.

i do prefer to work on something with a UI. I can do python, php, java, c#.

the reason i wanted to find a project to work on is that i know i would be improving my knowlege in the process.

i wanted a new/up-and-coming project because it would be easier to catch up to speed rather than an established project which would require me to read dozens of pages of documentation.
 
1 hour later…
04:36
There is a borderline on-topic question which beats up on (uncached) Python vs C++ (where g++ will enable tail recursion by default). Also, Python stackframe size (/recursionlimit). This has to have been addressed many times before.
30
Q: Why is Python recursion so expensive and what can we do about it?

jtallkSuppose we want to compute some Fibonacci numbers, modulo 997. For n=500 in C++ we can run #include <iostream> using namespace std; pair<int, int> fib(int n){ if(n==1) return pair<int, int>(1, 2); pair<int, int> x=fib(n-1); return pair<int, int>((x.first+x.second) % 997, (x.first+2*x...

05:18
Oh my, that looks like a prime candidate for "too broad"... ah, we don't have the nice toys anymore.
details or clarity still cuts it
but better if you can find a good duplicate
I'm guessing it'll be hard to find one that covers C++ as well. :/
05:58
cbg folks
the dreaded d-day finally happened. our company did something to our vpn, and it took out our stackoverflow access for 3 days.
and google.com access as well..
It's been a hilarious ride so far.
@ParitoshSingh And did productivity go up, or down? :) How do you watch cat videos now?
@tripleee But that isn't about recursively computing Fibonacci (which is infinite function recursion), but about computing Fibonacci mod 997, which reduces to a finite state-space of at most 997**2 (or much lower), which is far more amenable to caching than raw Fibonacci. Hence, the OP has already massively reduced the scope of the question, such as to not be very general or reusable.
so maybe not close-worthy then?
06:22
I've just dropped a comment asking for clarification on which question they are actually interested in – Fibonacci mod 997, compiled vs. interpreted calls, Python recursion limit – and VTC'd as "needs more focus". Scrapped my answer, since it got torn exactly between those three topics.
Truth be told, seeing how many upvotes this has I'm a tad afraid of meta drama...
Hi everyone need some help
I am trying to plot learning curves using this page as a reference:scikit-learn.org/stable/auto_examples/model_selection/…
However I am not getting anything for the first graph(top-left one)
Its basically an empty plot
I am using the exact same functions and the exact names for the two series(X and y) , the only thing I have changed is the estimator used(logistic regression instead of naive bayes) in the second portion as shown below
fig, axes = plt.subplots(3, 2, figsize=(10, 15))
title = "Learning Curves (Logistic Regression)"
# Cross validation with 100 iterations to get smoother mean test and train
# score curves, each time with 20% data randomly selected as a validation set.
cv = ShuffleSplit(n_splits=100, test_size=0.2, random_state=0)

estimator = LogisticRegression()
plot_learning_curve(estimator, title, X, y, axes=axes[:, 0], ylim=(0.7, 1.01),
                    cv=cv, n_jobs=4)

title = r"Learning Curves (SVM, RBF kernel, $\gamma=0.001$)"
ok figured out the issue
07:16
@ParitoshSingh that one sounds like a feature ;)
 
2 hours later…
08:49
@smci heh, definitely down, there's been angry mails flying all over, it's glorious. And it's not over yet!
@AndrasDeak ha! well even duckduckgo can't be accessed so..
they all work without the vpn though, that's the best part. no copouts possible here, it's 100% due to the vpn things are getting messed up.
Alright, back into the vpn for me. cya on the other side :P
09:22
@tripleee computing Fibonacci mod 997 is a toy problem, not a real problem, it's not reusable or general. Whereas *"How to reduce the number of recursive function calls when computing Fibonacci" is less toy.
10:20
Hi guys, I have a question...
df.groupby(pd.Grouper(key='Datetime',freq='D'))['column'].mean()
this one give the mean value at the end of the hour,
But is it possible, through the groupby function to get the value at the end of the hour?..
i tried groupby.nth, but could not get that to work
10:51
recbg
Can anyone help me in the most optimal logic for this? -> pastebin.com/y03hVkdr
11:15
@PooyaPanahandeh please review room rules; you can ask here when your question is 48 hours old
@RaphX would it not make sense to have an ordered dict of times and search until you find one which is newer than the date you care about, then pick the one before that?
are there going to be hundreds or thousands of pricing changes? probably not; so optimality is probably not even particularly important
could you share a sample code snippet @tripleee?
not a Pandas person anyway; the regular Python code should be quite obvious I think
open question whether you would copy the list from the previous activity if you care about speed, or perhaps by "previous" mean the previous one which included your activity
@roganjosh ^ ping?
Had spotted it literally 5 secs before. Thanks for letting me know :)
11:35
hey guys
would functions that use recursion
def function():
    try:
        # do something
    except:
        # change item
        function()
like thus cause the system to continue building memory usage if used many times throughout the run time in the program?
if yes how could i eliminate the memory retained once the try goes through successfully? as right not the memory keeps building to much
Not sure I understand the question. All the memory used by function will stay in use until the function returns. This is true for all functions, regardless of whether they're recursive or not. But of course, recursion makes the problem worse, because you're calling the function more often.
cbg, all
If memory is a problem, either eliminate the recursion, or del all the big variables when you no longer need them
so essentially if the function doesn't return anything then this would be the cause
Umm... no, if the function doesn't return anything it has a bug
11:46
well im using said function to handle automation with selenium and havent placed a return within it as its performing actions within it... would it be better to do dpaste.com/9S8CPPVRY then
simply placing the return keyword within?
charles babage
ok
@Kwsswart Unless there's more code after the try...except, that return does absolutely nothing
Any reason why you don't use a loop instead of recursion there?
11:55
Thats what I assumed seems like the memory problem is coming from stackoverflow.com/questions/38164635/…
12:47
That recent Fibonacci recursion question inspired me to enhance my old recursive fast Fibonacci code. This version keeps some cache stats. It also handles modulus. Set modulus to zero for normal Fibonacci numbers.
BTW, there's a Wikipedia article about the periods of modulus Fibonacci sequences: en.wikipedia.org/wiki/Pisano_period
My new code uses more cache space, and some cached entries are never used, but it ends up making fewer calls. But the cache size is no big deal, since it's ~2×log_2(n).
@smci Mod Fibonacci is popular on coding contest sites because it means you can handle large args without big integer support. Sure, it doesn't have much practical application, but modulus Fibonacci stuff is a well-studied part of number theory.
13:25
you mean to maintain a list for all of the dates? @tripleee?
@RaphX no, a dict so that you have the date (probably as seconds since epoch) as the key, and the actual price change as the value (probably as a dict)
13:41
ok but it would be different for each (game+subscription duration) combo so I would need to have one master key of game followed by as many keys for subscription duration and then what you suggested @tripleee?
13:58
basically your top-level dict keys would tell you "at the following times, something changed" and the values would tell you what exactly changed
so no durations is what I would propose, just points in time which you can flip trough chronologically until you are in the time window you want to ask about
14:47
Cabbage
15:07
Does anyone know if there's a library that can allow cron job's duration to be updated whenever there is a change in a database?
cron jobs don't have a duration though? A cron job is just a command + a trigger, no?
any odoo dudes here?
15:30
@Aran-Fey Isn't there the string which is similar to how you set its schedule? Was thinking if there is any mechanism that can update that string even after it is initialised
Can you give an example of such a string?
'1,2,4,5 * * * *'
Ok, thanks. And this is an argument that cron typically accepts? I'll try doing some research
recbg
thanks! @tripleee
I have another question if someone could help me
How do i get the feature names if I do RFECV in scikit learn using the above reference?
@Kevin Yes, but it seems the Python side of things call cron jobs slightly differently, not sure whether there are methods that take in that string
Was thinking for this kind of problems, whether the solution should be handled entirely by the database
@PrashinJeevaganth It might depend on how your Python code is calling cron. Are you using subprocess? Or something else perhaps?
In principle subprocess is capable of behaving exactly like the command prompt, if that is what is needed of it
@Kevin Am doing it via a script, using the CronTab module and passing in the string, which is already hardcoded
Ok. I'll poke around the python-crontab docs and see how they handle things
Kind of heart broken here because the OP chose the other answer, I thought mine was perfect. Nah I'm joking :p Attempt to make a timer in python, where is the error?
As long as the OP is educated with the best methods, I'm fine
@CoolCloud so if you're fine why are you complaining/"joking" here?
15:46
To know which is the best method
Which part of that Q&A do we have to see?
@CoolCloud then you misspelled "do you think the other answer is better?"
That would be a valid question, even if usually pointless. Whereas "boohoo/haha they accepted another answer" is just annoying.
I actually went ahead and thought someone might say either of the answer is better, that is why the OP chose it
[current mood: vaguely guilty about the various times I've complained in here about an answer I wrote that went unappreciated]
Guilty because you shouldn't have complained? Or because it did not get enough appreciation?
The first one.
15:56
Anyway which answer is better? Because I already had a efficiency doubt about using an extra StringVar.
That's what the upvote feature is for
If I said "yours is better" what do you get from that, btw? That's not objective feedback, it doesn't tell you anything about what I think could be improved, it really only serves an ego
I would only feel guilty about writing an unappreciated answer if I can tell (with the benefit of hindsight) that my solution wasn't up to my standards. But usually my solution is good enough (for me), and it's just submission time or the voters' aesthetic preferences or random chance that I wasn't elevated to greatness
Me, constantly: "Could it be that my code is only so-so? No, that can't be... It's the readers that are out of touch"
@roganjosh Yea that is true
If, however, you asked something that was more objective, then it wouldn't look so much like showboating for votes
Was not intending it to be used for showboating, but ya I get what you mean
16:01
At a glance I agree that the StringVar isn't required. My aesthetic preference is to leave it out. In terms of computational efficiency, it should be near-indistinguishable from the non-StringVar design.
@Kevin Okay I see, cool. This is what I was looking for, thanks :D
FWIW I didn't think you were showboating/fishing/whatever
for the record I did
but it's not a race :P
The world really is full of different perspectives [I shed a tear at the beauty of it]
16:07
IME, StringVar is most useful when you're extensively making use of its handy feature that it auto-updates labels and textboxes that it's associated to. I grant that ALai is using this feature with their Label's textvariable argument, but the UI design is straightforward enough that it's not saving them a whole lot of cognitive overhead
StringVar can get really useful if you use its trace method to enforce validation/sanitization on user inputs. Need an input that only allows digits? Bam, StringVar.
Although one must take care for more complex criteria like "input must be a valid phone number in the form XXX-XXXX". Imagine your user wishes to enter "867-5309". They press the 8 key, and the text box flashes, and the status bar reads "8 is not a valid phone number", and the text box remains empty. This is a problem.
@ParitoshSingh At one of my old companies, when our ERP went down, it knocked the phone out with it so none of the customers could ring in and complain. Management should have had the good sense to have the VPN also block internal emails. More fool them.
Yea I do use StringVar for its trace alone. It can also be used if you wish to keep the widget to None, but still support updation of it(you prolly shouldn't even think of doing this)
@Kevin Why would 8 trigger an error?
Well, one of the possible ways to implement text field validation is to trace the StringVar so that the validation method triggers on every key stroke. One might implement the logic as "if the next keystroke would make the field contain a string that isn't a phone number, ignore it".
If you're not thinking carefully about your design, then this seems fine. It does a good job of preventing the user from entering things that are blatantly not phone numbers, for example "!@#$%^&*". If the user tries to enter an exclamation point, nothing happens, and this is good.
Oh I see
I did ask something similar back in the day Auto add dashes to entryboxes in tkinter
and got an answer that I did not understand at all, but decided to use it, back then I just wanted my code to work somehow :/
But the person was quite patient with me and told me some more wrong things in the code and educated me further more
16:23
A somewhat better design would be something like "allow strings that might be part of a phone number". "8" and "86" and "867" and "867-" are all valid parts-of-phone-numbers, so the user would be able to type them out without a problem. In the meantime, the troll user trying to enter "!" is still foiled.
So basically allow numbers and - and block everything else? Let me try to build an example
But even this may cause user frustration. Suppose your logic is simply "allow the string iff it could be the beginning of a phone number". The user enters "8675-309" without any trouble. Then they say, "oops, that 6 is supposed to be a 1". They move the cursor just past 6 and presses backspace. Nothing happens, because the validator dutifully rejects "875-309" as not a partial phone number.
@CoolCloud What about international calling codes? 0044 can also be +44 for the UK, for example
@CoolCloud Yeah, that's pretty much the optimal solution in terms of 1) not annoying well-meaning users; 2) filtering out many kinds of obviously bad input; 3) not spending a thousand man-hours writing the perfect obviously-bad-input-rejector
(assuming that you weren't interested in allowing international calling codes and suchlike, and this is well established in your requirements from the beginning)
@roganjosh The code was something I was using for a school project, so I went on using a local code here, but ya if it were big, I would need to to find the country and then implement the local code there
16:33
If you need to allow any sequence of characters that would probably cause an ordinary telephone to successfully connect to another telephone, you may be doomed
Then it becomes one of those "how do I tell if an email address is valid?" situations
Hey all, moderation question. Came across this answer: stackoverflow.com/a/68023134/3483203, and noticed that every answer by the user advertises their commercial product, regardless of it usually being irrelevant to the question. Should I just be flagging them all for spam, or if I just left a note on one for moderator attention would they check their other posts?
If it was just one answer I'd probably just edit + leave a comment, but it's around 30, all with the same advertisement at the end.
My instinct is to leave one flag for moderator attention, and indicate that it's a problem for many of the user's posts.
I think I'd just flag one and say just what you said in your second comment here
consensus!
IIRC the moderator interface for spam flags is kind of obnoxious to clear out if they get a bunch of notifications at once for a serial spammer
May as well save them some clicks.
Yea, I flagged a few then realized it was every one of their answers, will just leave one, thanks for the input.
16:41
@Kevin A better affordance would surely be to indicate by a change of state (e.g. text hoes to red) when the current contents aren't acceptable.
I was sorta curious to try their link and see what car crash lived on the other side, but I'm not a fan of the URL either. Without having actually checked it, it makes me suspicious
@holdenweb Yeah, I'd say your "allow change, but warn" design is preferable for 95ish% of scenarios.
@roganjosh Yea, the link is even more a red flag, because it's a custom link tailored to identify traffic coming from stack overflow, so even more of a marketing campaign.
@user3483203 Frankly anyone who uses a word like "productionizable" deserves all the trouble they get.
4
I remember a project I did for work a couple years back, where I considered allow-but-warn, but ultimately decided on reject-entirely. I don't remember what my reasoning was. call it a 50/50 chance between "unusual circumstances beyond my control" and "I was dumber back then"
My hope is that Past Kevin is consistently dumber than Present Kevin, but evidence does not always paint a happy up-and-to-the-right trend
Re: the spammer's suspicious URL. I just noticed that Firefox no longer shows me the url of hyperlinks that I hover over. This is the third time in the last month that a browser update has robbed me of a useful feature.
16:51
What a bizarre change to make
If might just be a change of option default value, like Chrome's relatively recent (9 months ago?) switch to not displaying the whole URL by default until you interact with it.
I reckon there's a good chance the feature still exists, but it's off by default. or on by default for a new install, and off if you upgrade from a prior version, because your existing settings got mangled a little
Unfortunately this is rather hard to research because any of my google queries involving "firefox" and "url" are either obviously irrelevant, or lead to support tickets for somewhat similar problems people had in versions that definitely did not hide the feature away somewhere.
"URL address disappears -- just what I need! Posted in 2012! Never mind!"
I mean, my perception of the passage of time has been totally warped at this point. Maybe you've only just noticed? :P
Not inconceivable.
There's some stuff here. I'm getting closer, at least temporally
17:02
Come to think of it, my own perception of time was pretty spotty yesterday, because I had gotten an hour of sleep that night. I would notice the clock had moved forward by 2-3 minutes, despite me not having 2-3 minutes' worth of recollection of that time
Luckily a 2-3 minute span isn't enough time for an amnesiac and possibly deranged Kevin to do anything really bad, like push my neighbor's car into the lake. But it might be enough time to open about:config and set some preferences to more interesting values.
@Kevin In response to your recent slicing comments, the best explanation I've found that's "official" is docs.python.org/2.3/whatsnew/section-slices.html
"2.3" -- Oh this imperfect world :-/
Is it possible to have a blank column header for a column with data in a pandas dataframe?
No
You can think of a dataframe as being a dictionary of numpy arrays (in some ways); you can't have a dictionary without a key, and columns are keys
got it
does blank space count as a column header>
?
17:12
Was just waiting for that. You can test it
lol, thanks will do that now
df = pd.DataFrame({"": [1, 2, 3]})
df1 = pd.DataFrame({' ': ['1', '2', '3'],
' ': ['1', '2', '3']})
It does. But for multiple columns need to increase blank space size to avoid duplicates
Why would you want blank columns to begin with? Not a rhetorical question, I'm curious what the objective is
If it's something like "I want less clutter when I print out my dataframes", that's a perfectly cromulent goal
... Albeit one that might be more easily accomplished some other way.
Theory 2: "The column has effectively no semantic meaning, so any name I give it would be arbitrary, so I may as well make it nothing at all". I wonder if ndarray would be better for that kind of data...
"I wonder if ndarray would be better for that kind of data" certainly sounds that way
17:25
Theory 3: "there's no ultimate goal, I was just idly wondering if it was technically possible". I approve of this, since 90% of my output is caused by idle wondering.
I think this is probably spill-over from the problem yesterday (?) where they need to fit a standard spreadsheet output
The XY is getting XY-ier
Ah, valuable context
I'm usually pretty good at recognizing spillover questions, but I must have been busy pushing my neighbor's car into the lake when they were asking about spreadsheets yesterday
Sans my ability to remember what day I'm talking about. Nice call-back to my current inability to know the passage of time :P
22 hours ago, by AV111
@roganjosh Unfortunately yes, because I need to be able to 'col_index+something' or something similar to that, whcih can be applied to 15 columns per "model" (there could be upto 15 models, so 15*15 different columns
17:42
Ah yes, the 15x15 problem. For that, I can send only thoughts and prayers.
@Kevin Goes back to the structure of excel file output from a legacy software, and needing the same structure out of oython to import back to said legacy software
@Kevin I'm happy to report i'm in the home stretch, except some minor issues here and there
Ah, the old "I need the output in this specific format, due to requirements beyond my control"
Perhaps the most cromulent reason of all
@AV111 That's good. I figured you were at least trying potential approaches, since you wouldn't be asking about blank column names otherwise
You can't have an XY problem unless you first think "Ah ha, a way to solve X! But I need to solve Y to do it..."
brb
18:02
@Kevin Hmmmm I see
@TonyBrand I don't think anyone asked you for it? Please see our rules particularly in regards to waiting 48 hours before linking a question here
18:29
I'm not really sure on how Python Encoding works. If I have

`from num2words import num2words`
`# -*- coding: iso-2022-kr -*-`
`print((num2words(x, lang='ko'))`

the output still gives me a symbol [?] which shows the computer doesn't understand it.
Depends. Is that output in a terminal/cmd prompt window?
<Immediately steps away from the problem> Encoding isn't my game. But I can imagine things getting mangled by the terminal display
# -*- coding: iso-2022-kr -*- does literally nothing. Since python 3, scripts always have to be encoded in utf-8
Is the ? symbol already there in x or does num2words create it?
What I meant to ask is, can we have an MCVE
...okay, after looking up what num2words actually does, I retract that question
I'm gonna go ahead and assume you're on Windows, so the solution I'd recommend is to ditch the lame ol' cmd.exe and upgrade to the new Microsoft Windows Terminal
To add to what Aran-Fey said, the # -*- coding directive is obsolete. But it has no effect on how your program prints or reads data. It just tells the interpreter what the encoding is of your script file itself. That was useful in Python 2 if you used something apart from plain 7 bit ASCII as the encoding of your script. In Python 3, you should tell your editor / IDE to save your Python scripts with the UTF-8 encoding.
18:50
Found this cool repo ~ github.com/ParthJadhav/Tkinter-Designer. Seems like a great project
19:02
Have you gained rep @Aran-Fey? Maybe I've not been paying attention but I didn't think you were in the 30s
Yeah, got a random upvote a couple weeks ago
Wouldn't mind hitting 50 rep tbh, that's when they allow you to upload images I think
The smurf grows <tears up>
I noticed that @Kevin is no more in the "Nice" zone
What do you mean by that?
He passed 69k
19:08
Ah. I definitely misread that one, sorry
I'm still within the [69k, 70k) range. It's not so precisely nice as having exactly 69.000k, but still decently nice
@CoolCloud Very neat. It sounds a lot like the Visual Basic GUI designer, which was basically my very first experience with programming.
I have'nt tried it out, yet. But it sounds great, even the sample pictures looks nice, dont know how working those are.
@Kevin You sure? :P
I'm 80% sure, based on when I looked at the number about 30 minutes ago. But your message is making the percentage go down.
Ah, much to my continually decreasing surprise, I gained 500 rep in the last half hour. Not bad considering I've done literally nothing.
I actually did want to vote on some of those answers, but I read some 6 random tkinter answers from yours and voted for 4
19:23
Now to savor the one serotonin molecule I get per 10k rep gained... Aaaand, it's gone.
@Kevin Ok not to confuse/worry of serial voting, 500 is not mine, 40 is
acknowledged
But gaining 500 without doing something ATM is great, I struggle to maintain 10-20 per day :/
Kevin has tricked hordes of people into giving him bounties by making all his popular answers Community Wiki
Ah so that's the secret
19:26
At my current pace, it's quite rare for me to crack 50 rep on any particular day. And today is no exception apparently, because my reputation history panel makes no mention of my 500 point jump
Maybe they rounded up all my answers by a fraction of a penny
I'm somehow have 11k rep in chat, so no complaints here. The system is working as intended
Maybe they decided to delete every user I've ever downvoted. Should one man have all this power?
I'm assuming your downvotes given > upvotes given ?
My guess is, I give more upvotes.
Activity page says 2547 upvotes, 247 downvotes. Sounds about right.
Ah nice :)
19:42
i have 31 upvotes
no down votes
Infinity% positivity
and i only have 24 reputation
Hmmm 633 up and 32 downs
Really, 10 is all you need to get the best experience out of the site
Most of my question votes are down, because there's just so much yamming garbage that comes through the feed. I take post quality very seriously. OTOH, a majority of my answer votes are up, because I like to reward people who take the time to write out a clear, coherent, correct answer.
19:45
in meta stack exchange my question has -6 votes
Yea well Meta is known for giving good responses
Downvotes on Meta should be taken less seriously because they can indicate a simple difference of opinion
and that is why i will not ask a question in Meta
I learned it the hard way :P
ok
Stack overflow is better than Meta
19:54
IMO, both serve a different purpose
@Kevin I suppose it is not that difficult, I doubt if I will be able to do it, but it seems like they connect with Figma get the coordinate of each item, then resolve it into tkinter components and make a widgets and place them on screen using place(). So it is basically just images placed at x,y coordinates given to them in the Figma workspace. PS: I have not read the source code so I am not sure how it works yet
github.com/ParthJadhav/Tkinter-Designer/blob/master/backend.py Ah, well I am not entirely wrong. They write it all to a py file that we can run and check later
FWIW, a current HNQ on Puzzling shows that it's possible to pack all 16 2x2 bit patterns into a 4x4 wrap-around grid. The result is a kind of houndstooth pattern.
22:05
@PM2Ring Ok, thanks for the clarification. But the OP seems to be unaware that 997*log2(997) fits inside a cache, so no stack overflow.
22:16
@holdenweb Umm, typo. Unless that's a very dubious text-based service.
@smci You have to use a good algorithm to avoid the stack overflow, though. See the diagrams in Eric's answer. Or, as you mentioned earlier, you can take advantage of the fact that a modulus Fibonacci the sequence must repeat in at most m**2 steps. That's slightly more fiddly than simple caching, though.
22:38
@PM2Ring Why is it slightly more fiddly than simple caching? As long as the cache is large enough to hold the entire sequence.
Well, caching normally just looks at the keys. To track the cycling, we need to look at the values. Here's a (sensible) iterative demo
def fib_gen(m):
    a, b = 1, 1
    while True:
        yield a
        a, b = b, (a + b) % m

if __name__ == '__main__':
    m = int(sys.argv[1]) if len(sys.argv) > 1 else 20
    g = fib_gen(m)
    prev = None
    for i, u in enumerate(g, 1):
        print(i, u)
        if prev == 0 and u == 1:
            break
        prev = u
For m = 997, we get fib(1996)%m==0, fib(1997)%==1
So using that cycle is quite efficient if you want to calculate, eg fib(10**10)%997. OTOH, Eric's and my recursive versions are pretty fast, and happily calculate stuff like fib(10**100) % (10**9) quite quickly.
22:57
@smci Too late to fix it by the time my dyslexia went to sleep again!

« first day (3897 days earlier)      last day (1275 days later) »