Search Results

Search found 351 results on 15 pages for 'pseudocode'.

Page 2/15 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Can someone explain/annotate this Ruby snippet with comments?

    - by Ronnie
    Could someone please add comments to this code? Or, alternatively, what would be the pseudocode equivalent of this Ruby code? It seems simple enough but I just don't know enough Ruby to convert this to PHP. data = Hash.new({}) mysql_results.each { |r| data[r['year']][r['week']] = r['count'] } (year_low..year_high).each do |year| (1..52).each do |week| puts "#{year} #{week} #{data[year][week]}" end end Any help whatsoever would be really appreciated. Thanks!

    Read the article

  • Recursive algorithm for coalescing / collapsing list of dates into ranges.

    - by Dycey
    Given a list of dates 12/07/2010 13/07/2010 14/07/2010 15/07/2010 12/08/2010 13/08/2010 14/08/2010 15/08/2010 19/08/2010 20/08/2010 21/08/2010 I'm looking for pointers towards a recursive pseudocode algorithm (which I can translate into a FileMaker custom function) for producing a list of ranges, i.e. 12/07/2010 to 15/07/2010, 12/08/2010 to 15/08/2010, 19/08/2010 to 20/08/2010 The list is presorted and de-deuplicated. I've tried starting from both the first value and working forwards, and the last value and working backwards but I just can't seem to get it to work. Having one of those frustrating days... It would be nice if the signature was something like CollapseDateList( dateList, separator, ellipsis ) :-)

    Read the article

  • help in the Donalds B. Johnson's algorithm, i cannot understand the pseudo code

    - by Pitelk
    Hi , does anyone know the Donald B. Johnson's algorithm which enumarates all the elementary circuits (cycles) in a Directed graph? link text I have the paper he had published in 1975 but I cannot understand the pseudo-code. My goal is to implement this algorithm in java. Some questions i have is for example what is the matrix Ak it refers to. In the pseudo code mentions that Ak:=adjacency structure of strong component K with least vertex in subgraph of G induced by {s,s+1,....n}; Does that mean i have to implement another algorithm that finds the Ak matrix? Another question is what the following means? begin logical f; Does also the line "logical procedure CIRCUIT (integer value v);" means that the circuit procedure returns a logical variable. In the pseudo code also has the line "CIRCUIT := f;" . Does this mean? It would be great if someone could translate this 1970's pseudocode to a more modern type of pseudo code so i can understand it in case you are interested to help but you cannot find the paper please email me at [email protected] and i will send you the paper. Thanks in advance

    Read the article

  • NTRU Pseudo-code for computing Polynomial Inverses

    - by Neville
    Hello all. I was wondering if anyone could tell me how to implement line 45 of the following pseudo-code. Require: the polynomial to invert a(x), N, and q. 1: k = 0 2: b = 1 3: c = 0 4: f = a 5: g = 0 {Steps 5-7 set g(x) = x^N - 1.} 6: g[0] = -1 7: g[N] = 1 8: loop 9: while f[0] = 0 do 10: for i = 1 to N do 11: f[i - 1] = f[i] {f(x) = f(x)/x} 12: c[N + 1 - i] = c[N - i] {c(x) = c(x) * x} 13: end for 14: f[N] = 0 15: c[0] = 0 16: k = k + 1 17: end while 18: if deg(f) = 0 then 19: goto Step 32 20: end if 21: if deg(f) < deg(g) then 22: temp = f {Exchange f and g} 23: f = g 24: g = temp 25: temp = b {Exchange b and c} 26: b = c 27: c = temp 28: end if 29: f = f XOR g 30: b = b XOR c 31: end loop 32: j = 0 33: k = k mod N 34: for i = N - 1 downto 0 do 35: j = i - k 36: if j < 0 then 37: j = j + N 38: end if 39: Fq[j] = b[i] 40: end for 41: v = 2 42: while v < q do 43: v = v * 2 44: StarMultiply(a; Fq; temp;N; v) 45: temp = 2 - temp mod v 46: StarMultiply(Fq; temp; Fq;N; v) 47: end while 48: for i = N - 1 downto 0 do 49: if Fq[i] < 0 then 50: Fq[i] = Fq[i] + q 51: end if 52: end for 53: {Inverse Poly Fq returns the inverse polynomial, Fq, through the argument list.} The function StarMultiply returns a polynomial (array) stored in the variable temp. Basically temp is a polynomial (I'm representing it as an array) and v is an integer (say 4 or 8), so what exactly does temp = 2-temp mod v equate to in normal language? How should i implement that line in my code. Can someone give me an example. The above algorithm is for computing Inverse polynomials for NTRUEncrypt key generation. The pseudo-code can be found on page 28 of this document. Thanks in advance.

    Read the article

  • help in the Donalds B. Johnson's algorithm, i cannot understand the pseudo code (PART II)

    - by Pitelk
    Hi all , i cannot understand a certain part of the paper published by Donald Johnson about finding cycles (Circuits) in a graph. More specific i cannot understand what is the matrix Ak which is mentioned in the following line of the pseudo code : Ak:=adjacency structure of strong component K with least vertex in subgraph of G induced by {s,s+1,....n}; to make things worse some lines after is mentins " for i in Vk do " without declaring what the Vk is... As far i have understand we have the following: 1) in general, a strong component is a sub-graph of a graph, in which for every node of this sub-graph there is a path to any node of the sub-graph (in other words you can access any node of the sub-graph from any other node of the sub-graph) 2) a sub-graph induced by a list of nodes is a graph containing all these nodes plus all the edges connecting these nodes. in paper the mathematical definition is " F is a subgraph of G induced by W if W is subset of V and F = (W,{u,y)|u,y in W and (u,y) in E)}) where u,y are edges , E is the set of all the edges in the graph, W is a set of nodes. 3)in the code implementation the nodes are named by integer numbers 1 ... n. 4) I suspect that the Vk is the set of nodes of the strong component K. now to the question. Lets say we have a graph G= (V,E) with V = {1,2,3,4,5,6,7,8,9} which it can be divided into 3 strong components the SC1 = {1,4,7,8} SC2= {2,3,9} SC3 = {5,6} (and their edges) Can anybody give me an example for s =1, s= 2, s= 5 what if going to be the Vk and Ak according to the code? The pseudo code is in my previous question in http://stackoverflow.com/questions/2908575/help-in-the-donalds-b-johnsons-algorithm-i-cannot-understand-the-pseudo-code and the paper can be found at http://stackoverflow.com/questions/2908575/help-in-the-donalds-b-johnsons-algorithm-i-cannot-understand-the-pseudo-code thank you in advance

    Read the article

  • How to improve problem solving skills/programming skills

    - by kaibuki
    Hi All, I am new to programming, and have been given many interviews for jobs, but what I lag is the concepts and skills of general problem solving not respect to any particular programming language. are there any books or material available which can help me upgrade my programming skills. looking forward for you guys to share your views. Thanks a millions.. Kai

    Read the article

  • Help needed inorder to avoid recursion

    - by Srivatsa
    Hello All I have a method, which gives me the required number of Boxes based on number of devices it can hold.Currently i have implemented this logic using recursion private uint PerformRecursiveDivision(uint m_oTotalDevices,uint m_oDevicesPerBox, ref uint BoxesRequired) { if (m_oTotalDevices< m_oDevicesPerBox) { BoxesRequired = 1; } else if ((m_oTotalDevices- m_oDevicesPerBox>= 0) && (m_oTotalDevices- m_oDevicesPerBox) < m_oDevicesPerBox) { //Terminating condition BoxesRequired++; return BoxesRequired; } else { //Call recursive function BoxesRequired++; return PerformRecursiveDivision((m_oTotalDevices- m_oDevicesPerBox), m_oDevicesPerBox, ref BoxesRequired); } return BoxesRequired; } Is there any better method to implement the same logic without using recursion. Cos this method is making my application very slow for cases when number of devices exceeds 50000. Thanks in advance for your support Constant learner

    Read the article

  • Assign a Custom Global Pseudo Variable in Code Igniter

    - by Fábio Antunes
    Hello As you probably all know Code Igniter can assign pseudo variables using the Parser library, but you also know that if we want to assign a Pseudo Variable to use it in a View, we have to do it in every do it in every controller that loads those views with the pseudo variables. I would like to know if Code Igniter 1.7.2 has some way that i can assign a Global Pseudo variable (like the pseudo variables from the Benchmarking Class). The pseudo variables i want, would have simple data mostly returned from the $config array in the config.php file. If some could help me with that. Regards.

    Read the article

  • Conditions with common logic: question of style, readability, efficiency, ...

    - by cdonner
    I have conditional logic that requires pre-processing that is common to each of the conditions (instantiating objects, database lookups etc). I can think of 3 possible ways to do this, but each has a flaw: Option 1 if A prepare processing do A logic else if B prepare processing do B logic else if C prepare processing do C logic // else do nothing end The flaw with option 1 is that the expensive code is redundant. Option 2 prepare processing // not necessary unless A, B, or C if A do A logic else if B do B logic else if C do C logic // else do nothing end The flaw with option 2 is that the expensive code runs even when neither A, B or C is true Option 3 if (A, B, or C) prepare processing end if A do A logic else if B do B logic else if C do C logic end The flaw with option 3 is that the conditions for A, B, C are being evaluated twice. The evaluation is also costly. Now that I think about it, there is a variant of option 3 that I call option 4: Option 4 if (A, B, or C) prepare processing if A set D else if B set E else if C set F end end if D do A logic else if E do B logic else if F do C logic end While this does address the costly evaluations of A, B, and C, it makes the whole thing more ugly and I don't like it. How would you rank the options, and are there any others that I am not seeing?

    Read the article

  • Algorithm - Numbering for TOC (Table of Contents)

    - by belisarius
    I want to implement a VBA function to number Excel rows based upon the grouping depth of the row. But I think a general algorithm for generating TOCs is more interesting. The problem is: Given a list of "indented" lines such as One Two Three Four Five Six (the "indentation level" may be assumed to be known and part of the input data) To generate the following output: 1. One 1.1 Two 1.1.1 Three 1.1.1.1 Four 1.2 Five 2. Six Of course my code is up and running ... and also hidden under THWoS (The Heavy Weight of Shame)

    Read the article

  • Small-o(n^2) implementation of Polynomial Multiplication

    - by AlanTuring
    I'm having a little trouble with this problem that is listed at the back of my book, i'm currently in the middle of test prep but i can't seem to locate anything regarding this in the book. Anyone got an idea? A real polynomial of degree n is a function of the form f(x)=a(n)x^n+?+a1x+a0, where an,…,a1,a0 are real numbers. In computational situations, such a polynomial is represented by a sequence of its coefficients (a0,a1,…,an). Assuming that any two real numbers can be added/multiplied in O(1) time, design an o(n^2)-time algorithm to compute, given two real polynomials f(x) and g(x) both of degree n, the product h(x)=f(x)g(x). Your algorithm should **not** be based on the Fast Fourier Transform (FFT) technique. Please note it needs to be small-o(n^2), which means it complexity must be sub-quadratic. The obvious solution that i have been finding is indeed the FFT, but of course i can't use that. There is another method that i have found called convolution, where if you take polynomial A to be a signal and polynomial B to be a filter. A passed through B yields a shifted signal that has been "smoothed" by A and the resultant is A*B. This is supposed to work in O(n log n) time. Of course i am completely unsure of implementation. If anyone has any ideas of how to achieve a small-o(n^2) implementation please do share, thanks.

    Read the article

  • 2D World design question

    - by Maciek
    I'm facing a problem which is probably extremely common in game-design. Let's assume that we've got a 2D world The world's size is M x N rect The world may contain some items in it The items have (x,y) coords The world can be browsed via a window that is physically (m x n) large. The browser window can be zoomed in / out The browser window can be panned up/down + left right, while in the extents of the world's rect. How should I go about implementing this? I'm especially concerned about the browser window. Can anyone recommend any good reads ? This is not a homework - it's more of a task which I've set myself to complete.

    Read the article

  • C#, introduce a DragOver delay

    - by user275587
    In my application I catch a DragOver event and then perform an action. I'd like to wait for half a second before performing the action, the action should not be performed after that delay if the drag operation has ended. The only way I could think of to implement this feature is something like this: Function DragOver Event If TimerTimeReached Then PerformDragAction Else If Not TimerStarted StartTimer End End Function Function DragLeave Event If TimerStarted StopTimer End End Function Is there a better way to perform this operation?

    Read the article

  • PHP Resize image down and crop using imagemagick

    - by mr12086
    I'm trying to downsize image uploaded by users at the time of upload. This is no problem but I want to get specific with sizes now. I'm looking for some advice on an algorithm im struggling to produce that will take any shape image - square or rectangle of any widths/heights and downsize it. This image needs to be downsized to a target box size (this changes but is stored in a variable).. So it needs to downsize the image so that both the width and height are larger than the width and height of the target maintaining aspect ratio. but only just.. The target size will be used to crop the image so there is no white space around the edges etc. I'm looking for just the algorithm behind creating the correct resize based on different dimension images - I can handle the cropping, even resizing in most cases but it fails in a few so i'm reaching out. I'm not really asking for PHP code more pseudo. Either is fine obviously. Thanks Kindly.

    Read the article

  • Big-O for calculating all routes from GPS data

    - by HH
    A non-critical GPS module use lists because it needs to be modifiable, new routes added, new distances calculated, continuos comparisons. Well so I thought but my team member wrote something I am very hard to get into. His pseudo code int k =0; a[][] <- create mapModuleNearbyDotList -array //CPU O(n) for(j = 1 to n) // O(nlog(m)) for(i =1 to n) for(k = 1 to n) if(dot is nearby) adj[i][j]=min(adj[i][j], adj[i][k] + adj[k][j]); His ideas transformations of lists to tables His worst case time complexity is O(n^3), where n is number of elements in his so-called table. Exception to the last point with Finite structure: O(mlog(n)) where n is number of vertices and m is the amount of neighbour vertices. Questions about his ideas why to waste resources to transform constantly-modified lists to table? Fast? only point where I to some extent agree but cannot understand the same upper limits n for each for-loops -- perhaps he supposed it circular why does the code take O(mlog(n)) to proceed in time as finite structure? The term finite may be wrong, explicit?

    Read the article

  • Algorithm: Determine shape of two sectors delineated by an arbitrary path, and then fill one.

    - by Arseniy Banayev
    NOTE: This is a challenging problem for anybody who likes logic problems, etc. Consider a rectangular two-dimensional grid of height H and width W. Every space on the grid has a value, either 0 1 or 2. Initially, every space on the grid is a 0, except for the spaces along each of the four edges, which are initially a 2. Then consider an arbitrary path of adjacent (horizontally or vertically) grid spaces. The path begins on a 2 and ends on a different 2. Every space along the path is a 1. The path divides the grid into two "sectors" of 0 spaces. There is an object that rests on an unspecified 0 space. The "sector" that does NOT contain the object must be filled completely with 2. Define an algorithm that determines the spaces that must become 2 from 0, given an array (list) of values (0, 1, or 2) that correspond to the values in the grid, going from top to bottom and then from left to right. In other words, the element at index 0 in the array contains the value of the top-left space in the grid (initially a 2). The element at index 1 contains the value of the space in the grid that is in the left column, second from the top, and so forth. The element at index H contains the value of the space in the grid that is in the top row but second from the left, and so forth. Once the algorithm finishes and the empty "sector" is filled completely with 2s, the SAME algorithm must be sufficient to do the same process again. The second (and on) time, the path is still drawn from a 2 to a different 2, across spaces of 0, but the "grid" is smaller because the 2s that are surrounded by other 2s cannot be touched by the path (since the path is along spaces of 0). I thank whomever is able to figure this out for me, very very much. This does not have to be in a particular programming language; in fact, pseudo-code or just English is sufficient. Thanks again! If you have any questions, just leave a comment and I'll specify what needs to be specified.

    Read the article

  • Is this a bad version of the Merge Sort algorithm?

    - by SebKom
    merge1(int low, int high, int S[], U[]) { int k = (high - low + 1)/2 for q (from low to high) U[q] = S[q] int j = low int p = low int i = low + k while (j <= low + k - 1) and (i <= high) do { if ( U[j] <= U[i] ) { S[p] := U[j] j := j+1 } else { S[p] := U[i] i := i+1 } p := p+1 } if (j <= low + k - 1) { for q from p to high do { S[q] := U[j] j := j+1 } } } merge_sort1(int low, int high, int S[], U[]) { if low < high { int k := (high - low + 1)/2 merge_sort1(low, low+k-1, S, U) merge_sort1(low+k, high, S, U) merge1(low, high, S, U) } } I am really sorry for the terrible formating, as you can tell I am not a regular visitor here. So, basically, this is on my lecture notes. I find it quite confusing in general but I understand the biggest part of it. What I don't understand is the need of the "if (j <= low + k - 1)" part. It looks like it checks if there are any elements "left" in the left part. Is that even possible when mergesorting?

    Read the article

  • Big-O for GPS data

    - by HH
    A non-critical GPS module use lists because it needs to be modifiable, new routes added, new distances calculated, continuos comparisons. Well so I thought but my team member wrote something I am very hard to get into. His pseudo code int k =0; a[][] <- create mapModuleNearbyDotList -array //CPU O(n) for(j = 1 to n) // O(nlog(m)) for(i =1 to n) for(k = 1 to n) if(dot is nearby) adj[i][j]=min(adj[i][j], adj[i][k] + adj[k][j]); His ideas transformations of lists to tables His worst case time complexity is O(n^3), where n is number of elements in his so-called table. Exception to the last point with Finite structure: O(mlog(n)) where n is number of vertices and m is an arbitrary constants Questions about his ideas why to waste resources to transform constantly-modified lists to table? Fast? only point where I to some extent agree but cannot understand the same upper limits n for each for-loops -- perhaps he supposed it circular why does the code take O(mlog(n)) to proceed in time as finite structure? The term finite may be wrong, explicit?

    Read the article

  • String Compression using Lempel-Ziv

    - by roybot
    Im looking for a way of compressing a given string using the Lempel-Ziv Algorithm. Preferably there would only be a set of two functions, encoder and decoder. The encoder takes the string and returns an integer. The decoder takes the integer and returns the original string. Time complexity is not important. How would you implement this?

    Read the article

  • algorithms undirected graph twodegree[]

    - by notamathwiz
    For each node u in an undirected graph, let twodegree[u] be the sum of the degrees of u's neighbors. Show how to compute the entire array of twodegree[.] values in linear time, given a graph in adjacency list format. This is the solution for all u ? V : degree[u] = 0 for all (u; w) ? E: degree[u] = degree[u] + 1 for all u ? V : twodegree[u] = 0 for all (u; w) ? E: twodegree[u] = twodegree[u] + degree[w] can someone explain what degree[u] does in this case and how twodegree[u] = twodegree[u] + degree[w] is supposed to be the sum of the degrees of u's neighbors?

    Read the article

  • What will be the value of i in the following pseudocode?

    - by user283403
    I got this question in a programming test. Do you think this question is even correct? Look at the answer choices. (2^x means 2 raised to x) Consider the following pseudocode. x := 1; i := 1; while (x = 1000) begin x := 2^x; i := i + 1; end; What is the value of i at the end of the pseudocode? a) 4 b) 5 c) 6 d) 7 e) 8 I am sure that the value of i will 1. I told the examiner of the discrepancy and he advised me the leave the question unanswered if I felt it was incorrect. What else could I have done?

    Read the article

  • What's the most effective way to interpolate between two colors? (pseudocode and bitwise ops expecte

    - by navand
    Making a Blackberry app, want a Gradient class. What's the most effective way (as in, speed and battery life) to interpolate two colors? Please be specific. // Java, of course int c1 = 0xFFAA0055 // color 1, ARGB int c2 = 0xFF00CCFF // color 2, ARGB float st = 0 // the current step in the interpolation, between 0 and 1 /* Help from here on. Should I separate each channel of each color, convert them to decimal and interpolate? Is there a simpler way? interpolatedChannel = red1+((red2-red1)*st) interpolatedChannel = interpolatedChannel.toString(16) ^ Is this the right thing to do? If speed and effectiveness is important in a mobile app, should I use bitwise operations? Help me! */

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >