Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
extrefGenerate
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var currVal = DateTime.Now.Ticks; Console.WriteLine("Tick:"+currVal); Console.WriteLine("externalRef:"+GenerateT4TExternalReference(currVal)); } public static string GenerateT4TExternalReference(long extticks = 0) { var ticks = extticks != 0 ? extticks.ToString().Substring(5, 13) : DateTime.Now.Ticks.ToString().Substring(5, 13); Console.WriteLine("Short Tick:"+ticks); var mod10 = GetMod10Digit(ticks).ToString(); Console.WriteLine("LuhnChecksum:"+mod10); var strToBase = ticks + mod10; Console.WriteLine("Tick+check:"+strToBase); var longNumber = Convert.ToInt64(strToBase); return ConvertTo(longNumber); } private static int GetMod10Digit(string data) { int sumOfDigits = data.Where((e) => e >= '0' && e <= '9') .Reverse() .Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2)) .Sum((e) => e / 10 + e % 10); //// If the final sum is divisible by 10, then the credit card number is valid. If it is not divisible by 10, the number is invalid. return sumOfDigits % 10; } public static readonly string baseDef = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; public static string ConvertTo(long val) { string result = string.Empty; int targetBase = baseDef.Length; do { result = baseDef[Convert.ToInt32(val % targetBase)] + result; val = val / targetBase; } while (val > 0); return result; } }}
run
|
edit
|
history
|
help
0
Speed test for email text replacements
Numbers in Interval Dividable by Given Number
project euler 13, C#
if Two Words Are Anagrams of Each Other
Fibonacci Modified
Check if string is palindrome
Hello World!
Funzpoint
Оператор switch
Today's work