pseudocode

Computing All The Possible Substrings of a Given String [duplicate]

女生的网名这么多〃 提交于 2019-11-29 15:19:41
问题 Possible Duplicate: How to find all substrings of a string in PHP Find all subsets of a list How can I compute all the possible substrings of a string? For example given a string ABCDE. All its possible substrings will be A, B, C, D, E, AB, BC, CD, DE, ABC, BCD, CDE, ABCD, BCDE, ABCDE Thanks! A pseudocode will be highly appreciated. :D 回答1: Just use two for-loops: generate substrings(string): for start in [0,1,...,string.length-1]: for end in [start,...,string.length-1]: yield string[start..

Algorithm to solve the points of a evenly-distributed / even-gaps spiral?

廉价感情. 提交于 2019-11-29 07:01:23
First, just to give a visual idea of what I'm after, here's the closest result (yet not exactly what I'm after) image that I've found: Here's the entire site-reference: http://www.mathematische-basteleien.de/spiral.htm BUT, it doesn't exactly solve the problem I'm after. I would like to store an array of points of a very specific spiral algorithm. The points are evenly distributed The 360 degree cycles have an even gap If I'm not mistaken, the first two points would be: point[ 0 ] = new Point(0,0); point[ 1 ] = new Point(1,0); But where to go from here? The only arguments I'd like to provide

Object.hashCode() algorithm

[亡魂溺海] 提交于 2019-11-29 05:59:20
I'm looking for the algorithm of Object.hashCode() . This code is native in Object.java . Is this because (a) the code is in assembly-- never was in Java or any other HLL at all or (b) it simply isn't disclosed ? In either case, I am looking to get hold of the algorithm (pseudo-code or some detailed explanation) of "how hashCode() is calculated"-- what are the params going into its calculation and the calculation itself? Please note: It's the hashCode() of Object i'm looking for-- not another like that of String or hashMap/table . //=============================================================

uml classdiagram constructor with parameters

拟墨画扇 提交于 2019-11-28 21:08:32
I am a complete ROOKIE at this so I need some help on it. How would you create uml class diagram and constructors with parameters. for default (no parameters) you do policyholder() for diagram and pseudo-code for parameters would you do the same thing policyholder (policynumber, service class, and customer age) for class diagrams and pseudo-code. It also asked to initialize each attribute to value where an object of this type can be instantiated, If a policy number is not between 1000 and 999 inclusive, then set the policy number to 0. (policy number is attribute) The common way is to write

Create sine lookup table in C++

杀马特。学长 韩版系。学妹 提交于 2019-11-28 19:37:40
How can I rewrite the following pseudocode in C++? real array sine_table[-1000..1000] for x from -1000 to 1000 sine_table[x] := sine(pi * x / 1000) I need to create a sine_table lookup table. You can reduce the size of your table to 25% of the original by only storing values for the first quadrant, i.e. for x in [0,pi/2]. To do that your lookup routine just needs to map all values of x to the first quadrant using simple trig identities: sin(x) = - sin(-x), to map from quadrant IV to I sin(x) = sin(pi - x), to map from quadrant II to I To map from quadrant III to I, apply both identities, i.e.

How to generate n different colors for any natural number n? [duplicate]

天涯浪子 提交于 2019-11-28 15:19:18
问题 This question already has answers here : How to automatically generate N “distinct” colors? (13 answers) Closed 4 years ago . Say n = 100; How do I generate 100 visually distinct colors? Is this mathematically possible? 回答1: 100 is a lot of colours, but you might be able to do it by distributing them as sparsely as possible in the HSB or HSL space; doing it in RGB is probably difficult. For example, you might decide to use 10 different hues, 4 different saturation levels, and 3 different

Find maximum value in an array by recursion

狂风中的少年 提交于 2019-11-28 12:06:12
// Find a maximum element in the array. findMax(A) findMaxHelper(A, 0, A.length) findMaxHelper(A, left, right) if (left == right - 1) return A[left] else max1 = findMaxHelper(A, left, (right + left) / 2) max2 = findMaxHelper(A, (right + left) / 2, right) if (max1 > max2) return max1 else return max2 I am having a hard time understanding what is happening in this pseudo-code. Can someone help explain what is happening at each line. I need to understand this code before I can answer the questions. I know that the function findMax calls the helper function findMaxHelper, then findMaxHelper uses

Determine compass direction from one lat/lon to the other

浪尽此生 提交于 2019-11-28 11:47:47
问题 Does anyone have an algorithm to determine the direction from one lat/lon to another (pseudo-code): CalculateHeading( lat1, lon1, lat2, long2 ) returns string heading Where heading is e.g. NW, SW, E, etc. Basically, I have two points on a map and I want to get a general idea of the direction taking into account that 50 miles East and one mile North is simply East and not Northeast. 回答1: This site has the basic algorithm: // in javascript, not hard to translate... var y = Math.sin(dLon) * Math

sorting int array with only 3 elements

谁说胖子不能爱 提交于 2019-11-28 09:13:36
I have this array: int [] myarray = {17, 6, 8}; What is the optimal way to sort this array, in pseudocode? Thanks! I think this should be quite fast (ascending order): if (el1 > el2) Swap(el1,el2) if (el2 > el3) Swap(el2,el3) if (el1 > el2) Swap(el1,el2) adamax This code makes 2 or 3 comparisons and 4 memory records in the worst case, as opposed to another answer (always 3 comparisons and 9 memory records in the worst case). if a[0] < a[1]: if a[1] > a[2]: if a[0] < a[2]: temp = a[1] a[1] = a[2] a[2] = temp else: temp = a[0] a[0] = a[2] a[2] = a[1] a[1] = temp else: # do nothing else: if a[1]

Java balanced expressions check {[()]}

我与影子孤独终老i 提交于 2019-11-28 04:45:54
I am trying to create a program that takes a string as an argument into its constructor. I need a method that checks whether the string is a balanced parenthesized expression. It needs to handle ( { [ ] } ) each open needs to balance with its corresponding closing bracket. For example a user could input [({})] which would be balanced and }{ would be unbalanced. This doesn't need to handle letters or numbers. I need to use a stack to do this. I was given this pseudocode but can not figure how to implement it in java. Any advice would be awesome. Update- sorry forgot to post what i had so far.