logic

“Leaking this” from a Design Standpoint

一世执手 提交于 2019-12-13 15:47:16
问题 Warning: Leaking "this" in constructor I keep running into this, and I have a nagging feeling that it's because my design is wrong or not optimal. I understand that this warning is bringing to my attention the fact that I am allowing access to an object that is potentially not fully initialized. Let's say that I need a Frame that HAS and requires a List (Frame(List list)). In List, I might want to do something such as add(). In order to make sure Frame knows as little about List as possible

Multiple values of a variable inbetween 0 and a number prolog

送分小仙女□ 提交于 2019-12-13 15:08:05
问题 So I've been trying to teach myself prolog and I think I'm coming along nicely. However, I'm sort of stuck at this one method I'm trying to make. toN(N,A) A is equal to the integer values between 0 and N-1, generated in ascending order. so toN(5,A) would be A = 0; A = 1; A = 2; A = 3; A = 4. I'm still new to prolog so I'm not exactly sure how to do this with multiple values. I had something like this: toN(N,A) :- 0 < N, Nx is N-1, toN(Nx,A). toN(N,A) :- 0 =< N, Nx is N-1, A = Nx. However this

Algorithm to balance variably-sized items into roughly-balanced sets

老子叫甜甜 提交于 2019-12-13 11:45:29
问题 I'm seeking an algorithm to split a list of items of varying sizes into "N" number of similarly-sized groups. Specifically, I'm working on an ASP.NET site in C# where I have a (database-retrieved) list of strings. The strings are of varying lengths. I have a set of columns which need to display the strings. I need an algorithm that will find the most balanced sets (item order is irrelevant) to allow the final columns to be as balanced as possible. Abstracted Example: Creating 3 columns. Items

Distinguishing extra element from two arrays?

[亡魂溺海] 提交于 2019-12-13 11:33:02
问题 One of my friend was asked this question in an interview - You have given two integer arrays each of size 10. Both contains 9 equal elements (say 1 to 9) Only one element is different. How will you find the different element? What are different approaches you can take? One simple but lengthy approach would be - sort both arrays,go on comparing each element,on false comparison, you'll get your result. So what are different approaches for this? Specify logic as its expected in an interview. Not

Find total number of (i,j) pairs in an array such that i<j and a[i]+a[j]=i+j. [closed]

烈酒焚心 提交于 2019-12-13 11:31:42
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . I have a naive solution which uses two loops, but I want to improve the time complexity as O(nlogn). Any better approach available? The array is unsorted and can have negative values too. Sample Test Case: Array: 1 0 3 2 Output: 4 Explanation: Indices - (0,1), (0,3), (1,2), (2,3) are the pairs which

Unexpected “,” from StreamReader to StreamWriter

戏子无情 提交于 2019-12-13 10:34:58
问题 I've tried a lot of things as well as research and asking friends, but can't seem to write a second line without a "," replacing the line. All I'd to do is have a single line for each item read in a separate file. Each read file has several of these items: 2/20/2014 7:33:10 AM OPERATOR: jason FILE: C:\ax14\Setups\000062363106RH.prt UNITS: english TEST RESULT: Pass CHANNEL 1 TEST TYPE: VELOCITY RESULT: Pass UPPER LIMIT: 0.2260 LOWER LIMIT: 0.2220 MAX THICKNESS: 2.0110 MIN THICKNESS: 1.0110

Convert loop into mathematical equation

江枫思渺然 提交于 2019-12-13 09:58:11
问题 How would I represent this for loop in a mathematical equation? double n = 1; double x = Math.pow(3, n); for(double i = 0; i < n; i++){ x = x + Math.pow(3, i); } Sorry wrote it in Java in a hurry. 回答1: for loop can be simplifed to x= (pow(3,n)-1)/2 I have double checked this here: http://www.wolframalpha.com/input/?i=sum+pow%283%2Ci%29+for+i+from+0+to+%28n-1%29 来源: https://stackoverflow.com/questions/28392154/convert-loop-into-mathematical-equation

How to divide items equally in 4 boxes? [closed]

我的梦境 提交于 2019-12-13 09:46:23
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Suppose i have 7 bags with different weight. Actually a php array contains this data. Bag A 60 Kg Bag B 80 Kg Bag C 20 Kg Bag D 10 Kg Bag E 80 Kg Bag F 100 Kg Bag G 90 Kg In php it will look like this Array ( [30] => 60 [31] => 120 [32] => 120 [33] => 60 [35] => 180 ) Now i have to divide all 7 bags in 4

logic help for smallest/largest value

大憨熊 提交于 2019-12-13 09:45:35
问题 I went thru so many version of the algorithm to sort smallest and largest that my brain is fried. The book up to this point and searching online haven't helped at all. I'm having difficulties at saving the last. I used 3 in, 10 cm and 5 cm as test cases. Entering 3 in first, becomes the largest, entering 5 cm second becomes smallest and then 10 cm becomes smallest again. Tried different version for over 2 hours, even re-wrote that entire section. In the book Programming Principles and

Array pairwise matching in java give error also store data between two similar element

穿精又带淫゛_ 提交于 2019-12-13 09:44:34
问题 I have two array. They are represent x-coordinates and y-coordinates. The code is like that if both coordinates are same it print a statement "Both co ordinates are same" else they print They are not same . My code is public static void main(String args[]){ double[]xcoordinate={2.3,1.2,3.3,5.5,2.3,1.3,7.9,1.2,3.3,3.3,5.2}; double[]ycordinate={5.4,2.2,4.4,6.6,5.4,1.9,5.2,2.2,3.5,4.4,4.2}; int i=0,k=1; while(i<xcoordinate.length){ //if(xcoordinate[i]&&ycordinate[i]==xcoordinate[k]&&ycordinate[k