Pixar’s Elemental

Pixar always delivers on giving you a nice warm feeling by the time you finish watching the film.
Loved the design of the city and characters. This was a must watch for me as I have the tattoos of the four elements.

30 days of code: Day 10

https://www.hackerrank.com/challenges/30-binary-numbers/

To be honest, I looked this one up. In fact, many people had the same solution. Don’t really know who the original is, but thanks. Decided not to write the Task, head to link above for full details on the problem.

var n = int.Parse(Console.ReadLine());

var sum = 0;
var max = 0;


while (n > 0)
{
    if (n % 2 == 1)
    {
        sum++;

        if (sum > max)
            max = sum;
    }
    else sum = 0;

    n = n / 2;
}

Console.WriteLine(max);

30 days of code: Day 9

https://www.hackerrank.com/challenges/30-recursion/

Recursions were new to me. Haven’t had to use them with my previous apps. Or maybe I could have? Learned Summation, Factorial, and Exponentiation.

Sample Input
3

Sample Output
6

int n = Convert.ToInt32(Console.ReadLine());
static int Factorial(int n)
{
    if (n == 1)
    {
        return 1;
    }
    else
    {
        return n * Factorial(n - 1);
    }
}

Console.WriteLine(Factorial(n));

30 days of code: Day 8

https://www.hackerrank.com/domains/tutorials/30-days-of-code

Using a Dictionary
Sample Input

3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry
Sample Output

sam=99912222
Not found
harry=12299933
// Input number of data to retrieve
int nameCount =Convert.ToInt32(Console.ReadLine());

// Create Dictionary
Dictionary<string, string> phoneBook = new Dictionary<string, string>();

// User adds name and phonenumber to Dictionary x times
for (int i = 0; i < nameCount; i++)
{
    string inputPhoneBook = Console.ReadLine();
    string[] nameAndPhoneNumber = inputPhoneBook.Split(" ");
    string name = nameAndPhoneNumber[0];
    string phoneNumber = nameAndPhoneNumber[1];

    phoneBook.Add(name, phoneNumber);
}

// Name search and output infinite times
while (true)
{
    string inputName = Console.ReadLine();
    if (!string.IsNullOrEmpty(inputName))
    {
        if (phoneBook.ContainsKey(inputName))
        {
            Console.WriteLine(inputName + "=" + phoneBook[inputName]);
        }
        else
        {
            Console.WriteLine("Not found");
        }
    }
}

30 Days of code: Day 6

https://www.hackerrank.com/domains/tutorials/30-days-of-code
Felt like there’s a better way to do this, but this was my take.

Problem was to choose how many words to read, and then output even and odd characters in the format below.
Sample Input

2
Hacker
Rank

Sample Output

Hce akr
Rn ak

        int inputNumber = Convert.ToInt32(Console.ReadLine());

        for (int i = 0; i < inputNumber; i++)
        {
            string s = Console.ReadLine();

            for (int x = 0; x < s.Length; x += 2)
            {
                char evenChar = s[x];
                Console.Write(evenChar);
            }
            Console.Write(" ");

            for (int x = 1; x < s.Length; x += 2)
            {
                char oddChar = s[x];
                Console.Write(oddChar);
            }
            Console.WriteLine();
        }

30 Days of code: Day 4

https://www.hackerrank.com/domains/tutorials/30-days-of-code
No key notes for today’s code.

class Person {
    public int age;     
	public Person(int initialAge) {
        // Add some more code to run some checks on initialAge
        if (initialAge >= 0){
            age = initialAge;
        }
        else {
            age = 0;
            Console.WriteLine("Age is not valid, setting age to 0.");
        }
     }
     public void amIOld() {
        // Do some computations in here and print out the correct statement to the console 
        if (age < 13){
            Console.WriteLine("You are young.");
        }
        else if (age >= 13 && age < 18){
            Console.WriteLine("You are a teenager.");
        }
        else {
            Console.WriteLine("You are old.");
        }
     }

     public void yearPasses() {
        // Increment the age of the person in here
        age++;
     }
}

30 days of code: Day 2

https://www.hackerrank.com/domains/tutorials/30-days-of-code

Today’s code challenge was to come up with the solve function, in order to output the total cost of a meal including the tax and tip.

tip_percent and tax_percet are integers, but no need to convert to a Double?
By dividing the value by 100.0, we are using “Implicit Type Conversion

class Result
{

    /*
     * Complete the 'solve' function below.
     *
     * The function accepts following parameters:
     *  1. DOUBLE meal_cost
     *  2. INTEGER tip_percent
     *  3. INTEGER tax_percent
     */

    public static void solve(double meal_cost, int tip_percent, int tax_percent)
    {
        double tipCost = meal_cost * (tip_percent / 100.0);
        double taxCost = meal_cost * (tax_percent / 100.0);
        double totalCost = meal_cost + tipCost + taxCost;
        Console.WriteLine(Math.Round(totalCost));
    }

}

class Solution
{
    public static void Main(string[] args)
    {
        double meal_cost = Convert.ToDouble(Console.ReadLine().Trim());

        int tip_percent = Convert.ToInt32(Console.ReadLine().Trim());

        int tax_percent = Convert.ToInt32(Console.ReadLine().Trim());

        Result.solve(meal_cost, tip_percent, tax_percent);
    }
}