|
Azuth0667 posted:I want to be able to make a grid out of them and assign each one a different random number. But what are you going to do with that? If you have a bigger end goal in mind (like making an interactive sudoku grid or something) you might want to get learning a GUI library that will handle all the inputs and stuff
|
# ¿ Feb 7, 2017 08:12 |
|
|
# ¿ May 9, 2024 04:38 |
|
It would also help to do that with the original code - start with an edge case like an empty array, then 1 element, then 2, then 3... see how it behaves and if you notice a pattern emerging You can work this out on paper, but it might be a good excuse to practice using a debugger to step through the code too!
|
# ¿ Feb 12, 2017 05:09 |
|
That causes issues - the original version moves the left and right extremes towards each other in a way that they should eventually arrive on the same index, at which point the loop immediately ends. That's where the desired element should be, so then it checks if it's there or not Your version allows another loop when the indices match, so if they're at the end of the array (if X is the largest element) then you move L forward and it's out of bounds. You could get around this by doing your equality check first, but what if X isn't in the array? Your solution sort of changes how the algorithm works with that early return. "3 changes" is kind of arbitrary but you said "3 errors" first, which implies small corrections - otherwise what counts as a single change, y'know? I think if you look at the original code with the edge cases I mentioned (specifically 2 elements where 1st<X and 2nd=X, eg [2,5] with X=5) you'll see a problem, and there's an easy fix for it
|
# ¿ Feb 12, 2017 10:26 |
|
damnfan posted:Thanks, I was stuck with the binary search implementation that I was familiar with rather than thinking of other implementations. The edit that satisfied the requirements ended up just being: I was thinking of math.ceil, but that works too and it's probably a bit neater!
|
# ¿ Feb 14, 2017 01:42 |
|
If you do any programming challenge kind of stuff, you tend to run into problems where it's real easy to use astronomical amounts of memory (with a naive solution at least). You can generate a large graph of states following other states to hunt for optimal solutions, you might need to read in large amounts of data, or you might want to trade off memory for speed by caching lots of results instead of calculating them each time. Linked lists tend to be slower to iterate over than arrays, and if you have enough data the speed could be the difference between an algorithm that finishes in a reasonable time, or one that's unacceptable Plus sometimes you need to run many instances of your process, so a small inefficiency can multiply into a significant one. And you might have other things to worry about, like garbage collection and how it affects the responsiveness of your system. Depends on the language etc. though
|
# ¿ Feb 16, 2017 00:14 |
|
I've no experience with it but seems you can't do that in Sublime Text without a REPL plugin, all you have there is a basic output window The easiest way is to open a terminal window or whatever in the folder you've saved your script, and just do python scriptname.py, and then you can interact with it. Different editors and IDEs will come with something like this built in, or you can install plugins like the Sublime one up there
|
# ¿ Feb 25, 2017 07:23 |
|
I've been using Visual Studio Code a bunch for things lately, might be worth putting that in the IDEs section since it's the hotness and people might already be using it? They have a Python page and that Code Runner extension is real nice too
|
# ¿ Mar 6, 2017 10:34 |
|
|
# ¿ May 9, 2024 04:38 |
|
flosofl posted:It's nice and I use it for quick and dirty edits when I don't want to load PyCharm, or I'm on a computer I don't have access to PyCharm. Sure, I meant more as a 'stuff you can develop with' section - it has a decent amount going on though, I think for a lot of people it does what they'd want from PyCharm without being as overwhelming. Just a suggestion anyways!
|
# ¿ Mar 6, 2017 16:08 |