Posts

Showing posts from May, 2017

Finding words in a crosswords (homework assistance)

Image
One of my kids had the following task: find a set of words in the following crosswords: The set of words was given. The crosswords was created by another student, who accidentally might have drawn the wrong letter at the wrong position, which makes the task of finding the given words hard, especially for little kids. After attempting for a while, I decided to give them a hand. Here is a program to help them out: Input: a crosswords and a set of words to look for The code to find a given word in the crosswords is simple, just laborious and tedious: find the match to the first letter, then go into all the 8 possible directions trying to find the rest of the word. If found => success! The interesting part of the problem is to deal with the potential partial matches. To deal with that, take each word and recursively create a set of partial sub-words. The sub-words are created by removing characters from the initial word. Do so in such a way to always start with sub-words...

WannaCry Ransomware Encryption and Decryption

Image
UPDATE 1 : there is a very comprehensive Wiki about this ransomware:  https://en.wikipedia.org/wiki/WannaCry_cyber_attack . Keep on reading if you want to see some code. UPDATE 2 : patch your machines!!! This is coming directly from the dude who stopped WannaCry 1.0: OK, back to the blog: If you are one of the unfortunate 75,000 people who saw this pop-up in the past 72 hours: Then I have some bad news and some good news for you. Let's start with the bad news: first, your files are gone. Well, technically they are not gone, they've just been encrypted in your machine. Good luck trying to decrypt them. So yes, they are gone my friend. Sorry. But hey, if you managed to pay the 300 bucks, I do have some good news for you: you've just made a couple of guys somewhere (likely in Siberia or Finland) very, very happy!!! Isn't that a good feeling, to make people happy?! Good for you!!! Jokes aside, the WannaCry ransomware (whose more information you can find he...

Graph or Permutations With Constraints?

This is a variation (generalization) of an interview question asked by one of the engineers in our team (btw, you can check out one of her amazing talks, it is right here:  https://forwardcourses.com/lectures/239 ). The problem is the following: You'll be given a set of characters, let's name them C1, C2, ..., Cn, (for simplicity sake, there is no repetition) and you need to generate all permutations of these characters without violating any constraint. You're also given a set of constraints. Each constraint will be a pair of characters (Ci, Cj), and the semantics is that for Cj to show up in the resulting string, it can only be there when Ci shows up before it. Noticed that Ci and Cj do not have to necessarily be adjacent to each other Here is an example. Suppose that the set of characters is "ABC" and there is just one constraint: (A,C). Which means that for C to show up in the resulting string, A must precede it. There are only 3 possibilities then: A B C...

Big Sorting, a HackerRank problem

Image
Here is the link to the problem:  https://www.hackerrank.com/challenges/big-sorting , and the description copied/pasted: Consider an array of numeric strings,  , where each string is a positive number with anywhere from   to   digits. Sort the array's elements in  non-decreasing  (i.e., ascending) order of their real-world integer values and print each element of the sorted array on a new line. The numbers will be massive, up to 10^6 digits. One option is to use the BigInteger data type, but operations with BigIntegers are very slow. The other one, which is the one that I had opted to use, uses the Array.Sort() method in C#. The only caveat here is to implement the IComparer.Compare method. In our case it is very easy to implement since the inputs are in string format, with no leading zero. The key part of the code in my opinion is the implementation of this function , the rest is just syntax. Thanks, Marcelo. using System; using System....