Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Finding extra digit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53999] Re: [mg53955] Finding extra digit
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sun, 6 Feb 2005 00:45:24 -0500 (EST)
  • References: <200502050815.DAA22191@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

This returns the location (counting from the right) of the first digit that doesn't agree.

Clear@firstDifference
firstDifference[a_Integer, b_Integer] /; a == b = {};
firstDifference[a_Integer, b_Integer] := Module[{
     aList = Reverse@IntegerDigits@a, bList = Reverse@IntegerDigits@b, len},
     len = Max[Length@aList, Length@bList];
     {aList, bList} = PadRight[#, len] & /@ {aList, bList};
     First@Position[Equal @@@ Transpose@{aList, bList}, False, 1, 1]
     ]
firstDifference[123456789, 123456789]
firstDifference[123456789, 123455789]
firstDifference[123456789, 12345578]
firstDifference[43456789, 123455789]

{}
{4}
{1}
{4}

Bobby

On Sat, 5 Feb 2005 03:15:16 -0500 (EST), Zak Seidov <seidovzf at yahoo.com> wrote:

> Dear Math gurus,
> please help!
> What is an easy way to find extra digit in the integer n2,
> which differs from integer n1
> EXACTLY by ONE digit.
> I use a very dirt program,
> but guess that you can suggest smth (much) better.
> Thanks a lot,
> and please mail me your help
> seidovzf at yahoo.com
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Mathematica
  • Next by Date: Re: Re: Product {for p=2 to infinity} (p^2+1)/(p^2-1)
  • Previous by thread: Re: Finding extra digit
  • Next by thread: Re: Finding extra digit