Search Results

Search found 3047 results on 122 pages for 'subset sum'.

Page 64/122 | < Previous Page | 60 61 62 63 64 65 66 67 68 69 70 71  | Next Page >

  • All non-prime factorings

    - by Tony Veijalainen
    Let's say we have numbers factors, for example 1260: >>> factors(1260) [2, 2, 3, 3, 5, 7] Which would be best way to do in Python combinations with every subproduct possible from these numbers, ie all factorings, not only prime factoring, with sum of factors less than max_sum? If I do combinations from the prime factors, I have to refactor remaining part of the product as I do not know the remaining part not in combination. Example results would be: [4, 3, 3, 5, 7] (one replacement) [3, 6, 14, 5] (two replacements)

    Read the article

  • MySQL - Add Values In Query And Return As Single Value

    - by Sjwdavies
    I'm trying to query a database, and return a set of values. Part of the data i'm trying to return is an insurance premium breakdown. Is it possible to run a query, that selects multiple fields, then adds then and returns them as a single value? I've seen SUM() but the examples i've seen show it as adding up the results of an entire field - where as i need it to add specific fields for each row returned. Any help is much appreciated.

    Read the article

  • Getting caught in loops - R

    - by user334898
    I am looking at whether or not certain 'systems' for betting really do work as claimed, namely, that they have a positive expectation. One such system is based on the rebate on loss. You basically have a large master pot, say $1 million. Your bankroll for each game is $50k. The way it works, is as follows: 1) Start with $50k, always bet on banker 2) If you win, add the money to the master pot. Then play again with $50k. 3) If you lose(now you're at $30k) play till you either: (a) hit 0, you get a rebate of 10%. Begin playing again with $50k+5k=$55k. (b) If you win more than the initial bankroll, add the money to the master pot. Then play again with $50k. 4) Continue until you double the master pot. I just cant find an easy way of programming out the possible cases in R, since you can eventually go down an improbable path. For example, you start at 50k, lose 20, win 19, now you're at 49, now you lose 20, lose 20, now youre at 9, you either lose 9 and get back 5k or you win and this cycle continues until you either end up with more than 50k or hit 0 and get the rebate on the 50k and start again with $50k +5k. Here's some code i started, but i havent figured out a good way of handling the cases where you get stuck and keeping track of the number of games played. Thanks again for your help. Obviously, I understand you may be busy and not have time. p.loss <- .4462466 p.win <- .4585974 p.tie <- 1 - (p.win+p.loss) prob <- c(p.win,p.tie,p.loss) bet<-20 x <- c(19,0,-20) r <- 10 # rebate = 20% br.i <- 50 br<-200 #for(i in 1:100){ # cbr.i<-0 y <- sample(x,1,replace=T,prob) cbr.i<-y+br.i if(cbr.i > br.i){ br<-br+(cbr.i-br.i); cbr.i<-br.i; }else{ y <- sample(x,2,replace=T,prob); if( sum(y)< cbr.i ){ cbr.i<-br.i+(1/r)*br.i; br<-br-br.i} cbr.i<-y+ }else{ cbr.i<- sum(y) + cbr.i; }if(cbr.i <= bet){ y <- sample(x,1,replace=T,prob) if(abs(y)>cbr.i){ cbr.i<-br.i+(1/r)*br.i } }

    Read the article

  • How to calculate

    - by Bob
    Hi, I hv a table like this :- Item Qty Price A Price B abc 5 36.00 0 qwe 8 0 48.00 zxc 6 12.00 0 poi 4 10.00 0 lkj 9 12.00 0 mnb 3 0 14.00 vfr 7 0 6.00 How can I sum the value using SQL ie. if Price A is zero, it will pick Price B. The expected results will be as follows :- Item Value abc 180.00 qwe 384.00 zxc 72.00 poi 40.00 lkj 36.00 mnb 42.00 vfr 42.00

    Read the article

  • Error using iif in ms access query

    - by naveen
    I am trying to fire this query in MS Access SELECT file_number, IIF(invoice_type='Spent on Coding',SUM(CINT(invoice_amount)), 0) as CodingExpense FROM invoice GROUP BY file_number I am getting this error Error in list of function arguments: '=' not recognized. Unable to parse query text. I tried replacing IIF with SWITCH to no avail. What's wrong with my query and how to correct this?

    Read the article

  • sql query returns incorrect result

    - by reza saberi
    I have a mysql database that stores quotation documents with some products that are clearly defining the price of each product in them, and a table for contracts storing contract details as well as customer code and quotation code to which it belongs. I have the following query to see how much is the total price of the quotation to write it in the invoice: select sum(sqproducts.price * sqproducts.quantity) as 'total-price', squotations.currency as 'currency' from sqproducts, ccontracts, squotations where sqproducts.contracted=1 AND squotations.code=sqproducts.quotation_code AND sqproducts.quotation_code=ccontracts.squotation_code AND sqproducts.quotation_code='QUOT/2012/1' group by currency

    Read the article

  • Typemock - Worth the money?

    - by AngryHacker
    I know that this is a subjective question... Typemock is $799 per developer. Licences for 5 devs comes up to a pretty large sum. If someone here used Typemock and given that there are open source mocking frameworks, is it worth the money? Why?

    Read the article

  • Query performs poorly unless a temp table is used

    - by Paul McLoughlin
    The following query takes about 1 minute to run, and has the following IO statistics: SELECT T.RGN, T.CD, T.FUND_CD, T.TRDT, SUM(T2.UNITS) AS TotalUnits FROM dbo.TRANS AS T JOIN dbo.TRANS AS T2 ON T2.RGN=T.RGN AND T2.CD=T.CD AND T2.FUND_CD=T.FUND_CD AND T2.TRDT<=T.TRDT JOIN TASK_REQUESTS AS T3 ON T3.CD=T.CD AND T3.RGN=T.RGN AND T3.TASK = 'UPDATE_MEM_BAL' GROUP BY T.RGN, T.CD, T.FUND_CD, T.TRDT (4447 row(s) affected) Table 'TRANSACTIONS'. Scan count 5977, logical reads 7527408, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'TASK_REQUESTS'. Scan count 1, logical reads 11, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. SQL Server Execution Times: CPU time = 58157 ms, elapsed time = 61437 ms. If I instead introduce a temporary table then the query returns quickly and performs less logical reads: CREATE TABLE #MyTable(RGN VARCHAR(20) NOT NULL, CD VARCHAR(20) NOT NULL, PRIMARY KEY([RGN],[CD])); INSERT INTO #MyTable(RGN, CD) SELECT RGN, CD FROM TASK_REQUESTS WHERE TASK='UPDATE_MEM_BAL'; SELECT T.RGN, T.CD, T.FUND_CD, T.TRDT, SUM(T2.UNITS) AS TotalUnits FROM dbo.TRANS AS T JOIN dbo.TRANS AS T2 ON T2.RGN=T.RGN AND T2.CD=T.CD AND T2.FUND_CD=T.FUND_CD AND T2.TRDT<=T.TRDT JOIN #MyTable AS T3 ON T3.CD=T.CD AND T3.RGN=T.RGN GROUP BY T.RGN, T.CD, T.FUND_CD, T.TRDT (4447 row(s) affected) Table 'Worktable'. Scan count 5974, logical reads 382339, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'TRANSACTIONS'. Scan count 4, logical reads 4547, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table '#MyTable________________________________________________________________000000000013'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. SQL Server Execution Times: CPU time = 1420 ms, elapsed time = 1515 ms. The interesting thing for me is that the TASK_REQUEST table is a small table (3 rows at present) and statistics are up to date on the table. Any idea why such different execution plans and execution times would be occuring? And ideally how to change things so that I don't need to use the temp table to get decent performance? The only real difference in the execution plans is that the temp table version introduces an index spool (eager spool) operation.

    Read the article

  • postgres subquery w/ derived column

    - by Wells
    The following query won't work, but it should be clear what I'm trying to do: split the value of 't' on space and use the last element in that array in the subquery (as it will match tl). Any ideas how to do this? Thanks! SELECT t, y, "type", regexp_split_to_array(t, ' ') as t_array, sum(dr), ( select uz from f.tfa where tl = t_array[-1] ) as uz, sc FROM padres.yd_fld WHERE y = 2010 AND pos <> 0 GROUP BY t, y, "type", sc;

    Read the article

  • Convert this SQL Query into LINQ (OVER (PARTITION BY Date))

    - by user1106649
    Here's the query i'm trying to convert into Linq: SELECT R.Code, R.FlightNumber, S.[Date], S.Station, R.Liters, SUM(R.Liters) OVER (PARTITION BY Year([Date]), Month([Date]), Day([Date])) AS Total_Liters FROM S INNER JOIN R ON S.ID = R.SID WHERE (R.Code = 'AC') AND FlightNumber = '124' GROUP BY Station, Code, FlightNumber, [Date], Liter ORDER BY R.FlightNumber, [Date] Thanks for any help.

    Read the article

  • Alternative to subqueries

    - by Juanma
    I'm using Mysql 5.1, and have this query, is there a way to not use the subqueries and accomplish the same result? SELECT oref.affiliate_id, ROUND(sum( oph.amount ) * 0.10 ,2) AS tsum FROM operators_referer AS oref LEFT JOIN operators_payments_history AS oph ON oref.operator_id = oph.operator_id WHERE oref.affiliate_id = 28221 AND ( oph.date_paid > ( SELECT MAX(aph.date_paid) FROM affiliates_payments_history AS aph WHERE aph.operator_id = oref.affiliate_id ) OR ( SELECT MAX(aph.date_paid) FROM affiliates_payments_history AS aph WHERE aph.operator_id = oref.affiliate_id ) is NULL )

    Read the article

  • select query related problem

    - by user222585
    i have interest rate and amount in a table where interest rate are ranged in different values like 4.5,4.6,5.2,5.6 etc. i want to get sum of amounts classified by interest rate where interest rate will be separated by .25. for example all amount having interest rate 1.25,1.3,1.4 will be in one group and 1.5,1.67,1.9 will be in another group how can i write the query?

    Read the article

  • how to determine when two NSDates are 1 week apart?

    - by cgossain
    I'm my app I have an NSMutableArray, and each entry has an NSMutableDictionary with several Key-Value pairs. One of these pairs contains the date of the entry. For one of the functions of my app I need to determine which entries are exactly 1 week apart from each other (i.e from Sunday to Saturday) and sum the data from one of the Key-Value pairs for each day of that week. How should I go about doing this?

    Read the article

  • Calculate value from two field in third field

    - by terence6
    I'm trying to create a query, that will calculate sum of products on invoice. I have 3 tables : Product (with product's price) Invoice (with invoice id) Products on invoice (with invoice id, product id and number of particular products) So in my query I take invoice_id (from invoice), price (from product),number of products sold and invoice_id (from products on invoice) and calculate their product in fourth column. I know I sohuld use 'Totals' but how to achieve that ? Model:

    Read the article

  • PHP MSSQL : How to display output when query return no row

    - by vamps
    i have a problem with my PHP-MSSQL query. i have a join table that need to give a result something be like this: Department Group A Group B Total A+B WORKHOUR A OTHOUR A WORKHOUR B OTHOUR B WORKHOUR OTHOUR HR 10 15 25 0 35 15 IT 5 5 5 5 Admin 12 12 12 12 the query will count how many employee as per given date (admin will enter data and once submitted, the query will give the above result). The problem is, the final output is a mess when there's no row to be displayed. the column is shifted to the right. i.e: only Group A in IT only Group B in Admin Department Group A Group B Total A+B WORKHOUR A OTHOUR A WORKHOUR B OTHOUR B WORKHOUR OTHOUR HR 10 15 25 0 35 15 IT 5 5 5 5 Admin 12 12 12 12 my question is, how to prevent this to happen? i've tried everything with While.... if else.. but the result is still the same. how to display output "0" if no rows to return? echo "0"; this is my QUERY: select DD.DPT_ID,DPT.DEPARTMENT_NAME,TU.EMP_GROUP, sum(DD.WORK_HOUR) AS WORK_HOUR, sum(DD.OT_HOUR) AS OT_HOUR FROM DEPARTMENT_DETAIL DD left join DEPARTMENT DPT ON (DD.DEPT_ID=DPT.DEPT_ID) LEFT JOIN TBL_USERS TU ON (TU.EMP_ID=DD.EMP_ID) WHERE DD_DATE>='2012-01-01' AND DD_DATE<='2012-01-31' AND TU.EMP_GROUP!=2 GROUP BY DD.DEPT_ID, DPT.DEPARTMENT_NAME,TU.EMP_GROUP ORDER BY DPT.DEPARTMENT_NAME this is one of the logic that i've used, but doesn't return the result that i want:: while($row = mssql_fetch_array($displayResult)) { if ((!$row["WORK_HOUR"])&&(!$row["OT_HOUR"])) { echo "<td >"; echo "empty"; echo "&nbsp;</td>"; echo "<td >"; echo "empty"; echo "&nbsp;</td>"; } else { echo "<td>"; echo $row["WORK_HOUR"]; echo "&nbsp;</td>"; echo "<td>"; echo $row["OT_HOUR"]; echo "&nbsp;</td>"; } } please help. i've been doing this for 2 days. @__@

    Read the article

  • strip () and get value

    - by mandnd
    I have a html list that looks like this: animals (45) houses (36) computers (96) I want to get all the values inside those () and make like $sum = 45+36+96; How can I do that? Thanks

    Read the article

  • No warning from gcc when function definition in linked source different from function prototype in h

    - by c_c
    Hi, I had a problem with a part of my code, which after some iterations seemed to read NaN as value of a int of a struct. I think I found the error, but am still wondering why gcc (version 3.2.3 on a embedded Linux with busybox) did not warn me. Here are the important parts of the code: A c file and its header for functions to acquire data over USB: // usb_control.h typedef struct{ double mean; short *values; } DATA_POINTS; typedef struct{ int size; DATA_POINTS *channel1; //....7 more channels } DATA_STRUCT; DATA_STRUCT *create_data_struct(int N); // N values per channel int free_data_struct(DATA_STRUCT *data); int aqcu_data(DATA_STRUCT *data, int N); A c and header file with helper function (math, bitshift,etc...): // helper.h int mean(DATA_STRUCT *data); // helper.c (this is where the error is obviously) double mean(DATA_STRUCT *data) { // sum in for loop data->channel1->mean = sum/data->N; // ...7 more channels // a printf here displayed the mean values corretly } The main file // main.c #include "helper.h" #include "usb_control.h" // Allocate space for data struct DATA_STRUCT *data = create_data_struct(N); // get data for different delays for (delay = 0; delay < 500; delay += pw){ acqu_data(data, N); mean(data); // printf of the mean values first is correct. Than after 5 iterations // it is always NaN for channel1. The other channels are displayed correctly; } There were no segfaults nor any other missbehavior, just the NaN for channel1 in the main file. After finding the error, which was not easy, it was of course east to fix. The return type of mean(){} was wrong in the definition. Instead of double mean() it has to be int mean() as the prototype defines. When all the functions are put into one file, gcc warns me that there is a redefinition of the function mean(). But as I compile each c file seperately and link them afterwards gcc seems to miss that. So my questions would be. Why didn't I get any warnings, even non with gcc -Wall? Or is there still another error hidden which is just not causing problems now? Regards, christian

    Read the article

  • HOW TO RETURN VALUE FROM FUNCTION? (c#)

    - by Ole Jak
    So... I want to return value when C# function is called. I need a code example (simple summ of a,b values will be ok) Please help I need something like this ( I know ActionScript so I will write in it): public function sum(valueA:int, valueB:int):int { var summ:int = valueA + valueB; return summ; } How to translate it into C#?

    Read the article

  • summing two colums total in mysql

    - by JPro
    I want a resultset for this table : ID Number_of_posts Number_of_user 1 100 21 2 23 34 as ID Number_of_posts Number_of_user Number_of_posts_AND_Number_of_user 1 100 21 178 2 23 34 178 ----------------------------------------------- 123 55 Is it possible to get the sum of two colums as another column/ as output in mysql?

    Read the article

< Previous Page | 60 61 62 63 64 65 66 67 68 69 70 71  | Next Page >