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
- References:
- Finding extra digit
- From: seidovzf@yahoo.com (Zak Seidov)
- Finding extra digit