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!

Continue reading →

Learning to Code: Week 10 – Understand the Whole Problem

7/14/16

  • Excellent food for thought when it comes to solving a problem (from Shawn).

What I gave you was basically a functional requirement. Get from Atlanta to Miami.

But to get to the right answer, you have to get to the non-functional things that are important.

Is it about speed?

Is it about safety?

Do I want to see awesome scenery?

That’s one of the things that differentiates a programmer from an architect. Architects work to understand the whole problem space before running off an doing something. Or at least good ones do.

7/15/16

  • Nothing done today. 😑

7/16/16

003

Continue reading →

Learning to Code: Week 9 – Python?

7/8/16

CS50 Week 5

  • Watched lecture 1 (56m)

Found this website that indexes the popularity of various programming languages: http://www.tiobe.com/tiobe_index

Trying Daily Programmer Challenge #273 – Degree

  • Learned about scanf and its capabilities. Very cool. http://beej.us/guide/bgc/output/html/multipage/scanf.html
  • Wrote up the program on scratch paper while on break at work.
  • Everything seems to be working okay so far except when I use strcmp on “rd” it still thinks “dr” is acceptable?
  • Well it seems I should’ve read more about strcmp

  • Program is working now for degree and radians. I may try to tackle the bonus as well a little bit later as it would only require adding in more formulas.
  • A function would probably help that just used all that stuff and returned the conversion just to look cleaner?
  • I am not sure how to deal with decimals or rounding here. The output for rd is just to a whole number, but if I do %.2f I’ll always get a trailing 180.00.
  • Google to rescue again for my question above. I can use %g! http://stackoverflow.com/questions/9628645/use-printf-to-format-floats-without-decimal-places-if-only-trailing-0s
  • Still not sure how well %g will work well since precision is impaired.
  • http://stackoverflow.com/questions/277772/avoid-trailing-zeroes-in-printf WTF O_o
  • For the bonus attempt I’m going to write a function to convert any of the provided inputs. For converting Kelvin I’ll just have the function call itself to convert F to C or C to F.
  • Also that way you can add other units down the line like inches to feet or inches to cm.
  • http://www.almanac.com/content/temperature-conversion
  • Kept getting 0 as an output in my program, then remembered my functions have to return something. Doh.
  • My program works for all bonuses except I can’t seem to do a recursive call on my own function. Perhaps since there isn’t a base case…maybe it goes on forever somehow?
  • Debugging my function continuously calls itself instead of calling the cf one and returning a value…
  • Here is my code so far with the recursive call causing a segmentation fault 🙁

Continue reading →

Learning to Code: Week 8 – Recover

6/30/16

Problem Set 4

In ~/workspace/pset4/questions.txt, answer each of the following questions in a sentence or more.

  • What’s stdint.h?
    • A header file that standardizes integers (exact-width) across different systems.
  • What’s the point of using uint8_t, uint32_t, int32_t, and uint16_t in a program?
    • It’s easier to have aliases to use interchangeably for explicit fixed width integers. Specifies the number of bytes because one system an int might be a long in another.
  • How many bytes is a BYTE, a DWORD, a LONG, and a WORD, respectively?
    • 8, 32, 32, 16
  • What (in ASCII, decimal, or hexadecimal) must the first two bytes of any BMP file be? (Leading bytes used to identify file formats (with high probability) are generally called “magic numbers.)”
    • The file type; must be BM (ASCII).
    • 0x42 0x4D in hexadecimal.
  • What’s the difference between bfSize and biSize?
    • bfSize is the size of, in bytes, of the bitmap file.
    • biSize is the number of bytes required by the structure. (BITMAPINFOHEADER)
  • What does it mean if biHeight is negative?
    • If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.
    • If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
  • What field in BITMAPINFOHEADER specifies the BMP’s color depth (i.e., bits per pixel)?
    • biBitCount
  • Why might fopen return NULL in copy.c:37?
    • If the file cannot be found.
  • Why is the third argument to fread always 1 in our code?
  • What value does copy.c:70 assign padding if bi.biWidth is 3?
    • int padding =  (4 – (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
    • RGBTRIPLE is 3 bytes (24 bits)
    • 3 % 4 is 3
    • Padding = 3
  • What does fseek do?
  • What is SEEK_CUR?
    • How you set the offset to be relative to the current position indicator instead of the start or end.

Whodunit.c

Implement that same idea in whodunit. Like copy, your program should accept exactly two command-line arguments. And if you execute a command like the below, stored in verdict.bmp should be a BMP in which Mr. Boddy’s drawing is no longer covered with noise.

  • Once I understood the copy.c file this update to the file isn’t so bad. Copy just scans through all the pixels in a file and copies it to the output file.
  • All that is required is to check the value of the RGBTRIPLE struct BEFORE anything is written to the new file.
  • I will check for any red pixels and change them to white and see what happens.
  • Only problem I’ve run into so far is being confused on what the RGB value for red and white are. Guessing what it is isn’t a good plan when I can just look it up.
  • RED is  rgb(255,0,0)
  • WHITE is rgb(255,255,255)
  • Got red to switch with white and I know who the person in question is, however I want to darken the image to make it more clear, but I am not sure exactly how to do that.
  • I will use the xxd command and see what pixels are blue and darken those.
  • xxd printed out too much crap for me to get a good look so forget that.
  • Revealed picture is of Rick Astley…again. Look below.

BEFORE

image02

Continue reading →