Drop boxes for syringe disposal in Seattle

http://www.kingcounty.gov/depts/health/communicable-diseases/hiv-std/patients/drug-use-harm-reduction/needle-disposal.aspx

Posted in Health and wellness | Leave a comment

Check if a string can become empty by recursively deleting a given sub-string

Given a string “str” and another string “sub_str”. We are allowed to delete “sub_str” from “str” any number of times. The task is to find if “str” can become empty by removing “sub_str” again and again.

Examples:

Input : str = “GEEGEEKSKS”, sub_str = “GEEKS”
Output : Yes
Explanation : In the string GEEGEEKSKS, we can first
delete the substring GEEKS from position 4.
The new string now becomes GEEKS. We can
again delete sub-string GEEKS from position 1.
Now the string becomes empty.

Input : str = “GEEGEEKSSGEK”, sub_str = “GEEKS”
Output : No
Explanation : In the string it is not possible to make the
string empty in any possible manner.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static int flag = 0;
        public static void Main(string[] args)
        {
            string str = "KEEKEEKK";
            string subStr = "KEEK";
            RecursiveDeletion(str, subStr);
            if(flag == 0)
            {
                Console.WriteLine("No");
            }
        }

        public static void RecursiveDeletion(string str, string subStr)
        {
            if (str == null || str.Length == 0)
            {
                Console.WriteLine("Yes");
                flag = 1;
            }
            else
            {
                for (int i = 0; i <= str.Length - subStr.Length && flag == 0; i++)
                {
                    if (str.Substring(i, subStr.Length) == subStr)
                    {
                        RecursiveDeletion(str.Remove(i, subStr.Length), subStr);
                    }
                }
            }
        }
    }
}

Output
=======
Yes
Press any key to continue . . .
Posted in Information Technology | Leave a comment

Program to find amount of water in a given glass

There are some glasses with equal capacity as 1 litre. The glasses are kept as follows:

1
2 3
4 5 6
7 8 9 10

You can put water to only top glass. If you put more than 1 litre water to 1st glass, water overflows and fills equally in both 2nd and 3rd glasses. Glass 5 will get water from both 2nd glass and 3rd glass and so on.
If you have X litre of water and you put that water in top glass, how much water will be contained by jth glass in ith row?

Example. If you will put 2 litre on top.
1st – 1 litre
2nd – 1/2 litre
3rd – 1/2 litre

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public class Glass
        {
            public double volume;
        }
        public static void Main(string[] args)
        {
            double volumeOfWater = 100;
            int rowNum = 7, colNum = 7;
            double glassCapacity = 1;
            Glass[] glass = new Glass[(rowNum + 1) * (rowNum + 1 + 1)/2];//add an extra row
            //Initialize the glass array and store it in a list
            List<List<Glass>> glassPattern = new List<List<Glass>>();
            for (int glassCounter = 0, row = 0; row < rowNum + 1; row++)
            {
                List<Glass> subList = new List<Glass>();
                for (int col = 0; col <= row; col++)
                {
                    glass[glassCounter] = new Glass();
                    glass[glassCounter].volume = 0;
                    subList.Add(glass[glassCounter++]);
                }
                glassPattern.Add(subList);
            }
            //Fill the top glass
            glassPattern[0][0].volume = volumeOfWater;
            //Mock the waterflow
            int flag = 0;
            for (int i = 0; i < glassPattern.Count - 1 && flag == 0; i++)//for each row but the last
            {
                for (int j = 0; j < glassPattern[i].Count; j++)//each column
                {
                   if(glassPattern[i][j].volume > glassCapacity) //nothing to do if volume <= glassCapacity
                    {
                        double temp = glassPattern[i][j].volume;
                        glassPattern[i][j].volume = glassCapacity;
                        glassPattern[i + 1][j].volume = glassPattern[i + 1][j].volume + (temp - glassCapacity) / 2;
                        glassPattern[i + 1][j + 1].volume = glassPattern[i + 1][j + 1].volume + (temp - glassCapacity) / 2;
                    }
                   if(i == rowNum - 1 && j == colNum - 1)
                    {
                        Console.WriteLine("Volume of water in glass position (" + rowNum + "," + colNum + ") = " + glassPattern[i][j].volume);
                        flag = 1;
                        break;
                    }
                }
            }
        }
    }
}

Output
=======
Volume of water in glass position (7,7) = 0.578125
Press any key to continue . . .
Posted in Information Technology | Leave a comment

Application stages and timelines for Indian Entry Visa

Overall it took 7 days to complete the entire application process. It excludes the passport delivery timelines which depends on the opted shipping speed with the carrier (FedEx/UPS/USPS).

1. Received
2. Verification
3. UNDER PROCESS at CKGS
4. IN TRANSIT to Embassy
5. UNDER PROCESS at Embassy
6. IN TRANSIT to CKGS
7. Sorting
8. Dispatch
9. Delivered

Oct 12, 2016 09:45 pm Application is ‘Dispatch’
Passport picked up by UPS from CKGS in the Pre-Paid Envelope provided by you.

Your AWB Number is XXXXXXXXXXXXXX9083

To track the ‘Progress of Your Shipment’, log onto the site of your Service Provider and enter your AWB Number.

View History (reverse chronological order)
====================================

Oct 12, 2016 – Wednesday
09:45 pm
Passport picked up by UPS from CKGS in the Pre-Paid Envelope provided by you.
Your AWB Number is XXXXXXXXXXXXXX9083
To track the ‘Progress of Your Shipment’, log onto the site of your Service Provider and enter your AWB Number.

Oct 12, 2016 – Wednesday
08:50 pm
Passport ‘Received’ at the CKGS application center and is at the ‘Sorting Facility’ where it is being processed for delivery.

Oct 12, 2016 – Wednesday
07:21 pm
Application ‘Reviewed’ by Consulate and ‘In Transit’ to CKGS Application Centre.

Oct 07, 2016 – Friday
11:40 am
Application is ‘Under Process’ at Consulate for decision making.

Oct 06, 2016 – Thursday
08:22 pm
Application is ‘In Transit’ to the Consulate.

Oct 06, 2016 – Thursday
04:38 pm
Application is ‘Under Process’ at CKGS.

Oct 04, 2016 – Tuesday
06:29 pm
Application Verification is ‘Complete’. Processing of your application will continue.
The Consulate may request for further documents over and above those already submitted as per the Document Checklist.
Please continue tracking your application status online.

Oct 03, 2016 – Monday
07:48 pm
Application ‘Received’ by CKGS and ‘Not Verified’.
You will receive an E-mail advising you of the outcome of the verification process.

Posted in Business, Travel | Leave a comment

Online Video Editing Tool

http://online-video-cutter.com/

Posted in Information Technology | Leave a comment

Optimized Painting

You are given a range [first, last], initially white. You need to paint it black.
For this purpose you have a set of triples
[(f, l, cost), …] – where each triple means that you can paint the range [f, l] for ‘cost’ coins (limitations: cost is floating point >= 0; f, l are integers representing start and end of the range to be painted black).
Find minimum cost needed to paint the whole range [first, last] or return -1 if it’s impossible

Example:
[first, last] = [0, 5] and set of triples are
[[0, 5, 10], [0, 4, 1], [0, 2, 5], [2, 5, 1]]
Clearly the answer is to take [0, 4, 1] and [2, 5, 1] – the total cost will be 2.

Another example:
[first, last] = [0, 5]
triples are [[1,4, 10], [2, 5, 6]]
answer is -1, because it’s impossible to color the whole range.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    public class Triplet
    {
        public int start;
        public int end;
        public float cost;
    }

    class Program
    {
        public static void Main(string[] args)
        {
            string rangeStr = "[0, 5]";
            string tripletStr = "[0, 5, 10], [0, 4, 1], [0, 2, 5], [2, 5, 1]";
            char[] trimChar = { '[', ']' };
            Regex reg = new Regex(",");
            string[] rangeSplit = reg.Split(rangeStr.Trim(trimChar));
            int start = int.Parse(rangeSplit[0].Trim());
            int end = int.Parse(rangeSplit[1].Trim());
            Triplet[] triplets = ParseTriplet(tripletStr);
            //Filter out valid triplets
            ArrayList al = new ArrayList();
            for (int i = 0; i < triplets.Length; i++)
            {
                if ((start >= triplets[i].start && start < triplets[i].end) || (end > triplets[i].start && end <= triplets[i].end) || (triplets[i].start >= start && triplets[i].start < end) || (triplets[i].end > start && triplets[i].end <= end))
                {
                    al.Add(i);
                }
            }
            //Generate combinations
            float minCost = 0; ArrayList comboList = new ArrayList();
            int flag = 0;
            int maxLimit = (int)Math.Pow(2, al.Count) - 1;
            for (int i = 1; i <= maxLimit; i++)
            {
                string binary = DecimalToBinary(i).PadLeft(al.Count, '0');
                float tempCost = 0; ArrayList tempList = new ArrayList();
                for (int j = 0; j < binary.Length; j++)
                {
                    if (binary[j] != '0')
                    {
                        tempCost = tempCost + triplets[(int)al[j]].cost;
                        tempList.Add(triplets[(int)al[j]]);
                    }
                }
                //Check for valid combinations
                if (ValidCombo(tempList, start, end))
                {
                    if (flag == 0)
                    {
                        flag = 1;
                        comboList.AddRange(tempList);
                        minCost = tempCost;
                    }
                    else if (tempCost < minCost)
                    {
                        comboList.Clear();
                        comboList.AddRange(tempList);
                        minCost = tempCost;
                    }
                }
            }
            if (comboList.Count == 0)
            {
                Console.WriteLine("No solution found...");
            }
            else
            {
                Console.WriteLine("Minimum Cost = " + minCost);
                for (int i = 0; i < comboList.Count; i++)
                {
                    Console.WriteLine("[" + ((Triplet)comboList[i]).start + ", " + ((Triplet)comboList[i]).end + ", " + ((Triplet)comboList[i]).cost + "]");
                }
            }
        }

        public static bool ValidCombo(ArrayList tempList, int start, int end)
        {
            Hashtable ht = CreateHashTable(start, end);
            for (int i = 0; i < tempList.Count; i++)
            {
                for (int j = ((Triplet)tempList[i]).start; j < ((Triplet)tempList[i]).end; j++)
                {
                    if (ht.Contains(j.ToString() + ";" + (j + 1).ToString()))
                    {
                        ht[j.ToString() + ";" + (j + 1).ToString()] = 1;
                    }
                }
            }
            return CheckHashTable(ht);
        }

        public static bool CheckHashTable(Hashtable ht)
        {
            foreach (DictionaryEntry entry in ht)
            {
                if ((int)entry.Value == 0)
                    return false;
            }
            return true;
        }

        public static Hashtable CreateHashTable(int start, int end)
        {
            Hashtable ht = new Hashtable();
            for (int i = start; i < end; i++)
            {
                ht.Add(i.ToString() + ";" + (i + 1).ToString(), 0);
            }
            return ht;
        }

        public static string DecimalToBinary(int num)
        {
            string rem = "";
            while (num >= 1)
            {
                int quot = num / 2;
                rem += (num % 2).ToString();
                num = quot;
            }
            // Reversing the  value
            string bin = "";
            for (int i = rem.Length - 1; i >= 0; i--)
            {
                bin = bin + rem[i];
            }
            return bin;
        }

        public static Triplet[] ParseTriplet(string tripletStr)
        {
            Triplet[] triplets = new Triplet[GetNumberOfTriplets(tripletStr)];
            string tempStr = ""; int flag = 0, counter = 0;
            for (int i = 0; i < tripletStr.Length; i++)
            {
                if (tripletStr[i] == '[')
                {
                    flag = 1;
                }
                else if (tripletStr[i] == ']')
                {
                    flag = 0;
                    Regex reg = new Regex(",");
                    string[] tripletSplit = reg.Split(tempStr);
                    triplets[counter] = new Triplet();
                    triplets[counter].start = int.Parse(tripletSplit[0].Trim());
                    triplets[counter].end = int.Parse(tripletSplit[1].Trim());
                    triplets[counter].cost = float.Parse(tripletSplit[2].Trim());
                    counter++;
                    tempStr = "";
                }
                else if (flag == 1)
                {
                    tempStr = tempStr + tripletStr[i];
                }
            }
            return triplets;
        }

        public static int GetNumberOfTriplets(string tripletStr)
        {
            int count = 0;
            for (int i = 0; i < tripletStr.Length; i++)
            {
                if (tripletStr[i] == '[')
                    count++;
            }
            return count;
        }
    }
}

Output
=======
Minimum Cost = 2
[0, 4, 1]
[2, 5, 1]
Press any key to continue . . .
Posted in Information Technology | Leave a comment

Generate all possible combinations when two strings are merged while retaining the same character sequence

Given two strings A and B, generate all possible combinations when B is merged into A.
Example: A = “hey”
B: “sam”
Then the combinations are:
“heysam”, “hseaym”, “hesaym”, “sahemy” etc.

Note that the character order remains the same for both the strings while merging.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static void Main(string[] args)
        {
            string str1 = "sam";
            string str2 = "hey";
            Merge(str1, str2, "", 0, 0, 0);
            Merge(str2, str1, "", 0, 0, 0);
        }
        public static void Merge (string str1, string str2, string str, int pos1, int pos2, int toggle)
        {
            if (str.Length == str1.Length + str2.Length)
            {
                Console.WriteLine(str);
            }
            else
            {
                if(toggle == 0)
                {
                    for (int i = 1; i <= str1.Length; i++)//string length
                    {
                        if(pos1 + i <= str1.Length)
                        {
                            Merge(str1, str2, str + str1.Substring(pos1, i), pos1 + i, pos2, 1);
                        }
                    }
                }
                else
                {
                    for (int i = 1; i <= str2.Length; i++)//string length
                    {
                        if (pos2 + i <= str2.Length)
                        {
                            Merge(str1, str2, str + str2.Substring(pos2, i), pos1, pos2 + i, 0);
                        }
                    }
                }
            }
        }
    }
}

Output
=======
shaemy
shaeym
shamey
sheaym
sheamy
sheyam
sahmey
sahemy
saheym
samhey
hseaym
hseamy
hseyam
hsaemy
hsaeym
hsamey
hesyam
hesaym
hesamy
heysam
Press any key to continue . . .
Posted in Information Technology | Leave a comment