Counting derangements

Lets call the derangement function
f for clarity. At f(n) ,
there are n hats and n people. Everyone can choose
from n1 hats. Person 1 takes hat
i from n1 choices.
Person i still has n1
hats to choose from and everyone else has
n2 has to choose from (they can't
choose their own hat or i ).
Now we need two cases for what person
i does. Think of this as
 Person
i takes hat 1
 Person
i doesn't take hat 1 and
we don't know what they'll take until later
In case 2, we know person i
doesn't take hat 1, but nothing more. Previously
we knew that person i had
n1 choices, now he has
n2 , just like everyone else. This
means we can calculate f(n1) for this case. In
case 1, person i is no longer
forbidden to take hat 1. In essence, we know that
person i and person 1
have swapped hats and no longer need to be
matched, thus f(n2).
Either of these cases is possible, so we have a
recurrence that multiplies the (n1) choices by
the possibility of either happenning, f(n) =
(n1)(f(n1) + f(n2))

Related to : Counting derangements

SQL Counting of Different Values 
SELECT FileName,
sum(case when ReasonCode = 'x' then 1 else 0 end) as x_count,
sum(case when ReasonCode = 'y' then 1 else 0 end) as y_count,
sum(case when ReasonCode = 'z' then 1 else 0 end) as z_count
from TBL1
group by FileName

Counting lines in Swift 
This is the solution to the problem I found so I will leave it here in
case someone else finds it useful.
var text = "Line 1
Line 2
Line 3"
for var range = text.startIndex...text.startIndex; range.endIndex <
text.endIndex;
range = range.endIndex..<range.endIndex {
range = text.lineRangeForRange(range)
}

Counting Syllables In String 
If I understand correctly what are you asking you want to transform
line like this 'The first line leads off' to list like this:
[
['DH', 'AH0'], # The
['F', 'ER1', 'S', 'T'], # first
['L', 'AY1', 'N'], # line
['L', 'IY1', 'D', 'Z'], # leads
['AO1', 'F'] # off
]
And count number of elements that contain number (5 in provided
example  AH0, ER1, AY1,

Counting / Printing Path  From (1,1) to (m, n) 
The reason for this is the way you implemented the CountPath function.
Inside of the if statement you check for the starting coordinates as
they were final, in the recursive call you decrement the coordinates
instead of incrementing them. This should work the way you'd expect:
int CountPath ( int row, int column, int maxRow, int maxColumn)
{
if ( row == maxRow  column == maxColumn )
re

Counting instances in Java 
I made a new code, you were thinking about 2 dogs, if there are 3 or
more dogs, then your code won't work, so arrays are the solution to
this problem.
Each dog has it's own b, d variables. Test it with more than 2 dogs
and see what happens. If any error occurs just post it and I'll check
it.
Your for loop wasn't the optimal since you were taking 0 as the
interval start instead of your x and y (s



