I've got a rather strange optimization problem. I have some groups of divisors and factors from which I need to pick the combination that's closest to (but not larger than) a target value:
input:
target = 1234
divisors = {'a': [1, 2], 'b': [10, 100]}
factors = {'c': [5, 20]}
desired output: integers a, b, c so that
factors[c] / divisors[a] / divisors[b] is less than, but as close as possible to `target` (1234)
Is there a smart way to do this or do I have to loop through all the combinations? FWIW, the numbers in each group ([1, 2], [10, 100], [5, 20]) are sorted
Whoops, that should've been factors['c'][c] / divisors['a'][a] / divisors['b'][b]
Hi all. I'm having trouble understanding why I can't access the modules of the "ampy" package ( https://github.com/adafruit/ampy )
I've installed it with `pip install ampy`, but I'm not allowed to do `import ampy.files`. When reading around in various topics on Stackoverflow I can't find a way packages should be able to hide submodules - everyone just recommends naming them with an underscore. Why am I not able to access the submodules in this case then?
@AnttiHaapala Amber's answer there is rather unhelpful too. I guess that was from when she was still new to SO. Or maybe she just didn't want to do all the OP's work for them.
@AndrasDeak Thanks, but where to find a tl;dr on last week's events, I was unaware of any of that happening? other than reading all the Medium and Twitter thread, which I'm doing now
@AndrasDeak Yes, that's the missing link. Looking at the Tweets, I couldn't figure out which site (IPS.SE?) and which specific question on IPS were at issue.
@vaultah I'm also blocked now. Mostly due to the fact that Twitter does notify you if someone liked a tweet which was in a reply to you.
So, maybe I sent a couple notifications their way and they got annoyed. Someone doesn't know how to Twitter (verified handle, moderately large following?).
And Twitter isn't even like Facebook where replies / posts to you go on your "wall", so the "go away" was totally uncalled for.
I assume that the cmp microcode is pretty similar to sub. If you do the subtraction from MSB to LSB you could bail out early, but I suspect that it uses an algorithm that works in parallel.
Wow - When did this community become so toxic. :-(
I come to an unanswered question where the guy is asking how to do something, but he is taking a bad approach.
I try explain in an answer why the approach is wrong, and suggest better approaches. I then get told the the comments that my answer is too similar to a another answer, and I should just tell the question questioner "No"
@GaryvanderMerwe This question? stackoverflow.com/questions/52947223/… Had the OP made the edit when you submitted your answer? It's a classic "variable variables" XY problem.
@GaryvanderMerwe There's some helpful info in your answer, but it doesn't discuss his list of undefined names, and it doesn't actually solve his problem. But I don't think it deserves 2 downvotes.
Maybe so. But, doesn't hurt to ask. Also, for the most part the comments were not necessarily helpful. Granted, the OP didn't really provide adequate information. At the very least we can try to pick once or twice to get some info.
Speaking of 100GB json files: I recently almost crashed my PC my accidentally requesting 7 gigabytes of data from the github API. Shortly thereafter, the github downtime happened. Coincidence? I hope so.
@AaronHall Don't have my mac on me right now, but I do have a command that works great on all platforms I have been using. I'm trying to pull it up. Couple minutes.
@Aran-Fey I wouldn't be that surprised. find does have some variation across Unix versions, and Mac commands are often different to the GNU variants.
@AaronHall Good idea. Some of the U&L regulars have encyclopedic knowledge of the variations in behaviour of the standard commands. Eg, Stéphane Chazelas (the Shellshock dude) never ceases to amaze me with the depth & breadth of his Unix knowledge.
@Aran-Fey Not quite, he almost always explains his code. But yeah, those one-liners are a bit silly. OTOH, I guess I do stuff like that sometimes, but at least I format it over multiple lines. Or break it up into sections using temporary names to make it a little more readable.
morning cbg, this will be my last day as a User after tonight I will be purchasing StackOverflow and putting the python chat guys in charge of everything
@Aran-Fey Well, yes. But seriously, something needs to be done to improve question quality. Unfortunately, I don't think it's possible without returning to the old Jeff Atwood standards when "Lacks minimal understanding" was a thing, and newbies were tolerated if they could behave like professionals.
I think what SO needs is a walled-off veteran-only area where people can post self-answered questions. (The Q&A model would stay the same, but you can't post a question there without an answer.) And a wild-west low-quality newbie area.
It's like that bit in Narnia where each iteration of the Garden of Very Pleasant Things contains a full-scale model of the Garden of Very Pleasant Things at its center, with each layer being even more pleasant than the last
@AaronHall Well, the point is that the content would be separated by quality. One section would serve as a playground for programmer fledglings, and the other area would be the knowledge repository. Sure you can create pearls on SO, but they easily get lost among the trash
@Kevin Even if that happens, it'd still be a major improvement. I'd rather have veterans argue with veteran-veterans than veterans having to deal with hordes of inept newbies
@Aran-Fey Maybe, but people will be less motivated to write answers in the veteran area, since the self-answer should be adequate, unless they come up with an alternative solution that's significantly better. Or they get more points for participating there. And if the vets area is succesful the wild west will get dominated by the blind leading the blind, and the rep farmers.
No heres what should happen when you are under say 1k rep instead of asking a question you follow a tree of questions that leads you to the duplicate you were about to post
@Aran-Fey Do you really think things get lost in rubbish? I have yet to have that experience. Although I'm not at your level, I do use SO everyday (other than chat) and find what I need nearly every time.
But anyway, I'm absolutely convinced that pearls get lost. Next time you google something, pay attention: How many bad SO questions do you click before you find useful information?
If I have a try except... And the except is for a specific error type... Should I always follow that with another except to catch any none standard errors that could happen?
@Aran-Fey It's definitely harder to find good stuff on SO now compared to 5 years ago because you have to wade through so much rubbish. Ironically, bad questions having bad titles is kind of useful because it makes them easier to skip over, OTOH, if you can't find what you want then you have to go back & look at those questions with bad titles, just in case a pearl is buried there.
@AndrasDeak the non MySpecialException should throw an error as normal right if I am catching only that exception, i.e. something like except MySpecialException
@Johnston You can have a naked except (or except Exception as e) at the end of your named except clauses, if you want to log or print something there, but you should almost always re-raise the exception.
@Johnston If it tries to handle the exception, yes, it. ould catch stuff that it doesn't intend to, and which it's not designed go handle. That's not an issue though if it re-raises.
Hmm, a week ago I said that the bezier curve with control points [a,b,c] is the same as the bezier curve with control points [a,b,b,c], but now that I draw them out, they look different. I was misled by MS Paint, which I thought could draw both cubic and quadratic curves, but evidence now suggests otherwise
My assumption was that if you click three points with the bezier tool active, then it draws a preliminary cubic curve, and switches to quadratic when you click a fourth point. But no. The curve I thought was cubic actually perfectly overlays the quadratic curve I just rendered with PIL.
python -c "import pathlib; [p.unlink() for p in pathlib.Path('.').rglob('*.py[co]')]"
python -c "import pathlib; [p.rmdir() for p in pathlib.Path('.').rglob('__pycache__')]"
There are no private chats on Stack Overflow. And in any case I'm not sure toon ever said he was Canadian.
I guess you could interpret our customary greeting, "cbg", to mean "hello, yes, I am one of those things you said" but it could just as easily have been a greeting to the room, independent of your question
I was hoping to get some criticism of my python commands, so lay it on me if you have any... yes they're abusing list comprehensions for looping, but I can't think of a better way to one-line it...
I haven't tested it but I expect python -c "import pathlib: for p in pathlib.Path('.').rglob('*.py[co]'): p.unlink()" would have the same outcome, while not using the forbidden technique of "list comps with side effects"
Today's pet peeve: that there is no formal term for "the part of the for loop that encompasses for foo in bar: and not the indented lines that follow afterwards
for statement
vvvvvvvvvvvvvvvvvvvvvvvvvvvv
for x in range(10): print(x)
^ ^^^^^^^^^ ^^^^^^^^
| | suite
| |
| expression
| list
| ^
target |
list |
^ |
| |
+--------+
|
???
@toonarmycaptain You know, Actually, I'm from Iran and If you have been following the news a little I'm sure you know that the economy in Iran does not really keep going well, So I'm looking for a job somewhere else out of my country, At the end: I have no idea what I need to do to move from here to my dreamland!