New answers tagged

-1

We will ignore the last group here. Order within a group doesn't matter, so let's stick with alphabetical order. If you nest your loops the right way they will only generate letters that are in alphabetical order. The order of the groups doesn't matter. So let's stick with groups that are in alphabetical order relative to each other. Again, if you nest ...


3

No, there is no hope. The fastest thing you can do is replace characters in an array instead of generating a new string object at each iteration. But whatever processing you plan to do with each permutation will presumably take considerably longer than it took to generate the permutation in the first place.


0

Instead of asking "why does the last approach work", you should ask "does the last approach work". It doesn't. start is increased by 1 exactly once in each iteration of the loop, and curr_sum will be equal to 0 after start is increased. This will never find a solution unless sum == 0. I strongly suspect that there should be some "while" statement before the ...


0

Suggestion: Keep the internal universe network perfectly ordered, algorithmic, and relatively simple. You only need the universe to look random when it's displayed on the user screen. Only apply random offsets to the star positions for user display. Problem: The most obvious approach of calculating a random offset for each star won't do a very good job of ...


1

Your problem sounds like in can be described in terms of finding the shortest path between two points on a graph; if you are able to rephrase it in those terms, Dijkstra's algorithm is probably what you're looking for. You say you have no way of estimating the path length, but if you can provide a lower bound on it that varies to some degree you may be able ...


0

Basic concept: (1) We can view point (0,0,0) simply as 000. Each point in the lattice now falls in a simple sequence. The first point is 000, then 001, then 010 011 100 101 110 and 111. This is the order that you will try adding them to the point-set. (2) Similarly, the set {(0,0,0),(0,0,1),(0,1,0)} can simply be seen as 000001010, and the set ...


0

The following should not be interpreted as a proper answer to your question. Instead it's an exception to your question. You've been very good about answering questions in comments but even after trying to piece together the rules of your problem I don't see how you arrive at these 6 solutions. The remaining issues go beyond what I can explain in a ...


1

I assume you used Bresenham's algorithm? It works fine for nearly-horizontal or nearly-vertical cases. Works well with integer-only coordinates, too. If your integral value depends on the amount of interconnection between a cell and the line, consider the Xiaolin Wu's antialiased line algorithm. Both are for uniform grids only, though.


0

It would need to seek the largest possible subsets of topics, subject to matching a minimum number of students. So you essentially have 2 criteria. Let's look at "largest possible subset" first: This is brute force, unfortunately. In other words, you don't know the largest group until you've tallied all of the results. (Except you could optimize on ...


0

I think as you attempt to describe the situation more clearly, an approach will emerge. Backtracking breaks down a search (tree) into paths, which are accepted, rejected, or neither. In the neither case, you go on to build a longer path; in the rejected case you "back up" to build further on the last non-rejected path. To use backtracking, you have to ...


0

This dfs algorithm looks for a cycle in the graph G starting at v. The "extra parameter" u is the "previous" or "parent" node of v in the search tree, it is passed here because it enables the algorithm to avoid to take a sequence like "u - v - u" for a cycle. Understanding code is sometimes not easy, it takes practice, especially recursive code. There are ...


3

What you're looking for is called a Perfect Hash Function. If you have access to a linux system it likely already has a program called gperf installed that, given a set of strings will generate the C code for such a function.


1

There are some subtleties in this question that haven't been clarified yet. However, I have a working prototype that seems to approximate what OP is asking for. Before describing my approach, here is a test case. For this test case, the word list is obtained from: ...


2

This is a simple directed acyclic graph, which means that evaluating the nodes shouldn't be terribly complicated. The algorithms mentioned in the "Topological sorting and recognition" section of the Wikipedia article allow you to break the graph evaluation into a linear sequence of steps. Also see this answer.


2

You need a clustering algorithm. The basic idea is that you want to treat each student's data as an n-dimensional coordinate, e.g. 30-dimensional coordinate in this case. So if you had 3 dimensions, you could have a student at x,y,z: 1,1,0; another one at 0,1,1, etc. Distance between them could be found using euclidean formula. Distance between ...


0

As mentioned by Robert Harvey before, these sorts of problems are - most of the times - referred to as packing problems There are a lot of examples, where you are dealing with regular shapes(shapes, that are all the same). Your case is not one of them. Your case categorizes to having irregular shapes, and also in 3-dimensional space. One idea How about ...


0

Complexity is O(log(x) * n), or O(log(x) * (n - 1)) if you want the exact upper bound. Why? Because the inner loop can be determined to have at most n - 1 iterations each. You can provoke the worst case for x = n^i - 1 for any positive integers x, n and i.


1

First, three observations. Already covered by Christophe in the previous answer: the table that controls the flow to another question group needs to have the QuestionID as a foreign key. Otherwise the answers "Yes" or "Dogs" can't be related to a question. I would change the terminology from "ParentGroup/ChildGroup" to "QuestionGroup/FollowingGroup", ...


1

You implement a form of microservice architecture - each of the 25 sites has a 'front end' (to them) that is a back end to your website. You make requests to each of these which make the appropriate request to the sites. Its up to you how to aggregate the results you get back, whether to take them as they come, or to hold them and process them into a single ...


1

Rather than centralising the date overnight, why not use a user interface, which naturally shows the progress on each of the sites being searched. https://iwantmyname.com/?domain=somedomain is a good example interface for domain name search. You would basically set up a user interface with 25 rows, which contain the name of each of your databases. The ...


1

One of the tricky things about this is that '2016-05-06' was 4 business days after '2016-05-02', but '2016-05-10' was 2 business days after '2016-05-06', even though in both pairs of dates exactly the same total number of days passed. So what I'd probably do to get the number of business days between date A and date B (assuming "business day" means "any day ...


1

If A is the original two-dimensional matrix, B is the new one-dimensional matrix, m & n are height and width of B respectively, then given the position p of element a in A, the new [x,y] coordinates within B (given indices that are one-based) is x = (p - 1) / n + 1 y = n + 1 - (p % n) With zero-based indices, this becomes easier, as you no longer ...


0

Compute the day of week for each date. Most languages give you a function to find the difference in days between the two dates (even Python). With those you can determine the number of weeks, and subtract the number of weekends. For example, we could compute the number of weeks between the Saturday following the first date and the Saturday following ...


2

After thinking twice about your solution, I am sure that your algorithm works well. IMHO it could be seen as a variant of lazy evaluation. Here is another variant. Change smooth_once so it only puts the pairs (index,x) into a queue (lets call the arrays indexes and xs). function smooth_once(index, x): indexes.append(index) xs.append(x) Here is the ...


0

Threre is a herustic I use for packing grocery bags. Basically the key is well ordering prinicipal. First use the space on the back and sides first . Basically max distance from loading cross sectional area. That is for practicality of not stuffing objects in the very back after most the space is used. The most big objects go there. Then, put most ...


1

Questions templates or question instances ? Your question shows an ambiguity in the conceptual model: do you manage question instances ? In this case one QuestionId means one single question that could eventually be triggered by several events, but only one answer is relevant, regardless of the way you activate it. That's what your data model suggests. ...


9

That is a longer and less efficient variant of XOR swap algorithm. I'll just reiterate most-commonly known solutions here from the wiki: # solution 1 A = A + B B = A - B A = A - B # solution 2 (^ is XOR) A = A ^ B B = B ^ A A = A ^ B


1

If the graph is directed, that implies that no cycle can contain the same edge twice. If the graph is simple (assuming you really meant a simple graph), that implies that there are no "loop" edges starting and ending at the same vertex, and that any pair of distinct vertices has at most one edge between them. From those assumptions, we can easily show that ...


3

If the problem is small enough, a totally naive approach works well. We want to generate all pinned hamiltonian paths connecting two nodes a and b in a given graph. For this, we just generate all valid paths originating from a and filter out those that are not hamiltonian or that do not end in b. The following code snippet is an implementation of this idea ...


0

How about this. You have a series of data points as [x,y,t] triples - where and when. Lots of the (x,y) points will be close to each other. If they are, it generally means that the user's at a place and their GPS is generating noise. So you need to classify readings as being part of a larger group. If they are far apart, that indicates travel. Check out ...


0

Parser means converter. When we parse a String in java, means that we convert that String to other String. Everything is done using code and algorithm (code steps). Word lattice is a graph.See detail at http://www.statmt.org/moses/?n=Moses.WordLattices Lattice parser perhaps means Word lattice converter. When we parse the lattice, perhaps we want to ...


0

What really matter is time, coordinate (longitude & latitude), and places details. If you get the coordinate and places location in JSON format, then you'll need to parse the JSON data using JSONObject class. See tutorial on JSON parsing at http://www.tutorialspoint.com/android/android_json_parser.htm. Each time your app retrieved user data, extract ...


8

"Fancy" in this case is the opposite from "Simple". Take route finding, for example. A "simple" algorithm would be Dijkstra's algorithm. A "fancy" algorithm would be, for example, bidirectional Simplified Memory-Bounded A*. The "simple" algorithm doesn't look very good when you look at it's big-O runtime complexity, but you can write it quickly and it ...


0

Here's a naive backtracking solution, in JavaScript: https://jsfiddle.net/YSharpLanguage/dbt1gwk5 function q317951(input, exclusions) { // quick'n dirty cloning helper: var clone = function (o) { var c = {}; for (var k in o) { if (o.hasOwnProperty(k)) { c[k] = o[k]; } } return ...


7

A good pattern is Observer. https://en.wikipedia.org/wiki/Observer_pattern In your algorithm, at each point where you want to output something, you notify some observer(s). They then decide what to do, be it to output your text on the console, or to send it to the HTML engine/Apache etc. Depending on your programming language there may be different ways to ...


4

As a slight improvement to straight logging, create some sort of object that models one execution of the algorithm. Add a "step" to this container object each time your code does something interesting. At the end of the algorithm, log the accumulated steps from the container. This has a few advantages: You can log the full execution as one log entry, ...


0

I usually look for the branching, meaning i look for if-statements. Because these indicate that i evaluate a value, that will control the flow of the algorithm. In each such occurance (each condition) i can then log the chosen path, and why it was chosen. So basically i would log the entry values (initial state), every branch chosen (conditionals) and the ...


49

The "pattern" you are looking for is called "logging", just make the logging statements as verbose as you need them. By using a decent logging framework you should be able to switch it on and off at run time, provide different verbosity levels, or tailor the output for different purposes (like web vs. console). If this has a noteable performance impact ...


0

Having a series of numbers on a ticket (eg. 3 7 11 13 14 25) randomly given to N participants where N is a very low number (eg. 23) and then devising an algorithm where you can draw one number at a time making sure that you will pick a winner (most likely having a few participants still believing they could be a winner quite far into the drawing) just ...


0

It seems that the hard part of your problem is stated in your comment where you say you want to choose the winning number by 'drawing' random single digits and combing them To guarentee a winner you have to pick a winning ticket from a list of sold tickets. Normally you would simply record a list of tickets sold and pick.one of them randomly to get the ...


1

It's not necessarily the "wrong" definition, but it's not a very helpful one. Terms like general and specific (and category) are relative classifications. So, tossing them into a definition without context or further qualification doesn't tell us much. A better definition would simply be: A set of steps to solve a problem. From there, if a set of steps ...


3

I think that Wikipedia and the Encyclopedia of Mathematics definitions for algorithm are good complements for each other. “Detailed instructions defining a computational process (which is then said to be algorithmic), which begins with an arbitrary input (out of a certain number of inputs which are possible for the given algorithm), and with ...


1

This is a category of problems: "Sort a sequence of integers". These are specific problems of that category: "Sort the sequence [4, 3, 1, 8]". "Sort the sequence [1]". "Sort the sequence []". The word category only means that some details are variable and thus there are actually many (possible infinitely many) specific problems the process could ...


0

I also wonder if we can define algorithm in terms of functions only. An algorithm is very much like a function. The simple example is performing multiplication by using addition (3*4 = 4 times 3 = 4 times (+3) = +3 +3 +3 +3 = 12.) It is important that you can reduce one problem to another which you see that we just did by reducing multiplcation to ...


4

A general process is something that works on different inputs. Taking you example of odd or even. If I check if the number input is 1 then output odd. This is not a general process. It only works on one very specific input. If I instead check the modulus 2 of the input I would have a general process as it would work on all integer numbers as input. That ...


2

If I understand what you are want, then: create empty list for 1..N: do r = random number while r in list add r to list give ticket with r to person for number of winners: r = random element in list announce r as a winner remove r from list


1

Only track total bet by player and if they are folded or not 1) determine minimum bet from all player in the pot and player not folded 2) remove that amount from the every player (including folded) bet and sum it into a side-pot 3) based on hand strength divvy up that side pot to player stacks if a split (tie) and there are odd chips ...


1

The basic algorithm is the dead chips (folds) + the minimum committed chips are distributed among the winners of the hand (main pot). If after this, there are still chips left in the pot, the process is repeated (for every side pot). So let's say at the end of a hand there were three players all-in and $300 in dead chips: P1 shoved $50, P2 shoved $100 and ...


2

urlize is restrictive because it works with content which, in substance, is very different compared to SMS. The goal of urlize is to be restrictive, because: Developers would usually include the scheme by themselves, They won't be very annoyed if they don't and urlize will consider that example.com is not a valid URI, while http://example.com is. They will ...


4

This is a good candidate for Differential Evolution. DE is a very simple (but powerful) population based, stochastic function minimizer/maximizer. A key point for integrating DE in your scheme is the fitness function: double fitness(Agent_k) fit = 0 repeat M times randomly extract an individual Agent_i (i <> k) switch (result of ...



Top 50 recent answers are included