Search Results

Search found 5070 results on 203 pages for 'algorithm'.

Page 91/203 | < Previous Page | 87 88 89 90 91 92 93 94 95 96 97 98  | Next Page >

  • Elegant Method of Inserting Code Between Loops

    - by DeathMagus
    In web development, I often find I need to format and print various arrays of data, and separate these blocks of data in some manner. In other words, I need to be able to insert code between each loop, without said code being inserted before the first entry or after the last one. The most elegant way I've found to accomplish this is as follows: function echoWithBreaks($array){ for($i=0; $i<count($array); $i++){ //Echo an item if($i<count($array)-1){ //Echo "between code" } } } Unfortunately, there's no way that I can see to implement this solution with foreach instead of for. Does anyone know of a more elegant solution that will work with foreach?

    Read the article

  • LinkedList.contains execution speed

    - by Le_Coeur
    Why Methode LinkedList.contains() runs quickly than such implementation: for (String s : list) if (s.equals(element)) return true; return false; I don't see great difference between this to implementations(i consider that search objects aren't nulls), same iterator and equals operation

    Read the article

  • Enumerating large (20-digit) [probable] prime numbers

    - by Paul Baker
    Given A, on the order of 10^20, I'd like to quickly obtain a list of the first few prime numbers greater than A. OK, my needs aren't quite that exact - it's alright if occasionally a composite number ends up on the list. What's the fastest way to enumerate the (probable) primes greater than A? Is there a quicker way than stepping through all of the integers greater than A (other than obvious multiples of say, 2 and 3) and performing a primality test for each of them? If not, and the only method is to test each integer, what primality test should I be using?

    Read the article

  • C++ priority queue structure userd ?

    - by John Retallack
    While searching for some functions in C++ STL documentation I read that push and pop for priority queues needs constant time. "Constant (in the priority_queue). Although notice that push_heap operates in logarithmic time." My question is what kind of data structure is used to mantain a priority queue with O(1) for push and pop ?

    Read the article

  • permutation of array

    - by davit-datuashvili
    for example i have array int a[]=new int[]{3,4,6,2,1}; I need list of all permutation such that if one is like this, {3,2,1,4,6}, others must not be the same i know that if length of array=n then there is n! possible combination please help me to write this algortihm what to do?

    Read the article

  • What is the best book for learning about Algorithms?

    - by sheats
    I know what algorithms are, but I have never consciously used or created one for any of the programming that I have done. So I'd like to get a book about the subject - I'd prefer if it was in python but that's not a strict requirement. What book about algorithms helped you most to understand, use, and create algorithms? One book per answer so they can be voted on...

    Read the article

  • Are fragments of hashes collision-resistent?

    - by Mark
    Let me see if someone would mind clearing up this elementary point about md5 and hashing. If you only use the first 4 bytes of an md5 hash, would that mean theoretically only 1 in 255^4 chance of collision. iow is that the intention with it (and other hash algorithms) - that you only have to use a small portion of the returned hash (say the hash is of a file of some size).

    Read the article

  • How to prevent overdrawing?

    - by afriza
    This is a difficult question to search in Google since it has other meaning in finance. Of course, what I mean here is "Drawing" as in .. computer graphics.. not money.. I am interested in preventing overdrawing for both 3D Drawing and 2D Drawing. (should I make them into two different questions?)

    Read the article

  • Solving the problem of finding parts which work well with each other

    - by dotnetdev
    Hi, I have a database of items. They are for cars and similar parts (eg cam/pistons) work better than others in different combinations (eg one product will work well with another, while another combination of 2 parts may not). There are so many possible permutations, what solutions apply to this problem? So far, I feel that these are possible approaches (Where I have question marks, something tells me these are solutions but I am not 100% confident they are). Neural networks (?) Collection-based approach (selection of parts in a collection for cam, and likewise for pistons in another collection, all work well with each other) Business rules engine (?) What are good ways to tackle this sort of problem? Thanks

    Read the article

  • removing subset transactions form file

    - by user324887
    I have a file containing data as follows 10 20 30 40 70 20 30 70 30 40 10 20 29 70 80 90 20 30 40 40 45 65 10 20 80 45 65 20 I want to remove all subset transaction from this file. output file should be like follows 10 20 30 40 70 29 70 80 90 20 30 40 40 45 65 10 20 80 Where records like 20 30 70 30 40 10 20 45 65 20 are removed because of they are subset of other records.

    Read the article

  • Keyword sorting algorithm

    - by Nai
    I have over 1000 surveys, many of which contains open-ended replies. I would like to be able to 'parse' in all the words and get a ranking of the most used words (disregarding common words) to spot a trend. How can I do this? Is there a program I can use? EDIT If a 3rd party solution is not available, it would be great if we can keep the discussion to microsoft technologies only. Cheers.

    Read the article

  • Determining the best audio quality.

    - by The Rook
    How can you determine the best audio quality in a list of audio files, with out looking at the audio file's header. What if all of the files came from differnt encoding types and they where all transcoded to the same format and bit rate.

    Read the article

  • Recursive breadth-first travel function in Java or C++?

    - by joejax
    Here is a java code for breadth-first travel: void breadthFirstNonRecursive(){ Queue<Node> queue = new java.util.LinkedList<Node>(); queue.offer(root); while(!queue.isEmpty()){ Node node = queue.poll(); visit(node); if (node.left != null) queue.offer(node.left); if (node.right != null) queue.offer(node.right); } } Is it possible to write a recursive function to do the same? At first, I thought this would be easy, so I came out with this: void breadthFirstRecursive(){ Queue<Node> q = new LinkedList<Node>(); breadthFirst(root, q); } void breadthFirst(Node node, Queue<Node> q){ if (node == null) return; q.offer(node); Node n = q.poll(); visit(n); if (n.left != null) breadthFirst(n.left, q); if (n.right != null) breadthFirst(n.right, q); } Then I found it doesn't work. It is actually does the same thing as this: void preOrder(Node node) { if (node == null) return; visit(node); preOrder(node.left); preOrder(node.right); } Has any one thought about this before?

    Read the article

  • help implementing All Nearest Smaller Values algorithm

    - by davit-datuashvili
    http://en.wikipedia.org/wiki/All_nearest_smaller_values this is site of the problem and here is my code but i have some trouble to implement it import java.util.*; public class stack{ public static void main(String[]args){ int x[]=new int[]{ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; Stack<Integer> st=new Stack<Integer>(); for (int a:x){ while (!st.empty() && st.pop()>=a){ System.out.println( st.pop()); if (st.empty()){ break; } else{ st.push(a); } } } } } and here is pseudo code from site S = new empty stack data structure for x in the input sequence: while S is nonempty and the top element of S is greater than or equal to x: pop S if S is empty: x has no preceding smaller value else: the nearest smaller value to x is the top element of S push x onto S

    Read the article

  • Is it possible to compute the minimum of three numbers by using two comparisons at the same time?

    - by Milo Hou
    I've been trying to think up of some way that I could do two comparisons at the same time to find the greatest/least of three numbers. Arithmetic operations on them are considered "free" in this case. That is to say, the classical way of finding the greater of two, and then comparing it to the third number isn't valid in this case because one comparison depends on the result of the other. Is it possible to use two comparisons where this isn't the case? I was thinking maybe comparing the differences of the numbers somehow or their products or something, but came up with nothing. Just to reemphasize, two comparisons are still done, just that neither comparison relies on the result of the other comparison. EDIT: what about: boolA = A^2 + B^2 < C^2 boolB = A > B if boolA then max=C else if boolB then max=A else max=B

    Read the article

  • Unit Testing - Algorithm or Sample based ?

    - by ohadsc
    Say I'm trying to test a simple Set class public IntSet : IEnumerable<int> { Add(int i) {...} //IEnumerable implementation... } And suppose I'm trying to test that no duplicate values can exist in the set. My first option is to insert some sample data into the set, and test for duplicates using my knowledge of the data I used, for example: //OPTION 1 void InsertDuplicateValues_OnlyOneInstancePerValueShouldBeInTheSet() { var set = new IntSet(); //3 will be added 3 times var values = new List<int> {1, 2, 3, 3, 3, 4, 5}; foreach (int i in values) set.Add(i); //I know 3 is the only candidate to appear multiple times int counter = 0; foreach (int i in set) if (i == 3) counter++; Assert.AreEqual(1, counter); } My second option is to test for my condition generically: //OPTION 2 void InsertDuplicateValues_OnlyOneInstancePerValueShouldBeInTheSet() { var set = new IntSet(); //The following could even be a list of random numbers with a duplicate var values = new List<int> { 1, 2, 3, 3, 3, 4, 5}; foreach (int i in values) set.Add(i); //I am not using my prior knowledge of the sample data //the following line would work for any data CollectionAssert.AreEquivalent(new HashSet<int>(values), set); } Of course, in this example, I conveniently have a set implementation to check against, as well as code to compare collections (CollectionAssert). But what if I didn't have either ? This is the situation when you are testing your real life custom business logic. Granted, testing for expected conditions generically covers more cases - but it becomes very similar to implementing the logic again (which is both tedious and useless - you can't use the same code to check itself!). Basically I'm asking whether my tests should look like "insert 1, 2, 3 then check something about 3" or "insert 1, 2, 3 and check for something in general" EDIT - To help me understand, please state in your answer if you prefer OPTION 1 or OPTION 2 (or neither, or that it depends on the case, etc )

    Read the article

  • Using c#,c/c++ or java to improve BBN with GA

    - by madicemickael
    I have a little problem in my little project , I wish that someone here could help me! I am planning to use a bayesian network as a decision factor in my game AI and I want to improve the decision making every step of the way , anyone knows how to do that ? Any tutorials / existing implementations will be very good,I hope some of you could help me. I heard that a programmer in this community did a good implementation of this put together for poker game AI.I am planning to use it like him ,but in another poker(Texas) or maybe Rentz. Looking for C/c++ or c# or java code. Thanks , Mike

    Read the article

  • Credit Card checksums and validations that do not require connection to the financial institution

    - by cjavapro
    The validations I know of are: Checksum the whole card number should add up to zero. (range is 0-9) Check the first digit(s) against the card type Check the length against the card type Check the CCV length against the card type (I think all the major types are 3 anyway) Of course make sure it is accepted card type as well as non expired. Are there any other validations :) (I expect many folks did not know about all of these) The reason I ask is because I overheard there was one to checksum number against expiration or CCV.. I just wanted to check.

    Read the article

  • Fast inter-process (inter-threaded) communications IPC on large multi-cpu system.

    - by IPC
    What would be the fastest portable bi-directional communication mechanism for inter-process communication where threads from one application need to communicate to multiple threads in another application on the same computer, and the communicating threads can be on different physical CPUs). I assume that it would involve a shared memory and a circular buffer and shared synchronization mechanisms. But shared mutexes are very expensive (and there are limited number of them too) to synchronize when threads are running on different physical CPUs.

    Read the article

  • What's the best way to return a subset of a list

    - by Pikrass
    I have a list of tasks. A task is defined by a name, a due date and a duration. My TaskManager class handles a std::list<Task> sorted by due date. It has to provide a way to get the tasks due for a specific date. How would you implement that ? I think a good way (from API point of view) would be to provide a std::list<Task>::iterator pair. So I would have a TaskManager::begin(date) method. Do you think this method should get the iterator by iterating from the start of the list until it finds the first task due on that date, or by getting it from a std::map<date, std::list<Task>::iterator> (but then we have to keep it up-to-date when adding or removing tasks) ? And then, how could I implement the TaskManager::end(date) method ?

    Read the article

< Previous Page | 87 88 89 90 91 92 93 94 95 96 97 98  | Next Page >