3 replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
source | link
  • v1.1 - - 1 byte  - Thanks to Kevin'sKevin's comment.
  • v1.0 -  63 bytes - Initial solution.
  • v1.1 - - 1 byte  - Thanks to Kevin's comment.
  • v1.0 -  63 bytes - Initial solution.
  • v1.1 - - 1 byte  - Thanks to Kevin's comment.
  • v1.0 -  63 bytes - Initial solution.
2 added 184 characters in body
source | link

C#C#, 6363 62 bytes

i=>{int a=i.Length,b=a-1;while1,b=a;while(a--a>=0&&i[a]==i[b]>0&&i[a]==i[b]);return b-a;}
i => {
    int a = i.Length - 1,
        b = a - 1;a;

    while( a--a >=> 0 && i[ a ] == i[ b ] );

    return b - a;
}
i => {
    int a = i.Length - 1, // Store the length of the input
        b = a -; 1;          // Get the position of the last char

    // Cycle through the string from the right to the left
    //   while the current char is equal to the last char
    while( a--a >=> 0 && i[ a ] == i[ b ] );

    // Return the difference between the last position
    //   and the last occurrence of the same char
    return b - a;
}
using System;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, Int32> f = i => {
            int a = i.Length - 1, b = a - 1;a;
            while( a--a >=> 0 && i[ a ] == i[ b ] );
            return b - a;
         };

         List<String>
            testCases = new List<String>() {
               "14892093",
               "12344444",
               "112311",
               "888888",
               "135866667"
            };

         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput: {f( testCase )}\n" );
         }

         Console.ReadLine();
      }
   }
}
  • v1.1 - - 1 byte  - Thanks to Kevin's comment.
  • v1.0 -  63 bytes - Initial solution.

C#, 63 bytes

i=>{int a=i.Length,b=a-1;while(--a>=0&&i[a]==i[b]);return b-a;}
i => {
    int a = i.Length,
        b = a - 1;

    while( --a >= 0 && i[ a ] == i[ b ] );

    return b - a;
}
i => {
    int a = i.Length, // Store the length of the input
        b = a - 1;    // Get the position of the last char

    // Cycle through the string from the right to the left
    //   while the current char is equal to the last char
    while( --a >= 0 && i[ a ] == i[ b ] );

    // Return the difference between the last position
    //   and the last occurrence of the same char
    return b - a;
}
using System;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, Int32> f = i => {
            int a = i.Length, b = a - 1;
            while( --a >= 0 && i[ a ] == i[ b ] );
            return b - a;
         };

         List<String>
            testCases = new List<String>() {
               "14892093",
               "12344444",
               "112311",
               "888888",
               "135866667"
            };

         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput: {f( testCase )}\n" );
         }

         Console.ReadLine();
      }
   }
}
  • v1.0 -  63 bytes - Initial solution.

C#, 63 62 bytes

i=>{int a=i.Length-1,b=a;while(a-->0&&i[a]==i[b]);return b-a;}
i => {
    int a = i.Length - 1,
        b = a;

    while( a-- > 0 && i[ a ] == i[ b ] );

    return b - a;
}
i => {
    int a = i.Length - 1, // Store the length of the input
        b = a ;           // Get the position of the last char

    // Cycle through the string from the right to the left
    //   while the current char is equal to the last char
    while( a-- > 0 && i[ a ] == i[ b ] );

    // Return the difference between the last position
    //   and the last occurrence of the same char
    return b - a;
}
using System;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, Int32> f = i => {
            int a = i.Length - 1, b = a;
            while( a-- > 0 && i[ a ] == i[ b ] );
            return b - a;
         };

         List<String>
            testCases = new List<String>() {
               "14892093",
               "12344444",
               "112311",
               "888888",
               "135866667"
            };

         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput: {f( testCase )}\n" );
         }

         Console.ReadLine();
      }
   }
}
  • v1.1 - - 1 byte  - Thanks to Kevin's comment.
  • v1.0 -  63 bytes - Initial solution.
1
source | link

C#, 63 bytes


Golfed

i=>{int a=i.Length,b=a-1;while(--a>=0&&i[a]==i[b]);return b-a;}

Ungolfed

i => {
    int a = i.Length,
        b = a - 1;

    while( --a >= 0 && i[ a ] == i[ b ] );

    return b - a;
}

Ungolfed readable

i => {
    int a = i.Length, // Store the length of the input
        b = a - 1;    // Get the position of the last char

    // Cycle through the string from the right to the left
    //   while the current char is equal to the last char
    while( --a >= 0 && i[ a ] == i[ b ] );

    // Return the difference between the last position
    //   and the last occurrence of the same char
    return b - a;
}

Full code

using System;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, Int32> f = i => {
            int a = i.Length, b = a - 1;
            while( --a >= 0 && i[ a ] == i[ b ] );
            return b - a;
         };

         List<String>
            testCases = new List<String>() {
               "14892093",
               "12344444",
               "112311",
               "888888",
               "135866667"
            };

         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput: {f( testCase )}\n" );
         }

         Console.ReadLine();
      }
   }
}

Releases

  • v1.0 -  63 bytes - Initial solution.

Notes

Nothing to add