Subtracting from a recuring difference and storing it into an array c#

39 Views Asked by At

I have a riddle, practically it works this way.

You have a fixed originalValue which can not exceed 54; the plan is to get that value, subtract 6 and check if the diff or balance is greater than 12, if so subtract the difference by 12 until the reminder of that recurring difference is less than 12 then exit

  24 - 6 = 18;
  18 - 12 = 6;
  6  // the system exists why because 6 is less than 12
  // the goal is  store 6,12,6 in an array

This is my code:

int orignalValue = 24;
List<int> subtractabled = new List<int>();
int  diff = 0;
    
diff = orignalValue - 6;  // start sub with 6 and 12 for the recurring differences until the reminder is less than 12
subtractabled.Add(6);

while (diff < 12)
{
    if (diff > 12)
    {
        diff = diff - 12;
        subtractabled.Add(12);
    }

    if (diff < 12)
        subtractabled.Add(diff);  // get the reminder  
}

I have failed to loop through this and collect the subtractables. Maybe some hints on how I can solve this riddle? Thank you.

0

There are 0 best solutions below