The shahbag movement is a long-overdue protest against the war criminals of Bangladesh who were associated with the killing of around 3 million Bangladeshis and raping/torturing around 200 thousands women and children . To demand capital punishment for the war criminals (e.g., Abdul Quader Molla) and to ban on Bangladesh’s largest Islamic party, tens of thousands talented youth have been protesting at SHAHBAGH for last 8 days. Our only demand is to seek justice against the war criminals for their atrocities committed during the liberation war of the country in 1971. While the wikipedia page details about this historic event, the following video summarizes our message.
“Injustice anywhere is a threat to justice everywhere”-Martin Luther King Jr.
This post is my humble tribute to the tens of thousands of people who are relentlessly protesting at SHAHBAGH. And, we will not stop until we get justice.
We, the youth of Bangladesh… all we seek JUSTICE, nothing more or nothing less…
Last but not the least, I would like to express my gratitude to all who are expressing solidarity with SHAHBAG from all over the world. Nation will never forget your contributions. Being a Bangladeshi, I have never been so proud. I am so overwhelmed that I am literally standing tall.
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025-385 = 2640.Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
where both a and b are three digit number. To do so, we first define a function that checks whether a number (e.g., p) is a palindrome.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then, we iterate over all the tuples (a,b) of three digit numbers e.g., [100..999] that satisfy the following equation.
Finally, we check if a*b is a palindrome and get the largest palindrome, as outlined below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Edit Distance—a.k.a “Lavenshtein Distance”–is the minimum number of edit operations required to transform one word into another. The allowable edit operations are letter insertion, letter deletion and letter substitution.
Implementation
Using Dynamic Programming, we can compute the edit distance between two string sequences. But for that, we need to derive a recursive definition of Edit Distance. We denote the distance between two strings as D, which can be defined using a recurrence as follows.
Case 1 : Both and are empty strings, denoted as :
Case 2 : Either or is :
Case 3 : Both and are not :
Here , where is the last character of and contains rest of the characters. Same goes for . We define edit distance between and using a recurrence and in term of and .
can be defined as the minimum, or the least expensive one of the following three alternatives stated in the above equation.
Substitution: If , then the overall distance is simply . Otherwise, we need a substitution operation that replaces with , and thus, the overall distance will be .
Insertion: Second possibility is to convert to by inserting in . In this case, the distance will be . Here, +1 is the cost of the insert operation.
Deletion: Last alternative is to convert to by deleting from that costs +1. Then the distance become .
As this is a ternary recurrence, it would result in an exponential run-time, which is quite impractical. However, using the dynamic programming with memoization, this recurrence can be solved using a 2D array. The code to solve this problem is outline below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As shown in line 14, the distance grid.[h,w] can be computed locally by taking the min of the three alternatives stated in the recurrence (computed in line 11,12, 13). By obtaining the locally optimum solutions, we eventually get the edit distance from grid.[s.length, t.length].
Complexity: Run-time complexity: . Lets denote the lengths of both strings as . Then, the complexity become . Space complexity is also same.
Complete source code is outlined in the next page.
Given a list, write a function to reverse every K element when k is an input to the function.
Example:
Input: [1;2;3;4;5;6;7;8] and k = 3
Output:[3;2;1;6;5;4;8.7]
In case of an empty list, it just returns [].
Solution with F#:
From the problem definition, the signature of reverseK is quite trivial:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In order to implement this function, we have used int list list, which in essence, acts as an accumulator to store the intermediate results. In addition, for every Kth element, we are creating a new list (Line 5) and resetting counter i to zero for further processing. In a sense, we are splitting the list in K chunks and reversing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These results are afterwards reversed and flattened using List.rev and List.collect as shown in Line 13 and in Line 14.
Algorithmic Complexity:
Complexity of the above algorithm: O(n).
Solution with c:
An implementation of this problem in C is available here.
Output:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters