Why teach your kid times tables when you can teach them times tables and a little bit of coding ?

So I promised my daughter a big present if she could learn all of her times tables, up to 12 x 12. Sure, we have some flash cards, and there are endless apps on any software platform to practice math facts. But why do that when you can write your own? The side benefit, is that she and I can personalize it to whatever we want. Next up is division, but she is going to have to help me code up that functionality.







using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PracticeMultiplication
    class Program
        static void Main(string[] args)

            // Get the largest number to multiply by, up to 12
            // Choosing 2 will get 1 x 12 - 2 x 12, choosing 6 will get 1 x 12 up through 6 X 12

            Console.Write("What's the largest number you want to multiply (1-12) ? ");
            int max = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Just type 'done' or 'q' to quit");
            string studentAnswer = String.Empty;
            int score = 0; //total correct answers
            int correctAnswersInARow = 0; // correct answers in a row

            while (true)

                ShowCurrentScore(score, correctAnswersInARow);

                // Generate a new problem using random numbers based on the max value
                // num2 will always be between 1 and 12
                Random random = new Random();
                int num1 = random.Next(0, max);
                int num2 = random.Next(0, 12);
                Console.Write("{0} x {1} = ", num1, num2);
                studentAnswer = Console.ReadLine();

                // check to see if we should quit
                if (studentAnswer == "done" || studentAnswer == "q")
               // Convert to Int so we can multiply and see what the answer is
                int studentNumber = Convert.ToInt32(studentAnswer);
                int answer = (num1 * num2);

                if (answer == studentNumber)
                    // Score and Correct get bumped up if they get it right.

                    // If they get 5 rigth in a row, they get a bonus of 5 points
                   // Using Modulo 5 to test for divisible by 5
                    if (correctAnswersInARow > 1 && correctAnswersInARow % 5 == 0)
                        score += 5;
                        WriteMessage("Bonus 5 points for getting 5 right in a row!", ConsoleColor.DarkGreen, score);
                    WriteMessage("Great Job Madeline! ",ConsoleColor.Green,score);
                    WriteMessage("Oh bummer! Let's try another one",ConsoleColor.Red,score);
                    // reset to 0 since we got it wrong
                    correctAnswersInARow = 0;

        private static void ShowCurrentScore(int score, int rightInarow)
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Your score is {0}                        ", score);
            Console.WriteLine("You have got {0} correct answers in a row", rightInarow);

        private static void WriteMessage(string Message, ConsoleColor Color, int score)
            Console.ForegroundColor = Color;
            Console.WriteLine("Your score is {0}",score);


Active Directory Search that works - Ambiguous Name Resolution

I am not a big fan of having to specify filters using the syntax prescribed for Get-ADuser.  Ambiguous Name Resolution is an old API that allows you to query against multiple attributes at the same time. There is some more information on ANR here http://support.microsoft.com/kb/243299

By default, the following attributes are set for ANR:

  • GivenName
  • Surname
  • displayName
  • LegacyExchangeDN
  • msExchMailNickname
  • RDN
  • physicalDeliveryOfficeName
  • proxyAddress
  • sAMAccountName

It turns out you just need to pass in an LDAP Query. Once you get the list of results, you can pipe them into the Get-ADuser cmdlet to get the user objects as you would expect them. All we have to do is build an LDAP Filter and query against an attribute called ANR. This will return all objects that have an attribute from the list above that maches User. You can kind of think of it as a wildcard search on steroids.

Function Get-User {
BEGIN {import-module activedirectory}
   $filter = "(&(ObjectClass=User)(ANR=$User))" 
   Get-ADObject -LDAPFilter $filter  |

Hope this is helpful.