Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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!

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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:
code:
m = (l + r + 1) // 2

I was thinking of math.ceil, but that works too and it's probably a bit neater!

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

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.

I would probably not call it an IDE (especially for macOS). It's really more of a language aware editor.

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!

  • Locked thread