12,296,307 members (63,488 online)

Algorithms

 Re: Factorials Ian Uy25-Jun-08 6:32 Ian Uy 25-Jun-08 6:32
 Re: Factorials Tim Craig25-Jun-08 8:55 Tim Craig 25-Jun-08 8:55
 Re: Factorials Luc Pattyn25-Jun-08 11:01 Luc Pattyn 25-Jun-08 11:01
 Re: Factorials Tim Craig25-Jun-08 21:06 Tim Craig 25-Jun-08 21:06
 Re: Factorials cp987624-Jun-08 12:33 cp9876 24-Jun-08 12:33
 Re: Factorials Matthew Butler24-Jun-08 12:38 Matthew Butler 24-Jun-08 12:38
 Re: Factorials cp987624-Jun-08 14:05 cp9876 24-Jun-08 14:05
 Re: Factorials Luc Pattyn24-Jun-08 15:02 Luc Pattyn 24-Jun-08 15:02
 Hi Peter, IMO this will behave much better; it gives 4 for 10000000, does not overflow, has no loops but uses a recursion (scaling down by a factor of 5). ```private int rightmostNonzeroInFactorial(int n) { int result = 1; // factor ending on 1 // no change // factor ending on 2 int count2 = (n+8) / 10; // factor ending on 3 int count3 = (n + 7) / 10; // factor ending on 4 int count4 = (n + 6) / 10; // factor ending on 5 int count5 = (n + 5) / 10; // factor ending on 6 int count6 = (n + 4) / 10; // factor ending on 7 int count7 = (n + 3) / 10; // factor ending on 8 int count8 = (n + 2) / 10; // factor ending on 9 int count9 = (n + 1) / 10; // factor ending on 0 int count10 = (n + 0) / 10; count5 += count10; if (count5 != 0) { result = (result * rightmostNonzeroInFactorial(count5)) % 10; count2 -= count5; } count2 += 2 * count4; // 4 = 2*2 count2 += 3 * count8; // 8 = 2*2*2 count2 += 4 * count6; // 16 = 2*2*2*2 count3 += 2 * count9; // 9 = 3*3; count3 += 3 * count7; // 27 = 3*3*3 int[] fact3 = new int[] { 1, 3, 9, 7 }; // 3^5 ends on 3 result = (result * fact3[count3 % fact3.Length]) % 10;   int[] fact2 = new int[] { 1, 2, 4, 8 }; // 2^5 ends on 2 int factor2=fact2[count2 % fact2.Length]; if (factor2 == 1 && count2 != 0) factor2 = 6; // 2^4 = 16 result = (result * factor2) % 10;   return result; } ``` Main principle is factors that are not multiples of 5 don't care about their digits except the lowest one (and also: there will be more powers of 2 than powers of 5). Luc Pattyn [Forum Guidelines] [My Articles] Voting for dummies? No thanks.
 Re: Factorials cp987624-Jun-08 20:09 cp9876 24-Jun-08 20:09
 Re: Factorials Luc Pattyn24-Jun-08 23:53 Luc Pattyn 24-Jun-08 23:53
 Re: Factorials cp987625-Jun-08 2:27 cp9876 25-Jun-08 2:27
 Re: Factorials Luc Pattyn25-Jun-08 2:34 Luc Pattyn 25-Jun-08 2:34
 Re: Factorials cp987625-Jun-08 2:40 cp9876 25-Jun-08 2:40
 Re: Factorials tim_one14-Jul-08 8:37 tim_one 14-Jul-08 8:37
 Re: Factorials Arash Partow25-Jun-08 2:14 Arash Partow 25-Jun-08 2:14
 Re: Factorials Ian Uy25-Jun-08 6:26 Ian Uy 25-Jun-08 6:26
 How to determine the next x,y coordinate for a tank in a 2-D game... Edmundisme18-Jun-08 8:35 Edmundisme 18-Jun-08 8:35
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... 73Zeppelin18-Jun-08 11:38 73Zeppelin 18-Jun-08 11:38
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... Matthew Butler18-Jun-08 11:44 Matthew Butler 18-Jun-08 11:44
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... 73Zeppelin18-Jun-08 22:00 73Zeppelin 18-Jun-08 22:00
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... Edmundisme18-Jun-08 12:00 Edmundisme 18-Jun-08 12:00
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... Matthew Butler18-Jun-08 11:41 Matthew Butler 18-Jun-08 11:41
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... Edmundisme18-Jun-08 12:01 Edmundisme 18-Jun-08 12:01
 Re: How to determine the next x,y coordinate for a tank in a 2-D game... CPallini18-Jun-08 21:19 CPallini 18-Jun-08 21:19
 Polyline offset algorithm beko16-Jun-08 21:59 beko 16-Jun-08 21:59
 Last Visit: 31-Dec-99 18:00     Last Update: 26-May-16 16:54 Refresh « Prev1...153154155156157158159160161162 Next »