Craig Rodrigues!

Learning to Code: Week 11 - Coding While Travelling

7/21/16

  • Mom sent me this article here.
  • I applied to Rmotr. What’s the harm really. I don’t know anything about Object Oriented Programming so I just had to guess when that question came up.

7/22/16

  • Wasn’t able to get anything in today - busy working at SDCC. 😢 

7/23/16

  • CS50 is having a coding contest next weekend I will try to take part in. You can have teams and setup meetups too.

CS50 and HackerRank present the first-ever...

CS50x CODING CONTEST 2016

an epic weekend of code

Friday, 29 July 2016 – Sunday, 31 July 2016

Open to CS50x students around the world (and friends). Solve as many problems (in C!) as you can!

7/24/16

  • Worked on the Temperature Conversion practice challenge for CS50. It’s a simpler version of the Daily Challenge I did a bit ago, but I can’t seem to get my code to pass two of their test cases and I don’t know why.

Write a program that, given a temperature in Celsius, C, as a floating-point value via standard input, prints via standard output that temperature in Fahrenheit, F, as a floating-point value, rounded to one decimal place.

Recall that:

F = C * 9/5 + 32

For example, if a user inputs:

0.0, your program should print 32.0

100.0, your program should print 212.0

42.0, your program should print 107.6

screenshot-2016-07-24-07-42-22

7/25/16

  • Was out working and then visiting sites in San Diego. Nothing done today.

comic-con1

7/26/16

  • Flying all day back from working SDCC. Didn’t do anything on the plane except watch a movie and nap.

7/27/16

  • Found a guy in Atlanta that was looking for a teammate for the CS50 challenge. Hopefully he responds favorably to my email.
  • Asked for help on the CS50 practice problem, and the only reason my code failed two test cases was because I used float instead of double...weird.
  • Solution here
#include <math.h>
#include <stdio.h>
#include "cs50.h"

int main(void)
{
    double num;

    while (scanf("%lf", &num) == 1)
    {
        if (num < DBL_MAX || num >= -DBL_MAX)
        {
            double answer = num * 1.8 + 32;
            printf("%.1f\n", answer);
        }
        else
        {
            printf("Enter a number between %f and %f degrees Celsius.", -DBL_MAX, DBL_MAX);
            return 1;
        }    
    }
    return 0;
}

 

7/28/16

  • Finished the factorization practice problem.
    • Write a program that takes an integer as input and outputs its factorial.
    • Solution here
  • It took me a long time (a bit over an hour), but I finished the practice problem to find a substring in a string! There is only a 60% success rate on that one.
    • Write a program that takes two strings as input. If the second string is a substring of the first, output the index where the second string begins within the first string. Otherwise, output -1. Be sure to support wildcard characters, represented by an asterisk (*).
    • Solution here
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cs50.h"

int main(void)
{
    int num = GetInt();
    int factorial = 1;

    for (int i = num; i > 0; i--)
    {
        factorial *= i;
    }

    printf("%i", factorial);
    return 0;
}

 

  • Solved decimal to binary converter practice problem (took maybe 10 minutes)
    • Take in a decimal number via input and output the corresponding binary number, displaying only significant bits (i.e., don't show 01111 for 15, only 1111).
    • Solution here
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cs50.h"

int main(void)
{
    int i = 0;
    int remainder;
    int binary[50]; //this is an array placeholder for the binary digits. Once we put each one in there we will print it out again but backwards.

    int decimal = GetInt();

    while (decimal != 0)
    {
        binary[i] = decimal % 2;
        decimal = decimal / 2;
        i++;
    }

    for (int j = i - 1; j >= 0; j--)
        printf("%d", binary[j]);
}

Learning to Code: Week 12 - CS50x Coding Contest!

Learning to Code: Week 10 - Understand the Whole Problem