Search This Blog

Tuesday, December 14, 2010

Euler Problem 16

http://projecteuler.net/index.php?section=problems&id=16

What is the sum of all the numbers in the answer from 2^1000?

This is tricky because it’s a big number!

C# .NET3.5 does this…1.0715086071862673E+301
…which means I don’t have all the digits to add up…

As an aside.. here’s what python does when you ask it for 2 to the power 1000…

>>> print pow(2,1000)
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376

No problem! Just need to add those up……

Anyway back to C#… how to cope? We need to make an array.. and handle it ourselves like this..:

static void Main(string[] args)
       {
           int[] c = new int[999];

           c[0] = 2; //starting condition

           for (int i = 1; i < 1000; i++)   //go to the power of 1000
           {
               //do mult in place
                for (int n=0;n<999;n++)
               {
                   c[n] *= 2;
               }
              
            
               //sort out carries across to right
               for (int n=0;n<999;n++)
               {
                 
                   if (c[n] >= 10)
                   {
                       c[n+1] += 1;
                       c[n] -= 10;
                   }
                   }

           }

           //now add up all the columns
           long sum = 0;

           for (int n = 0; n < 999; n++)
           {
              sum+= c[n];
           }


           Console.WriteLine(sum);

        
       Console.ReadLine();

       }

Project Euler–Problem 15

This was a tough one! So the problem is to find how many ways to get from one side of a 20x20 chessboard without backtracking.

As a simple example.. starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.

alt text

So the answer is to think about the problem rather differently… in fact the question is to use 20 Rights and 20 Downs to get across the chessboard… so how many combinations are there to arrange 20R and 20D?? So now it’s a combination problem which means we can use some stats..

The formula is n! / r! (n-r)!

Where n is 40 and r is 20…  so 40!/(20! * 20!)

Which gives us:    137846528820 ways to get there!

 

In fact Google’s online calculator can do this for you….

Just type 40 choose 20 into Google!!

Sunday, December 12, 2010

Euler problem 14

Easy as long as you remember to use LONG and not INT!

http://projecteuler.net/index.php?section=problems&id=14

The following iterative sequence is defined for the set of positive integers:

n → n/2 (n is even)
n → 3n + 1 (n is odd)

Using the rule above and starting with 13, we generate the following sequence:

13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1

It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.

Which starting number, under one million, produces the longest chain?

NOTE: Once the chain starts the terms are allowed to go above one million.

________________

static void Main(string[] args)
      {
          long maxl = 0;
          long maxn = 0;
          for (long s = 6; s < 1000000; s++)
          {
             long x = s;
              long l = 1;
              while (x > 1)
              {
                  l++;
                  if (x % 2 == 0)
                  {
                      x = x / 2;
                  }
                  else
                  {
                      x = 3 * x + 1;
                  }

              }
              if (l > maxl)
              {
                  maxn = s; //starting number
                  maxl = l;
              }
          }
      Console.WriteLine(maxl + ","+ maxn);
      Console.ReadLine();

      }

Euler–problem 13

http://projecteuler.net/index.php?section=problems&id=13

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.

37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
62176457141856560629502157223196586755079324193331
64906352462741904929101432445813822663347944758178
92575867718337217661963751590579239728245598838407
58203565325359399008402633568948830189458628227828
80181199384826282014278194139940567587151170094390
35398664372827112653829987240784473053190104293586
86515506006295864861532075273371959191420517255829
71693888707715466499115593487603532921714970056938
54370070576826684624621495650076471787294438377604
53282654108756828443191190634694037855217779295145
36123272525000296071075082563815656710885258350721
45876576172410976447339110607218265236877223636045
17423706905851860660448207621209813287860733969412
81142660418086830619328460811191061556940512689692
51934325451728388641918047049293215058642563049483
62467221648435076201727918039944693004732956340691
15732444386908125794514089057706229429197107928209
55037687525678773091862540744969844508330393682126
18336384825330154686196124348767681297534375946515
80386287592878490201521685554828717201219257766954
78182833757993103614740356856449095527097864797581
16726320100436897842553539920931837441497806860984
48403098129077791799088218795327364475675590848030
87086987551392711854517078544161852424320693150332
59959406895756536782107074926966537676326235447210
69793950679652694742597709739166693763042633987085
41052684708299085211399427365734116182760315001271
65378607361501080857009149939512557028198746004375
35829035317434717326932123578154982629742552737307
94953759765105305946966067683156574377167401875275
88902802571733229619176668713819931811048770190271
25267680276078003013678680992525463401061632866526
36270218540497705585629946580636237993140746255962
24074486908231174977792365466257246923322810917141
91430288197103288597806669760892938638285025333403
34413065578016127815921815005561868836468420090470
23053081172816430487623791969842487255036638784583
11487696932154902810424020138335124462181441773470
63783299490636259666498587618221225225512486764533
67720186971698544312419572409913959008952310058822
95548255300263520781532296796249481641953868218774
76085327132285723110424803456124867697064507995236
37774242535411291684276865538926205024910326572967
23701913275725675285653248258265463092207058596522
29798860272258331913126375147341994889534765745501
18495701454879288984856827726077713721403798879715
38298203783031473527721580348144513491373226651381
34829543829199918180278916522431027392251122869539
40957953066405232632538044100059654939159879593635
29746152185502371307642255121183693803580388584903
41698116222072977186158236678424689157993532961922
62467957194401269043877107275048102390895523597457
23189706772547915061505504953922979530901129967519
86188088225875314529584099251203829009407770775672
11306739708304724483816533873502340845647058077308
82959174767140363198008187129011875491310547126581
97623331044818386269515456334926366572897563400500
42846280183517070527831839425882145521227251250327
55121603546981200581762165212827652751691296897789
32238195734329339946437501907836945765883352399886
75506164965184775180738168837861091527357929701337
62177842752192623401942399639168044983993173312731
32924185707147349566916674687634660915035914677504
99518671430235219628894890102423325116913619626622
73267460800591547471830798392868535206946944540724
76841822524674417161514036427982273348055556214818
97142617910342598647204516893989422179826088076852
87783646182799346313767754307809363333018982642090
10848802521674670883215120185883543223812876952786
71329612474782464538636993009049310363619763878039
62184073572399794223406235393808339651327408011116
66627891981488087797941876876144230030984490851411
60661826293682836764744779239180335110989069790714
85786944089552990653640447425576083659976645795096
66024396409905389607120198219976047599490197230297
64913982680032973156037120041377903785566085089252
16730939319872750275468906903707539413042652315011
94809377245048795150954100921645863754710598436791
78639167021187492431995700641917969777599028300699
15368713711936614952811305876380278410754449733078
40789923115535562561142322423255033685442488917353
44889911501440648020369068063960672322193204149535
41503128880339536053299340368006977710650566631954
81234880673210146739058568557934581403627822703280
82616570773948327592232845941706525094512325230608
22918802058777319719839450180888072429661980811197
77158542502016545090413245809786882778948721859617
72107838435069186155435662884062257473692284509516
20849603980134001723930671666823555245252804609722
53503534226472524250874054075591789781264330331690

 

_______________

 

Another great one!

This time all the numbers are 100 digits long.. so don’t fit into an int, or even a long…

C# can handle is using BigInt when using .NET 4.. but trying to do it another way I thought about using doubles, and just adding a decimal point to each number… we only need to first ten digits from the sum… not pretty… but it works and only took 2 mins to code up using TextPad’s macros to do the formatting for me!!

 

______

static void Main(string[] args)
      {
         

     double a1 = 3710728753.3902102798797998220837590246510135740250;
     double a2 = 4637693767.7490009712648124896970078050417018260538;
     double a3 = 7432498619.9524741059474233309513058123726617309629;
     double a4 = 9194221336.3574161572522430563301811072406154908250;
     double a5 = 2306758820.7539346171171980310421047513778063246676;
     double a6 = 8926167069.6623633820136378418383684178734361726757;
     double a7 = 2811287981.2849979408065481931592621691275889832738;
     double a8 = 4427422891.7432520321923589422876796487670272189318;
     double a9 = 4745144573.6001306439091167216856844588711603153276;
     double a10 = 7038648610.5843025439939619828917593665686757934951;
     double a11 = 6217645714.1856560629502157223196586755079324193331;
     double a12 = 6490635246.2741904929101432445813822663347944758178;
     double a13 = 9257586771.8337217661963751590579239728245598838407;
     double a14 = 5820356532.5359399008402633568948830189458628227828;
     double a15 = 8018119938.4826282014278194139940567587151170094390;
     double a16 = 3539866437.2827112653829987240784473053190104293586;
     double a17 = 8651550600.6295864861532075273371959191420517255829;
     double a18 = 7169388870.7715466499115593487603532921714970056938;
     double a19 = 5437007057.6826684624621495650076471787294438377604;
     double a20 = 5328265410.8756828443191190634694037855217779295145;
     double a21 = 3612327252.5000296071075082563815656710885258350721;
     double a22 = 4587657617.2410976447339110607218265236877223636045;
     double a23 = 1742370690.5851860660448207621209813287860733969412;
     double a24 = 8114266041.8086830619328460811191061556940512689692;
     double a25 = 5193432545.1728388641918047049293215058642563049483;
     double a26 = 6246722164.8435076201727918039944693004732956340691;
     double a27 = 1573244438.6908125794514089057706229429197107928209;
     double a28 = 5503768752.5678773091862540744969844508330393682126;
     double a29 = 1833638482.5330154686196124348767681297534375946515;
     double a30 = 8038628759.2878490201521685554828717201219257766954;
     double a31 = 7818283375.7993103614740356856449095527097864797581;
     double a32 = 1672632010.0436897842553539920931837441497806860984;
     double a33 = 4840309812.9077791799088218795327364475675590848030;
     double a34 = 8708698755.1392711854517078544161852424320693150332;
     double a35 = 5995940689.5756536782107074926966537676326235447210;
     double a36 = 6979395067.9652694742597709739166693763042633987085;
     double a100 = 4105268470.8299085211399427365734116182760315001271;
     double a37 = 6537860736.1501080857009149939512557028198746004375;
     double a38 = 3582903531.7434717326932123578154982629742552737307;
     double a39 = 9495375976.5105305946966067683156574377167401875275;
     double a40 = 8890280257.1733229619176668713819931811048770190271;
     double a41 = 2526768027.6078003013678680992525463401061632866526;
     double a42 = 3627021854.0497705585629946580636237993140746255962;
     double a43 = 2407448690.8231174977792365466257246923322810917141;
     double a44 = 9143028819.7103288597806669760892938638285025333403;
     double a45 = 3441306557.8016127815921815005561868836468420090470;
     double a46 = 2305308117.2816430487623791969842487255036638784583;
     double a47 = 1148769693.2154902810424020138335124462181441773470;
     double a48 = 6378329949.0636259666498587618221225225512486764533;
     double a49 = 6772018697.1698544312419572409913959008952310058822;
     double a50 = 9554825530.0263520781532296796249481641953868218774;
     double a51 = 7608532713.2285723110424803456124867697064507995236;
     double a52 = 3777424253.5411291684276865538926205024910326572967;
     double a53 = 2370191327.5725675285653248258265463092207058596522;
     double a54 = 2979886027.2258331913126375147341994889534765745501;
     double a55 = 1849570145.4879288984856827726077713721403798879715;
     double a56 = 3829820378.3031473527721580348144513491373226651381;
     double a57 = 3482954382.9199918180278916522431027392251122869539;
     double a58 = 4095795306.6405232632538044100059654939159879593635;
     double a59 = 2974615218.5502371307642255121183693803580388584903;
     double a60 = 4169811622.2072977186158236678424689157993532961922;
     double a61 = 6246795719.4401269043877107275048102390895523597457;
     double a62 = 2318970677.2547915061505504953922979530901129967519;
     double a63 = 8618808822.5875314529584099251203829009407770775672;
     double a64 = 1130673970.8304724483816533873502340845647058077308;
     double a65 = 8295917476.7140363198008187129011875491310547126581;
     double a66 = 9762333104.4818386269515456334926366572897563400500;
     double a67 = 4284628018.3517070527831839425882145521227251250327;
     double a68 = 5512160354.6981200581762165212827652751691296897789;
     double a69 = 3223819573.4329339946437501907836945765883352399886;
     double a70 = 7550616496.5184775180738168837861091527357929701337;
     double a71 = 6217784275.2192623401942399639168044983993173312731;
     double a72 = 3292418570.7147349566916674687634660915035914677504;
     double a73 = 9951867143.0235219628894890102423325116913619626622;
     double a74 = 7326746080.0591547471830798392868535206946944540724;
     double a75 = 7684182252.4674417161514036427982273348055556214818;
     double a76 = 9714261791.0342598647204516893989422179826088076852;
     double a77 = 8778364618.2799346313767754307809363333018982642090;
     double a78 = 1084880252.1674670883215120185883543223812876952786;
     double a79 = 7132961247.4782464538636993009049310363619763878039;
     double a80 = 6218407357.2399794223406235393808339651327408011116;
     double a81 = 6662789198.1488087797941876876144230030984490851411;
     double a82 = 6066182629.3682836764744779239180335110989069790714;
     double a83 = 8578694408.9552990653640447425576083659976645795096;
     double a84 = 6602439640.9905389607120198219976047599490197230297;
     double a85 = 6491398268.0032973156037120041377903785566085089252;
     double a86 = 1673093931.9872750275468906903707539413042652315011;
     double a87 = 9480937724.5048795150954100921645863754710598436791;
     double a88 = 7863916702.1187492431995700641917969777599028300699;
     double a89 = 1536871371.1936614952811305876380278410754449733078;
     double a90 = 4078992311.5535562561142322423255033685442488917353;
     double a91 = 4488991150.1440648020369068063960672322193204149535;
     double a92 = 4150312888.0339536053299340368006977710650566631954;
     double a93 = 8123488067.3210146739058568557934581403627822703280;
     double a94 = 8261657077.3948327592232845941706525094512325230608;
     double a95 = 2291880205.8777319719839450180888072429661980811197;
     double a96 = 7715854250.2016545090413245809786882778948721859617;
     double a97 = 7210783843.5069186155435662884062257473692284509516;
     double a98 = 2084960398.0134001723930671666823555245252804609722;
     double a99 = 5350353422.6472524250874054075591789781264330331690;


     double sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10
          + a11 + a12 + a13 + a14
          + a15
     + a16 + a17       + a18 + a19        + a20 + a21       + a22 + a23
     + a24 + a25       + a26 + a27       + a28 + a29       + a30 + a31
     + a32 + a33       + a34 + a35       + a36 + a100       + a37 + a38
     + a39 + a40       + a41 + a42       + a43 + a44       + a45 + a46
     + a47 + a48       + a49 + a50       + a51 + a52       + a53 + a54
     + a55 + a56       + a57 + a58       + a59 + a60       + a61 + a62
     + a63 + a64       + a65 + a66       + a67 + a68       + a69 + a70
     + a71 + a72       + a73 + a74       + a75 + a76       + a77 + a78
     + a79 + a80       + a81 + a82       + a83 + a84       + a85 + a86
     + a87 + a88       + a89 + a90       + a91 + a92       + a93 + a94
     + a95 + a96       + a97 + a98       + a99;

     Console.WriteLine(sum);
     Console.ReadLine();

      }

Euler–Project Number 12

http://projecteuler.net/index.php?section=problems&id=12

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

1: 1
3: 1,3
6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

____________________________

Ok so this was a bit tricky… the dumb approach to just add up numbers and keep trying for factors takes WAY too long.. so you need to use the summation formula:

Sum of numbers up to n = n(n+1)/2

Then remember you only need to find half of the factors… so when factorising 12 you’d get:

1,2,3,4,6,12 – 1 and 12 are obvious so start with 2 factors…

then work your way up to sqrt(12) to get 2,3 as factors…
their counter parts will be 6,4 – but you don’t need to know them.. only that they exist.. so in other words just double up the number of factors found up to sqrt(12) = 4

So total number of factors for 12 is 2 + 4 = 6

________________

CODE:

static void Main(string[] args)
      {
          int t;
          int f = 0;

          for (int q = 2; q < 1000000000; q++)
          {
               //sum of all numbers up to t using summation formula
              t = q * (q + 1) / 2;
          //factors

              f = 2;  //1 and the number t to be added as factors
              for (int z = 2; z < (Math.Sqrt(t)+1); z++)
              {
                  if (t % z == 0) { f+=2; }

              }
         if (f >= 500)
          {
              Console.WriteLine(t +","+ f);
          }

          }

         Console.WriteLine(">>");

          Console.ReadLine();

      }

MTB Skills - phundamentals

great course today... at bottle lake...

Heals down, elbow out, find the the light hands balance point!

Map image

Euler 11

There's a cool website full of maths and programming challenges.. which I've started working through.. Dave told me about it.. and suggested documenting the solutions.. so here it goes.. I've done the previous 11 but not saved the code.. but from now on I'll document it here.

This is the solution to problem 11...

http://projecteuler.net/index.php?section=problems&id=11

 

In the 20x20 grid below, four numbers along a diagonal line have been marked in red.

08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

The product of these numbers is 26 × 63 × 78 × 14 = 1788696.

What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20×20 grid?

 

 

___________

 

static void Main(string[] args)
        {
            string[] a = new string[20];
           string[,] aa = new string[20,20];

a[0]="08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08";
a[1]="49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00";
a[2]="81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65";
a[3]="52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91";
a[4]="22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80";
a[5]="24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50";
a[6]="32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70";
a[7]="67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21";
a[8]="24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72";
a[9]="21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95";
a[10]="78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92";
a[11]="16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57";
a[12]="86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58";
a[13]="19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40";
a[14]="04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66";
a[15]="88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69";
a[16] ="04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36";
a[17]="20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16";
a[18]="20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54";
a[19]="01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48";

int max=0;
int r = 0;
//set up - split up
foreach (string c in a)
{
     for (int n=0;n<20;n++)
     {
        aa[r,n]=c.Split(' ')[n];
     }
     r++;
}
//horiz
for (int x=0;x<16;x++)
{
    for (int y = 0; y < 20; y++)
    {
        int tot = Convert.ToInt16(aa[x,y]) *Convert.ToInt16(aa[x + 1,y])*Convert.ToInt16( aa[x + 2,y]) *Convert.ToInt16( aa[x + 3,y]);
        if (tot>max) {max=tot;}

    }
}

//vert
for (int x = 0; x < 20; x++)
{
    for (int y = 0; y < 16; y++)
    {
        int tot = Convert.ToInt16(aa[x, y]) * Convert.ToInt16(aa[x, y + 1]) * Convert.ToInt16(aa[x, y + 2]) *Convert.ToInt16( aa[x, y + 3]);
        if (tot > max) { max = tot; }

    }
}

//diag tl - br
//vert
for (int x = 0; x < 16; x++)
{
    for (int y = 0; y < 16; y++)
    {
        int tot = Convert.ToInt16(aa[x, y]) * Convert.ToInt16(aa[x + 1, y + 1]) * Convert.ToInt16(aa[x + 2, y + 2]) * Convert.ToInt16(aa[x + 3, y + 3]);
        if (tot > max) { max = tot; }

    }
}          

//diag tl - br
//vert
for (int x = 0; x < 16; x++)
{
    for (int y = 0; y < 16; y++)
    {
        int tot = Convert.ToInt16(aa[x + 3, y]) * Convert.ToInt16(aa[x + 2, y + 1]) * Convert.ToInt16(aa[x + 1, y + 2]) * Convert.ToInt16(aa[x, y + 3]);
        if (tot > max) { max = tot; }

    }
}

Console.WriteLine(max);

         //   Console.WriteLine(max);

            Console.ReadLine();

        }