Skip to content

Instantly share code, notes, and snippets.

@mark665
Created March 22, 2017 22:36
Show Gist options
  • Save mark665/e743199e2c54e6a0a4bbce0389894658 to your computer and use it in GitHub Desktop.
Save mark665/e743199e2c54e6a0a4bbce0389894658 to your computer and use it in GitHub Desktop.
Full Beaker "Homework"

1. The table below shows the formulas for triangular, pentagonal, and hexagonal numbers.

... ... ...
Triangular Tn = n(n+1)/2 1, 3, 6, 10, 15, ...
Pentagonal Pn = n(3n-1)/2 1, 5, 12, 22, 35, ...
Hexagonal Hn = n(2n-1) 1, 6, 15, 28, 45, ...

The number T285 = P165 = H143 = 40755 is a triangular number, a pentagonal number, and a hexagonal number. Write code to find the next number like this.

2. Describe a situation where something you wrote was unacceptably slow and/or memory intensive. What did you do to fix it?

3. The following javascript is intended to print twenty asterisks, but is incorrect.

    var i = 0, n = 20;
    do
    {
        document.write("*");
        i--;
    } while ( i < n );

There are at least 4 ways to fix it by replacing exactly one character. What are they?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment