我正在尝试计算一系列数字的每个数字的数字乘积,例如:
21,22,23 ...... 98,99 ..
将会:
2,4,6 ... 72,81 ..
为了减少复杂性,我会考虑只有[ 连续编号中的数字的有限长度],如从001到999或从0001到9999.
但是,例如,当序列很大时1000000000,重复提取数字然后乘以每个数字将是低效的.
基本思路是跳过我们在计算过程中会遇到的连续零点,如:
using System.Collections.Generic;
using System.Linq;
using System;
// note the digit product is not given with the iteration
// we would need to provide a delegate for the calculation
public static partial class NumericExtensions {
public static void NumberIteration(
this int value, Action<int, int[]> delg, int radix=10) {
var digits=DigitIterator(value, radix).ToArray();
var last=digits.Length-1;
var …Run Code Online (Sandbox Code Playgroud)