Trying to generate all possible draws(combinations) for a lottery of unique 6 out of 42.
Actually looking for the most efficient way to do this (so that the actual generation does not take days).
Aside from the processing HOG (which is to be expected) .. i'm running into a memory limitation issue .. where my machine of 12GB ram cant hold 10% of the amount on number, let alone all combos.
So i decided to look into a Database alternative.
But with that i have the problem of duplicates (since i do not have the whole list in memory to check for existence).
I tried a lot of code versions but all are resource consuming.
Currently looking for alternatives that actually work :)
Here's my latest code sample that employs a database for later record processing and filtering and duplication removal:
public List<Draw> getDrawsContaining(List<int> initialBalls)
{
if (initialBalls == null)
initialBalls = new List<int>();
if (initialBalls.Count >= 6)
return new List<Draw> { new Draw(initialBalls) };
List<Draw> toReturn = new List<Draw>();
for (int i = 1; i <= 42; i++)
{
if (initialBalls.IndexOf(i) != -1)
continue;
initialBalls.Add(i);
toReturn.AddRange(getDrawsContaining(initialBalls));
initialBalls.Remove(i);
}
return toReturn;//.Distinct(dc).ToList();
}
AND say in the Page_Load i fire this :
try
{
using (SqlConnection connection = new SqlConnection(sqlConnectionString))
{
connection.Open();
String query = "TRUNCATE TABLE Draws";
SqlCommand command = new SqlCommand(query, connection);
//command.Parameters.Add("#id", "abc");
command.ExecuteNonQuery();
connection.Close();
}
DataTable dt = new DataTable("Draws");
dt.Columns.Add("Ball1");
dt.Columns.Add("Ball2");
dt.Columns.Add("Ball3");
dt.Columns.Add("Ball4");
dt.Columns.Add("Ball5");
dt.Columns.Add("Ball6");
for (int j = 1, k = 1; j <= 42 && k <= 42; )
{
List<Draw> drawsPart = getDrawsContaining(new List<int> { j, k });
if (drawsPart.Count > 0)
{
foreach (Draw d in drawsPart)
{
d.Balls.OrderBy(c => c);
DataRow dr = dt.NewRow();
dr["Ball1"] = d.Balls[0];
dr["Ball2"] = d.Balls[1];
dr["Ball3"] = d.Balls[2];
dr["Ball4"] = d.Balls[3];
dr["Ball5"] = d.Balls[4];
dr["Ball6"] = d.Balls[5];
dt.Rows.Add(dr);
}
DataTable tmp = dt.Copy();
dt.Rows.Clear();
AsyncDBSave AsyncDBSaveInstance = new AsyncDBSave(tmp, AsyncDBSaveDispose);
Thread t = new Thread(new ThreadStart(AsyncDBSaveInstance.commit));
t.Start();
}
k++;
if (k == 43) { j++; k = 1; }
}
}
catch (Exception ex)
{
var v = ex.Message;
throw;
}
Here we go... all very fast and efficient:
using System;
using System.Diagnostics;
static class Program
{
static void Main(string[] args)
{
byte[] results = new byte[6 * 5245786];
byte[] current = new byte[6];
int offset = 0;
var watch = Stopwatch.StartNew();
Populate(results, ref offset, current, 0);
watch.Stop();
Console.WriteLine("Time to generate: {0}ms", watch.ElapsedMilliseconds);
Console.WriteLine("Data size: {0}MiB",
(results.Length * sizeof(byte)) / (1024 * 1024));
Console.WriteLine("All generated; press any key to show them");
Console.ReadKey();
for (int i = 0; i < 5245786; i++)
{
Console.WriteLine(Format(results, i));
}
}
static string Format(byte[] results, int index)
{
int offset = 6 * index;
return results[offset++] + "," + results[offset++] + "," +
results[offset++] + "," + results[offset++] + "," +
results[offset++] + "," + results[offset++];
}
static void Populate(byte[] results, ref int offset, byte[] current, int level)
{
// pick a new candidate; note since we're doing C not P, assume ascending order
int last = level == 0 ? 0 : current[level - 1];
for (byte i = (byte)(last + 1); i <= 42; i++)
{
current[level] = i;
if (level == 5)
{
// write the results
results[offset++] = current[0];
results[offset++] = current[1];
results[offset++] = current[2];
results[offset++] = current[3];
results[offset++] = current[4];
results[offset++] = current[5];
}
else
{
// dive down
Populate(results, ref offset, current, level + 1);
}
}
}
}
Just for fun, non recursive version is about 2-3 times faster
static byte[] Populate2()
{
byte[] results = new byte[6 * 5245786];
int offset = 0;
for (byte a1 = 1; a1 <= 37; ++a1)
for (byte a2 = a1; ++a2 <= 38;)
for (byte a3 = a2; ++a3 <= 39;)
for (byte a4 = a3; ++a4 <= 40;)
for (byte a5 = a4; ++a5 <= 41;)
for (byte a6 = a5; ++a6 <= 42;)
{
results[offset] = a1;
results[offset+1] = a2;
results[offset+2] = a3;
results[offset+3] = a4;
results[offset+4] = a5;
results[offset+5] = a6;
offset += 6;
}
return results;
}
Related
It take pretty long time to complete the limit(n) of 100,000.
I suspect that the problem is with the CalculateAmicable() where the number get bigger and it take more time to calculate. What can I change to make it speed up faster than this?
public static void Main (string[] args)
{
CheckAmicable (1, 100000);
}
public static int CheckAmicable(int start, int end)
{
for (int i = start; i < end; i++) {
int main = CalculateAmicable (i); //220
int temp = CalculateAmicable (main); //284
int compare = CalculateAmicable (temp); //220
if (compare == main) {
if (main != temp && temp == i) {
Console.WriteLine (main + " = " + temp + " = " + compare + " i: " + i);
i = compare + 1;
}
}
}
return 0;
}
public static int CalculateAmicable(int number)
{
int total = 0;
for (int i = 1; i < number; i++) {
if (number%i == 0){
total += i;
}
}
return total;
}
Note: English is not my first language!
Yes, CalculateAmicable is inefficient - O(N) complexity - and so you have fo N tests 1e5 * 1e5 == 1e10 - ten billions operations which is slow.
The scheme which reduces complexity to O(log(N)) is
int n = 100000;
//TODO: implement IList<int> GetPrimesUpTo(int) yourself
var primes = GetPrimesUpTo((int)(Math.Sqrt(n + 1) + 1));
// Key - number itself, Value - divisors' sum
var direct = Enumerable
.Range(1, n)
.AsParallel()
.ToDictionary(index => index,
index => GetDivisorsSum(index, primes) - index);
var result = Enumerable
.Range(1, n)
.Where(x => x < direct[x] &&
direct.ContainsKey((int) direct[x]) &&
direct[(int) direct[x]] == x)
.Select(x => $"{x,5}, {direct[x],5}");
Console.Write(string.Join(Environment.NewLine, result));
The outcome is within a second (Core i7 3.2Ghz .Net 4.6 IA-64):
220, 284
1184, 1210
2620, 2924
5020, 5564
6232, 6368
10744, 10856
12285, 14595
17296, 18416
63020, 76084
66928, 66992
67095, 71145
69615, 87633
79750, 88730
Details GetDivisorsSum:
private static long GetDivisorsSum(long value, IList<int> primes) {
HashSet<long> hs = new HashSet<long>();
IList<long> divisors = GetPrimeDivisors(value, primes);
ulong n = (ulong) 1;
n = n << divisors.Count;
long result = 1;
for (ulong i = 1; i < n; ++i) {
ulong v = i;
long p = 1;
for (int j = 0; j < divisors.Count; ++j) {
if ((v % 2) != 0)
p *= divisors[j];
v = v / 2;
}
if (hs.Contains(p))
continue;
result += p;
hs.Add(p);
}
return result;
}
And GetPrimeDivisors:
private static IList<long> GetPrimeDivisors(long value, IList<int> primes) {
List<long> results = new List<long>();
int v = 0;
long threshould = (long) (Math.Sqrt(value) + 1);
for (int i = 0; i < primes.Count; ++i) {
v = primes[i];
if (v > threshould)
break;
if ((value % v) != 0)
continue;
while ((value % v) == 0) {
value = value / v;
results.Add(v);
}
threshould = (long) (Math.Sqrt(value) + 1);
}
if (value > 1)
results.Add(value);
return results;
}
I'm a hobby programmer.
I tried to ask this question earlier on a very unstructured way (Sorry again), now I try to ask on the proper way.
I wrote the following code that seems to work unreliably.
The code was written like this for several reasons. I know it's messy but it should still work. To explain why I wrote it like this would mean that I need to explain several weeks' of work that is quite extensive. Please accept that this is at least the least worse option I could figure out. In the below sample I removed all sections of the code that are not needed to reproduce the error.
What this program does in a nutshell:
The purpose is to check a large number of parameter combinations for a program that receives streaming data. I simulate the original process to test parameter combinations.
First data is read from files that represents recorded streaming data.
Then the data is aggregated.
Then I build a list of parameters to test for.
Finally I run the code for each parameter combination in parallel.
Inside the parallel part I calculate a financial indicator called the bollinger bands. This is a moving average with adding +/- standard deviation. This means the upper line and the lower line should only be equal when variable bBandDelta = 0. However sometimes it happens that CandleList[slot, w][ctr].bollingerUp is equal to CandleList[slot, w][ctr].bollingerDown even when bBandDelta is not 0.
As a result I don't understand how can line 277 kick in. It seems that sometimes the program fails to write to the CandleList[slot, w][ctr]. However this should not be possible because (1) I lock the list and (2) I use ConcurrentBag. Could I have some help please?
Source files are here.
The code is:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;
namespace Justfortest
{
class tick : IComparable<tick> //Data element to represent a tick
{
public string disp_name; //ticker ID
public DateTime? trd_date; //trade date
public TimeSpan? trdtim_1; //trade time
public decimal trdprc_1; //price
public int? trdvol_1; //tick volume
public int CompareTo(tick other)
{
if (this.trdprc_1 == other.trdprc_1)
{
return other.trdprc_1.CompareTo(this.trdprc_1); //Return the later item
}
return this.trdprc_1.CompareTo(other.trdprc_1); //Return the earlier item
}
}
class candle : IComparable<candle> //Data element to represent a candle and all chart data calculated on candle level
{
public int id = 0;
public DateTime? openDate;
public TimeSpan? openTime;
public DateTime? closeDate;
public TimeSpan? closeTime;
public decimal open = 0;
public decimal high = 0;
public decimal low = 0;
public decimal close = 0;
public int? volume = 0;
public decimal totalPrice = 0;
public decimal bollingerUp = 0; //Bollinger upper line
public decimal bollingerDown = 0; //Bollinger below line
public int CompareTo(candle other)
{
if (totalPrice == other.totalPrice)
{
return other.totalPrice.CompareTo(totalPrice); //Return the later item
}
return totalPrice.CompareTo(other.totalPrice); //Return the earlier item
}
}
class param : IComparable<param> //Data element represent a trade event signal
{
public int par1;
public int bollPar;
public int par2;
public int par3;
public int par4;
public int par5;
public int par6;
public decimal par7;
public decimal par8;
public decimal par9;
public decimal par10;
int IComparable<param>.CompareTo(param other)
{
throw new NotImplementedException();
}
}
class programCLass
{
void myProgram()
{
Console.WriteLine("Hello");
Console.WindowWidth = 180;
string[] sources = new string[]
{
#"C:\test\source\sourceW1.csv",
#"C:\test\source\sourceW2.csv",
};
List<candle>[] sourceCandleList = new List<candle>[sources.Count()];
List<param> paramList = new List<param>(10000000);
var csvAnalyzer = new StringBuilder();
{
List<tick>[] updatelist = new List<tick>[sources.Count()];
Console.WriteLine("START LOAD");
for (var i = 0; i < sources.Count(); i++)
{
var file = sources[i];
updatelist[i] = new List<tick>();
// ---------- Read CSV file ----------
var reader = new StreamReader(File.OpenRead(file));
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
tick update = new tick();
update.disp_name = values[0].ToString();
update.trd_date = Convert.ToDateTime(values[1]);
update.trdtim_1 = TimeSpan.Parse(values[2]);
update.trdprc_1 = Convert.ToDecimal(values[3]);
update.trdvol_1 = Convert.ToInt32(values[4]);
updatelist[i].Add(update);
}
Console.WriteLine(i);
}
Console.WriteLine("END LOAD"); // All files are in the memory
// Aggreagate
Console.WriteLine("AGGREGATE START");
int tickAggr = 500;
for (var w = 0; w < sources.Count(); w++)
{
sourceCandleList[w] = new List<candle>();
List<tick> FuturesList = new List<tick>();
foreach (var update in updatelist[w])
{
tick t = new tick();
t.disp_name = update.disp_name.ToString();
t.trd_date = update.trd_date;
t.trdtim_1 = update.trdtim_1;
t.trdprc_1 = Convert.ToDecimal(update.trdprc_1);
t.trdvol_1 = update.trdvol_1;
// Add new tick to the list
FuturesList.Add(t);
if (FuturesList.Count == Math.Truncate(FuturesList.Count / (decimal)tickAggr) * tickAggr)
{
candle c = new candle();
c.openDate = FuturesList[FuturesList.Count - tickAggr].trd_date;
c.openTime = FuturesList[FuturesList.Count - tickAggr].trdtim_1;
c.closeDate = FuturesList.Last().trd_date;
c.closeTime = FuturesList.Last().trdtim_1;
c.open = FuturesList[FuturesList.Count - tickAggr].trdprc_1;
c.high = FuturesList.GetRange(FuturesList.Count - tickAggr, tickAggr).Max().trdprc_1;
c.low = FuturesList.GetRange(FuturesList.Count - tickAggr, tickAggr).Min().trdprc_1;
c.close = FuturesList.Last().trdprc_1;
c.volume = FuturesList.GetRange(FuturesList.Count - tickAggr, tickAggr).Sum(tick => tick.trdvol_1);
c.totalPrice = (c.open + c.high + c.low + c.close) / 4;
sourceCandleList[w].Add(c);
if (sourceCandleList[w].Count == 1)
{
c.id = 0;
}
else
{
c.id = sourceCandleList[w][sourceCandleList[w].Count - 2].id + 1;
}
}
}
FuturesList.Clear();
}
Console.WriteLine("AGGREGATE END");
for (var i = 0; i < sources.Count(); i++)
{
updatelist[i].Clear();
}
}
Console.WriteLine("BUILD PARAMLIST");
for (int par1 = 8; par1 <= 20; par1 += 4) // parameter deployed
{
for (int bollPar = 10; bollPar <= 25; bollPar += 5) // parameter deployed
{
for (int par2 = 6; par2 <= 18; par2 += 4) // parameter deployed
{
for (int par3 = 14; par3 <= 20; par3 += 3) // parameter deployed
{
for (int par4 = 10; par4 <= 20; par4 += 5) // parameter deployed
{
for (int par5 = 4; par5 <= 10; par5 += 2) // parameter deployed
{
for (int par6 = 5; par6 <= 30; par6 += 5)
{
for (decimal par7 = 1.0005M; par7 <= 1.002M; par7 += 0.0005M)
{
for (decimal par8 = 1.002M; par8 <= 1.0048M; par8 += 0.0007M)
{
for (decimal par9 = 0.2M; par9 <= 0.5M; par9 += 0.1M)
{
for (decimal par10 = 0.5M; par10 <= 2; par10 += 0.5M)
{
param p = new param();
p.par1 = par1;
p.bollPar = bollPar;
p.par2 = par2;
p.par3 = par3;
p.par4 = par4;
p.par5 = par5;
p.par6 = par6;
p.par7 = par7;
p.par8 = par8;
p.par9 = par9;
p.par10 = par10;
paramList.Add(p);
}
}
}
}
}
}
}
}
}
}
}
Console.WriteLine("END BUILD PARAMLIST, scenarios to test:{0}", paramList.Count);
var sourceCount = sources.Count();
sources = null;
Console.WriteLine("Start building pools");
int maxThreads = 64;
ConcurrentBag<int> pool = new ConcurrentBag<int>();
List<candle>[,] CandleList = new List<candle>[maxThreads, sourceCount];
for (int i = 0; i <= maxThreads - 1; i++)
{
pool.Add(i);
for (int w = 0; w <= sourceCount - 1; w++)
{
CandleList[i, w] = sourceCandleList[w].ConvertAll(p => p);
}
}
Console.WriteLine("End building pools");
int pItemsProcessed = 0;
Parallel.ForEach(paramList,
new ParallelOptions { MaxDegreeOfParallelism = maxThreads },
p =>
{
int slot = 1000;
while (!pool.TryTake(out slot));
var bollPar = p.bollPar;
decimal bollingerMiddle = 0;
double bBandDeltaX = 0;
for (var w = 0; w < sourceCount; w++)
{
lock (CandleList[slot, w])
{
for (var ctr = 0; ctr < CandleList[slot, w].Count; ctr++)
{
CandleList[slot, w][ctr].bollingerUp = 0; //Bollinger upper line
CandleList[slot, w][ctr].bollingerDown = 0; //Bollinger below line
//Bollinger Bands Calculation
if (ctr + 1 >= bollPar)
{
bollingerMiddle = 0;
bBandDeltaX = 0;
for (int i = 0; i <= bollPar - 1; i++)
{
bollingerMiddle = bollingerMiddle + CandleList[slot, w][ctr - i].totalPrice;
}
bollingerMiddle = bollingerMiddle / bollPar; //average
for (int i = 0; i <= bollPar - 1; i++)
{
bBandDeltaX = bBandDeltaX + (double)Math.Pow(System.Convert.ToDouble(CandleList[slot, w][ctr - i].totalPrice) - System.Convert.ToDouble(bollingerMiddle), 2);
}
bBandDeltaX = bBandDeltaX / bollPar;
decimal bBandDelta = (decimal)Math.Sqrt(System.Convert.ToDouble(bBandDeltaX));
CandleList[slot, w][ctr].bollingerUp = bollingerMiddle + 2 * bBandDelta;
CandleList[slot, w][ctr].bollingerDown = bollingerMiddle - 2 * bBandDelta;
if (CandleList[slot, w][ctr].bollingerUp == CandleList[slot, w][ctr].bollingerDown)
{
Console.WriteLine("?! Items processed=" + pItemsProcessed + " bollPar=" + bollPar + " ctr=" + ctr + " bollingerMiddle=" + bollingerMiddle + " bBandDeltaX=" + bBandDeltaX + " bBandDelta=" + bBandDelta + " bollingerUp=" + CandleList[slot, w][ctr].bollingerUp + " bollingerDown=" + CandleList[slot, w][ctr].bollingerDown);
}
}
// REMOVED Further calculations happen here
}
// REMOVED Some evaluations happen here
}
}
// REMOVED Some more evaluations happen here
Interlocked.Increment(ref pItemsProcessed);
pool.Add(slot);
});
}
static void Main(string[] args)
{
var P = new programCLass();
P.myProgram();
}
}
}
I have 2 dynamic textboxes which stores users input in the form of an array Int32[] iA1 = new Int32[3];
and also have a combo box, which has mathematical operator.
My question is how to get the following output when user fills the number of rows and column dynamically at run time and make an appropriate selection from the combo box.
Thanks in advanceenter image description here
string output = "";
Int32[] array = new Int32[3] { 25, 4, 1 };
int rows = array[0];
int cols = array[1];
int op = array[2];
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
int value = 0;
string opStr = "";
if (op == 1) // +
{
opStr = "+";
value = r + c;
}
else if (op == 2) // -
{
opStr = "-";
value = r - c;
}
else if (op == 3) // *
{
opStr = "*";
value = r * c;
}
// ...
output += string.Format("{0} {1} {2} = {3}\t", r, opStr, c, value);
}
output += System.Environment.NewLine;
}
System.Console.Write(output);
System.Diagnostics.Debug.Write(output);
textarea.Text = output;
Here is a small console app which does what you want:
class Program
{
static void Main(string[] args)
{
var firstNumber = 24;
var secondNumber = 4;
var op = "+";
var result = new List<List<string>>();
for (int i = 0; i <= firstNumber; i++)
{
var list = new List<string>();
for (int j = 0; j < secondNumber; j++)
{
list.Add(i.ToString());
list.Add(op);
list.Add(j.ToString());
list.Add("=");
list.Add((i + j).ToString());
}
result.Add(list);
}
foreach (var item in result)
{
Console.WriteLine(string.Join(" ", item));
}
Console.ReadLine();
}
}
You need to take the numbers and the operator from your textboxes.
Actually i have a button to display the first 100 even numbers using For
int a = 100;
int res = 0;
int i;
string npares = "";
for (i = 0; i <= a; i++)
{
if (i % 2 == 0)
{
res = res + i;
if (i < a)
npares += i + ",";
else
npares += i;
}
}
LBLstatus.MaximumSize = new Size(200, 0);
LBLstatus.Text = npares;
But i need to make the same with more two buttons using While and Do While , how i can make this ?
EDIT >>>>>>
Using while i got this way :
int a = 100;
int i = 0;
string npares = "";
int res = 0;
while (i <= a)
{
i++;
if
(i % 2 == 0)
{
res = res + i;
if (i < a)
npares += i + ",";
else
npares += i;
}
LBLstatus.Text = npares;
(This answer shows the relationship between constructs, but does not otherwise attempt to provide a solution.)
The construct
for (init;cond;post)
{
body;
}
can be generally rewritten as / considered equivalent to
init;
while (cond) {
body;
post;
}
On the other hand a do-while has no analogous simple for form, because it delays evaluation of cond until after the body has been executed once, but it can be written as
for (init;;post) {
body;
if (!cond) break;
}
Using Take
List<int> ints;
List<int> positiveInts = ints.Where(i => i % 2 == 0).Take(100).ToList();
Using Aggregate
List<int> ints;
string positiveInts = ints.Where(i => i % 2 == 0).Take(100).Select(i => i.ToString()).Aggregate((a,b) => b += String.IsNullOrEmpty(b) ? a : "," + a);
I was wondering if it is possible to make a sum from a user input int but the sum must be radom every time.
This is the code that I made :
public static string genSum(int askedNumber)
{
string outputStr = null;
bool switchOneTwo = false;
int neededSum = 0;
int intOne = 0;
int intTwo = 0;
while (askedNumber != neededSum)
{
if (switchOneTwo == true)
{
intOne += 1;
switchOneTwo = false;
}
else
{
intTwo += 1;
switchOneTwo = true;
}
neededSum = intOne + intTwo;
if (neededSum == askedNumber)
{
if (neededSum >= 4)
{
Random randomInt = new Random();
int tmpIntOne = intOne;
int tmpIntTwo = intTwo;
int method;
//For now only one method
method = randomInt.Next(1, 1);
if (method == 1)
{
tmpIntOne = tmpIntOne / 2;
tmpIntTwo = (tmpIntTwo * 2) - tmpIntOne;
}
intOne = tmpIntOne;
intTwo = tmpIntTwo;
}
outputStr = "(" + intOne.ToString() + "+" + intTwo.ToString() + ")";
return outputStr;
}
}
return outputStr;
}
so what I want is that if a user eneters a number for example 20 it will then make a sum :
User enters 20 and presses GO! :
Result :
10 + 10 = 20
12 + 8 = 20
5 + 15 = 20
1 + 19 = 20
3 + 17 = 20
User enters 500 and presses GO! :
Result :
9 + 491 = 500
263 + 237 = 500
300 + 200 = 500
250 + 250 = 500
109 + 391 = 500
Create a random number less than the input and the other one will be User-YourRandom
void Foo(int userNumber)
{
Random r = new Random();
int firstNumber = r.Next(userNumber - 1);
int secondNumber = userNumber - firstNumber;
}
You can extend this to support negatives also.
edit getting true randoms
as I4V points out, if you put this in a loop you might get same set of numbers, so instead of calling Random you can use this approach:
void Foo(int userNumber)
{
int userNumber = 500;
for (int i = 0; i < 10; i++ )
{
int firstNumber = Next(0, userNumber - 1);
int secondNumber = userNumber - firstNumber;
Console.WriteLine(firstNumber + "+" + secondNumber);
}
}
internal static int RandomExt(int min, int max)
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buffer = new byte[4];
rng.GetBytes(buffer);
int result = BitConverter.ToInt32(buffer, 0);
return new Random(result).Next(min, max);
}
foreach (var s in genSum(500).Take(5))
{
Console.WriteLine(s);
}
public static IEnumerable<string> genSum(int askedNumber)
{
Random r = new Random();
while (true)
{
var i = r.Next(0, askedNumber);
yield return i + "+" + (askedNumber - i);
}
}