.net - Selecting combination using linq -


This is an interview question that I have recently encountered.

Description:

This work is $ 100 (please consider some currency) I will be given. I need to buy three items item A, item B, item C. (I'm not sure whether $ 0.25 or $ 0.75 is meaningful, think it as the other currency) Item A = 0.25 $, item B = 0.75 $ and item C = 20 $ me 100 items Actually $ 100 < / B> (I can buy a number of items, Item B, Item C but total should be 100).

Solution: I have solved this by using for loop.

 for  (int i = 1; i  

I got the result too

  item1 = 1, item2 = 93, item3 = 6 // cost = 100, items = 100 items 1 = 18, item 2 = 74, item 3 = 8 // Cost = 100, Item = 100 items 1 = 35, Item 2 = 55, Object 3 = 10 // value = 100, Item = 100 Object 1 = 52, Object 2 = 36, Object 3 = 12 // value = 100, Item = 100 items 1 = 69, item 2 = 17, item 3 = 14 // cost = 100, item = 100  

The actual task was to give a demo using "linq". How do I solve it using Linq?

(Anyhow the interview was over. Nobody would have asked in the next interview).

  var r = from enumerable.Range (1, 100) in enumerable in j. N KK in Range (1, 100) Range (1, 20) where (i * 0.25) + (j * 0.75) + (k * 5) == 100 & amp; Amp; (I + j + k) == 100 Select the string. Format ("item 1 = {0}, item 2 = {1}, item 3 = {2}", i, j, k); Foreach (Win Line) console in R Line line (line);  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -