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.
 
  • Post
  • Reply
Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I love how the first post on every problem is someone doing it in assembly.

Adbot
ADBOT LOVES YOU

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
If the nodes aren't marked as visited then they will never finish.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm not quite sure what you mean by that. Which nodes are being put into the queue? In what order are they being put in? How are you using the queue?

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
That runs in O(V+E) time, but it doesn't color the graph. It merely verifies that it is colored.

Dr. Stab fucked around with this message at 17:11 on Apr 25, 2015

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm just a little confused because that's not BFS or DFS. If they needed to actually do one of those to generate a 2-coloring, you couldn't just visit the nodes in an arbitrary order.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

LeftistMuslimObama posted:

OK, how does this solution sound:

Depth first search. Base case of recursion is that we reach the target or there are no unvisited nodes to visit. Keep an auxiliary array that records the path with the current minimum elevation. Each time a new path is found, check its elevation against the recorded path and swap if it's lower. The worst case scenario visits some nodes and edges multiple times, but it's some constant multiplier of the number of nodes + edges, as each recursive call does constant-time work(add itself to the current path, do a comparison against the present max elevation on the path).

I feel like I'm missing something still, but I think this is on the right track.

I don't think this is quite right, or at least isn't clear to me. What do you do if the correct path requires edges that were in previously checked paths?

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

sarehu posted:

Uhhh... But O(E/2) = O(E) which means O(E) + O(E/2) + O(E/4) + ... = O(E) + O(E) + O(E) + ... = O(E log E).

What was really meant was O(E + E/2 + E/4...), but is pretty clear as it was written. While you're technically true, it's not useful to the discussion at hand. e: in case you're actually confused, the series asymptotically approaches 2E.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
Don't actually generate the numbers and count all the bits. Try to figure out a pattern and calculate the sum.

Like:

1 bit: 1
2 bits: 4
3 bits: 12

Is there some pattern you can use here? Think about defining each term in terms of the previous term.

e:Wait, derp. You're going up to 10^16, and not 2^16? Well, you can apply the result from the problem that I thought it was to get the solution to the actual problem.

Dr. Stab fucked around with this message at 11:45 on Jul 10, 2015

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Hadlock posted:

Has anyone written anything of great interest using Rust yet?

Is Atom/Sublime the new vi/emacs war?

I really don't see this being the case. It's not like there's some fundamental difference between the two. Atom looks and feels a lot like sublime. The real argument is atom/sublime vs vi.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

22 Eargesplitten posted:

Induction: The shortest path between any two points will also contain the shortest path between any two points on the path.


You want to prove that? Because that's easy.

Say you have a shortest path from A to C that passes through some arbitrary point B. Assume the path used from B to C is not shortest. That is, there exists some shorter path from B to C. Then we can construct a path from A to C through B using our shortest path from B to C that is shorter than the given shortest path from A to C, a contradiction.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm not sure what you mean by redistribution, but it seems like what you want is GPL.

Rolling your own license is a very bad idea, and you should avoid doing that if you can help it.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I would just go with the one that conveys the intended meaning the best, which will almost always be "if (foo == 0)"

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm not really an expert on what's best for that situation, but I can't imagine php being the right choice unless you already have a lot of experience with it. What language/framework is best for you depends on exactly what your needs are and what you are familiar with.

Running github on your own server seems like huge overkill for what I assume to be a personal project. Most repository hosting services (including github) allow you make your own private repositories on their servers for free (whereas github enterprise starts at $2500/year + the cost of hosting your own server).

In terms of version control for Unity, Unity 5 has a tool called UnityYAMLMerge. It allows you to resolve conflicts on scene and prefab files. You should integrate it into your git configuration.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
So, it looks like what you're trying to do is something like this.

code:
var build = {
	skin: 1,
	hair: 1,
	brows: 1,
	eyes: 1,
	nose: 1,
	mouth: 1
};
build[type] = value;
But given that this is an create function and not an "initialize all to default values except for one entry and then not return anything" function, This probably isn't entirely what you want.

e: to clarify what you were doing: You initialized build to an array with one element, that element being a dictionary defining your attributes. Then, you iterated over that one element, checked to see if your type parameter was the dictionary, then added a copy of the dictionary as a key to the dictionary, with the value being whatever you passed into value.

e2: Looking back at your original post. It sounds like you're having trouble with making this persist. Where are you storing the state of your current build? Because right now, that function defines a local variable and doesn't return anything, so that build doesn't exist outside the life of that function.

Dr. Stab fucked around with this message at 17:46 on Sep 26, 2016

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
Yeah, I do some stuff that works on a data set of every card ever printed in magic the gathering, and that poo poo is super small.

Also, I think the same text copy pasted a few thousand times probably gzips a lot better than the actual thing. But, it will probably still be under a meg. MTG JSON, which is what I'm using, zips to just under a meg. The only thing you should need to download as required is card images. It'll probably end up being slower if you have to make an http request for every single card file.

Also, Pokemon cards may feel like they're simple, but there's some very tricky effects in there. You could get 95% of cards implemented in a snap once you have the basic rules set up, but those few remaining cards will end up making this a massive undertaking, especially once you realize that those cards also happen to be the ones that people want to play with.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

it is posted:

Thanks for the suggestions guys, I'm pretty sure I know where I'm going with this.

And actually Pokemon cards pretty much all have very simple effects. This is probably the card with the highest density of weird special-case effects in Standard; if this were an MtG card, this would be a creature with a free activated ability "discard all cards attached to this creature. It becomes an Aura enchantment with with 'Enchanted Pokemon has protection from Mega Evolution Pokemon. Discard this enchantment at your opponent's end step.'"



There's still cards like ninja boy or even garbodor that are trickier than you may think to in a modular way.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
UML is a very broad thing. It's a standard for drawing a large number of kinds of diagrams for specifying software. You'll have to be a bit more specific. I'm assuming they want you to draw a class diagram, but I'm not sure.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
That looks exactly right.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
You need to fetch in order to see changes to the upstream.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Peristalsis posted:

So the value here is that committing locally triggers runs of the test suite that you might not otherwise make? (Again, I'm genuinely curious.)

No, it means you get a more granular history to bisect on when trying to identify the source of a bug.

e: A pretty big deal with local history is that you can branch locally. Make some experimental changes to your feature, abandon them, and maybe come back to them later. No need to add a new feature branch to the main repository for your little 10 minute digression.

Dr. Stab fucked around with this message at 22:51 on Mar 6, 2017

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
The cyclic buffer idea is best, but you just store the index of the head rather than a pointer.

Also, it should be wrapped in a class so that you don't need to worry about offsetting the head everywhere you use it and can just ask for the nth value as though it were the other implementation.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Eela6 posted:

No. It will, though (assuming you're using real words and not just the arbitrary string "well, actually" repeated over and over again). Letters in English are not remotely uniformly distributed.

Wouldn't a non-uniform distribution be more likely to have this method give you a wrong answer? If you assume that the letters are uniformly distributed, then the top 5 letters are most likely correct. But if, like in a language, letters appear in clusters, you're more likely to have weird outlier scenarios. Like, eg, if a tenth of all words started with "qwert" and "qwert" didn't appear anywhere else, those letters would be very frequent, but also be a good candidate for the best set. I know that's a contrived scenario, but I just mean to demonstrate that uniform distribution would help rather than hinder this approach.

Also, I really don't agree with this idea considering that the original problem is not especially unfeasible. An 83 fold speedup is cool, but not at the expense of correctness, especially since you can run the brute force solution for the same amount of time and get a similar result.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
Saying "just use the first 12" is an approximation. It happened to be right in this particular instance, but that's not the same. I could easily throw another set of words at it that would break it.

Now, if your algorithm actually performed that calcuation, and chose which letters to exclude based on that then that would be another thing.

Also, your idea here gives me a better idea. As you're iterating, whenever you find a candidate letter set, cull all letters with higher frequency from consideration. You'll probably save a bit more computation this way versus culling once ahead of time using a a rough upper bound.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Eela6 posted:

Okay. Give me a set of ten thousand or more unique English words that breaks this.*

Edit: Thank you, KernelSlanders, NippaShish. I never claimed to have a solution for any possible arbitrary combinations of strings. I claimed (and, in fact, proved my claim) to have a solution to the problem presented to me.

*if we have less, there's clearly no reason to do any filtering at all. Or, better yet, cut out the "well, actually" and present your own superior solution.

I was responding specifically to the fact that you were saying that it wasn't an approximation. You made an assumption, and did some calculation to demonstrate that it was correct. I'm not trying to poo poo you because you made an optimizing assumption about the real world behaviour of the problem. I'm just saying that it's a different thing than a program that solves for any instance.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Eela6 posted:

And I'm saying that claiming you could easily build a list that beats it is different from actually doing so ;)

You also added the caveat that the list needs to be very large and use english words. I'm not sure exactly what you're trying to prove but you're being a gigantic dick here. Are you saying that you don't actually believe that it's possible to synthesize an instance that doesn't work, or are you just trying to win some argument that you think you're having?

I'm still not sure why you're being so hostile in asking for this, but here's a rough idea of what I was thinking for my algorithm:

code:
for letter in alphabet:
	for word in words:
		if letter in word 
			letter.frequency += 1

sort alphabet by frequency

cap = alphabet.length; 
candidate_set = {}
candidate_frequency = words.length+1

//there's probably a less stupid way to do this
for(i = 0; i < cap-4; i ++):
	for(j = i+1; j < cap-3; j ++):
		for(k = j+1; k < cap-2; k ++):
			for(l = k+1; l < cap-1; l ++):
				for(m = l+1; l < cap; m ++):
					
					current_set = alphabet[n] for n in [i,j,k,l,m]
					current_frequency = 0

					for word in words:
						if word contains letter from current set:
							current_frequency += 1
					
					if current_frequency < candidate_frequency:
						candidate_set = current_set
						candidate_frequency = current_frequency
						for letter in alphabet:
							if letter.frequency > candidate_frequency:
							cap = index of letter
							break
					
return candidate_set
I'm not a very good programmer, and I don't know python, but I hope it's clear enough to be understood.

e: Also you really seem to care about the example instance I was thinking of, so something like this:

https://pastebin.com/j9y70An5

It doesn't meet your restrictions but that's the sort of thing I was thinking of.

Again, I wasn't saying that there's anything wrong with solving it as though it were a real world problem. I'm wasn't trying to poo poo on you in any way. It's just a different thing.

Dr. Stab fucked around with this message at 02:32 on May 30, 2017

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Eela6 posted:

Sure! I am relatively confident you will not be able to build a solution; but if that's not the case, I'd love to see it.

I am completely confident that Dr. Stab cannot build a solution.

I'm not sure what I did to slight you, but gently caress you too I guess.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Eela6 posted:

It was this entire post:


:allears:

Again, this is the sort of thing I was thinking of:

https://pastebin.com/j9y70An5

Here, the most common 4 letters are part of the set.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
Yes I totally understand that you made an assumption about the real world behaviour of the problem. I'm not disputing that. There must be something really off about the apparent tone of my posts, because I was just trying to discuss the problem. I wasn't trying to challenge your intelligence or anything.

I was just responding to what you said here:

quote:

I'm not 'efficiently approximating', I'm getting the correct answer.

to say that, no, it was an approximation. You made an assumption about the nature of the problem, specifically that the program would only be applied to sufficiently large lists of english words. Like there's nothing wrong with a solution that's

quote:

(assuming you're using real words and not just the arbitrary string "well, actually" repeated over and over again)

but then when you say "actually no it's universally correct" that's a different thing.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
Liberally apply <marquee> tags and don't let anyone tell you otherwise.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Linear Zoetrope posted:

Just to make sure my intuition is correct, it's impossible to uniformly randomly choose m distinct instances from n things iteratively (that is, without knowing n upfront), correct?

I'm essentially simulating something and want to sample exactly 3 instances from each simulation without biasing towards any step count, but simulations are long and keeping all instances around (even on disk) is prohibitively large, and only storing transitions and having to resimulate the entire episode just to select 3 instances after the length is known is prohibitively slow because my simulator can't be modified (3rd party, closed source) and only runs in real time or slower.

E: Would it be equivalent to do it in "blocks"? I.E. I keep a buffer of (say) the last 1000 instances, and once it hits that value randomly select one of those, keep it elsewhere, and empty the buffer and repeat. And then I randomly sample 3 instances from the values I set aside (assume n always >= 3000). I think that's the same?

To get one state at random, it seems pretty obvious to me. At step n, 1/nth of the time, choose the current state, otherwise keep previously held state.

Getting more states shouldn't be impossible, but I can't think of a precise method right now.

e: at step n, 3/nths of the time, update a previously chosen state to the present state. Easy peasy.

Dr. Stab fucked around with this message at 20:30 on Jul 11, 2017

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Sedro posted:

Can't you store the selection in a cell and use it to compute both the background color and the sum?

You can, but he didn't. So, it doesn't help at this point.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

AgentCow007 posted:

Is there anything legitimately useful/productive that you can do with recursion, or is it just retarded mental gymnastics for CompSci classes? I don't imagine there's a lot of money to be made checking strings for palindromes or calculating Fibonacci numbers.

Recursion is very useful and it pays to be able to think about problems in that way. Also, you'll get along with people better if you don't call things retarded.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Dominoes posted:

I'm new to open-source collaboration. What do you do with your local code after you merge someone's PR on Github? Deleting and git-cloning the local code would work; is there a more elegant way?

edit: In PyCharm, I clicked VCS -> Update -> OK (Merge and Stash selected); the result seemed to be what I asked.

Why can you just pull?

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
git pull and git push are two pretty useful commands to learn. They're what let you talk to remote repositories, such as the one on github.

If you initialized your repository with a clone, then you should be able to run "git pull" with no additional parameters to pull any changes to the master branch, assuming that you don't have any conflicts with the github repository and your directory is clean (no uncommitted work).

For a fork and pr based workflow with no branches, accepting a pr would look like
1. "git push" to bring your github master up to date with your local.
2. At this point I would download the pr and review it, but let's just say that it's fine for now
3. Accept the pull request on github
4. "git pull" to bring your local repository up to date with the one on github.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'd assume online blackjack would reshuffle after every hand and eliminate the edge from counting cards.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

underage at the vape shop posted:

Why is this returning an empty string?If you print the values its getting them correctly.

code:
	public static String getList() {
		Titles.sort(String.CASE_INSENSITIVE_ORDER);
		String sorted = new String();	
		for (String name:Titles) {
				sorted.concat(name);
			}
		System.out.print(sorted);
			
	return sorted;
	}
This is in java

Java Strings are immutable. Nothing ever changes a string in place. Using
code:
sorted = sorted.concat(name);
will work, but it creates a whole bunch of strings that are immediately discarded. The appropriate tool here is a StringBuilder.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Uhh Nope posted:

Haha you nailed it, I am stuck on 1.7.

Thanks for the tips, I really felt like I was drowning in what I thought was an easy first question, I really appreciate it.

I was actually staring at the answer in the wiki too and I didn't understand his assumption of "z <= n" because there's no n originally and I think I may be confused because the author doesn't really explain strong vs weak induction.

The assumption "z <= n" is where n is introduced.

The assumption step is saying "assume that the algorithm is correct for case z=n, and all cases z<n" for some arbitrary n
Then, to prove by induction, you prove that, given the above assumption, the algorithm gives correct answer for case z=n+1.
That, combined with the fact that you know the algorithm is correct for z=0, means that the algorithm is correct for z=1. Then, since it's correct for z=0 and z=1, it's correct for z=2, and so on down the number line into infinity.

It's not really a great first example because it has a bunch of little wrinkles, but that's the crux of what you're trying to do when you prove something via induction.

Dr. Stab fucked around with this message at 23:50 on Oct 16, 2018

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

leper khan posted:

I already gave the tip. If you took the time to read and comprehend my short post, you would see that. Look at and reason about your data layout and optimize for cache misses.

If you want another pointer, indirect fewer pointers.

I'm happy you got to feel like you brutally owned that noob, but that's actually not something you can do at the same time that you're helping them. Pick one of the two.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
You need a solid basis in mathematics if you want to be a computer scientist. You need at least some understanding of set theory to understand the basics of the theory of computation.

You don't need to be a computer scientist at all to be a world class programmer.

Adbot
ADBOT LOVES YOU

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Pakistani Brad Pitt posted:

Thanks for all of the very quick answers (and the detail, KillHour/Dominoes)!

This all makes good sense to me, and I think you pretty much answered my followup, which was going to be "What if the rules of Monopoly limited the supply of money to what is physically shipped in a set?". (e.g. if you draw a "Collect $200" card, you can only collect it as 2 $100 bills if there are still 2 $100 bills in the bank, but you could also take twenty $10 bills, or 1 $100 and two $50's, etc.)

In that case, it seems like it would be a good idea to make an Bill-type object and methods to move/store them in Player or Bank owned arrays to represent the money? It seems like you could also do this by keeping a counter integer for each bill type and incrementing/decrementing it all the time to keep track?

Even in that case, rather that throw around bill objects, I would just make a MoneySupply object, with properties like num20, num100, etc. Then, you can write methods like totalMoney() or canMakeExactChange(). Then, give each player and the bank their own MoneySupply.

The idea here is that all the code that cares about fiddling with money goes in the money class, and other classes only need to think about money in a broad sense.

e: also, later, if you decide you need individual bill objects, you can just change the implementation of the MoneySupply class and not have to touch a bunch of different places.

Dr. Stab fucked around with this message at 20:20 on May 25, 2020

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply