Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Trond240/e1e940704d1f44ace0e9e69b4510b20f to your computer and use it in GitHub Desktop.

Select an option

Save Trond240/e1e940704d1f44ace0e9e69b4510b20f to your computer and use it in GitHub Desktop.

Revisions

  1. Trond240 revised this gist Jul 30, 2020. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions roman_numeral_recursion.md
    Original file line number Diff line number Diff line change
    @@ -69,11 +69,19 @@ string builder will print roman numeral representation of our input
    ```

    ## What do you think the Big O complexity of your algorithm is? (time complexity and space complexity)

    O(n)2, because we are working with two arrays and combining the information ti make 1.
    ## JS Starter Code
    ```js
    function toRoman(num) {
    // your code goes here
    let values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
    let romanLetters =["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
    let romanString = []
    for(i = 0; i < values.length; i++) {
    if (num => values[i]) {
    num -= values[i];

    }
    }
    }

    console.log(toRoman(128)); // should return "CXXVIII"
  2. Trond240 revised this gist Jul 30, 2020. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion roman_numeral_recursion.md
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,13 @@ Here are the Roman Numeral equivalents you'll need to know:

    ## What assumptions will you make about this problem if you cannot ask any more clarifying questions? What are your reasons for making those assumptions?

    Write a function that takes in a integer and coverts it into roman numerals in the most effecient way.


    ## What are your initial thoughts about this problem? (high level design, 2-3 sentences)

    My initial thoughts on this problem is that I will need to store my numbers and their corresponding roman numerals in an array. I will then need to figure out the pattern for coverting the integer into a roman numeral string.


    ## How would you identify the elements of this problem?

    @@ -48,11 +52,20 @@ Here are the Roman Numeral equivalents you'll need to know:

    ## Which data structure(s) do you think you'll use? What pros/cons do you see with that choice?

    I will use arrays so that I can do my calculations with a forloop.

    ## Write out a few lines of initial pseudocode: (mid-level design, this should be short, and not be real code!)

    ```
    write out your pseudocode here
    Store letters used in Roman numerals
    Store corresponding numerical numbers in an array
    Create a string builder
    Check the number being input if it is less than or eqaul to the highest roman numeral
    Add to the string builder
    Reduce corresponding value from input number
    if input number is greater than highest roman then check with next highest roman numeral
    repeat til inout number = 0
    string builder will print roman numeral representation of our input
    ```

    ## What do you think the Big O complexity of your algorithm is? (time complexity and space complexity)
  3. @ericweissman ericweissman revised this gist Jul 30, 2020. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions roman_numeral_recursion.md
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,19 @@ Write a recursive function that converts an integer into a string such that the
    eg, the number 4 could be written as 'IIII' but it's more efficient to use 'IV' since that's a shorter string
    Assume no number is greater than 4,000
    Here are the Roman Numeral equivalents you'll need to know:
    M=1000, CM=900, D=500, CD=400,
    C=100, XC=90, L=50, XL=40,
    X=10, IX=9, V=5, IV=4, I=1
    * M=1000
    * CM=900
    * D=500
    * CD=400
    * C=100
    * XC=90
    * L=50
    * XL=40
    * X=10
    * IX=9
    * V=5
    * IV=4
    * I=1

    ## Rewrite the question in your own words:

  4. @ericweissman ericweissman created this gist Jul 30, 2020.
    71 changes: 71 additions & 0 deletions roman_numeral_recursion.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    # Instructions

    1. Fork this gist, then "edit" the gist
    2. Fill out the questions below
    3. Click the "Add file" button and add your source code to the gist
    4. Submit by the due time as instructed in Zoom

    Do not publish your code on a public repl.it or repo or other public means.

    ## Prompt
    Write a recursive function that converts an integer into a string such that the number is represented in Roman Numerals in the most efficient way.
    eg, the number 4 could be written as 'IIII' but it's more efficient to use 'IV' since that's a shorter string
    Assume no number is greater than 4,000
    Here are the Roman Numeral equivalents you'll need to know:
    M=1000, CM=900, D=500, CD=400,
    C=100, XC=90, L=50, XL=40,
    X=10, IX=9, V=5, IV=4, I=1

    ## Rewrite the question in your own words:


    ## What assumptions will you make about this problem if you cannot ask any more clarifying questions? What are your reasons for making those assumptions?


    ## What are your initial thoughts about this problem? (high level design, 2-3 sentences)


    ## How would you identify the elements of this problem?

    - [ ] Searching of Data
    - [ ] Sorting of Data
    - [ ] Pattern Recognition
    - [ ] Build/Navigate a Grid
    - [ ] Math
    - [ ] Language API knowledge
    - [ ] Optimization


    ## Which data structure(s) do you think you'll use? What pros/cons do you see with that choice?


    ## Write out a few lines of initial pseudocode: (mid-level design, this should be short, and not be real code!)

    ```
    write out your pseudocode here
    ```

    ## What do you think the Big O complexity of your algorithm is? (time complexity and space complexity)

    ## JS Starter Code
    ```js
    function toRoman(num) {
    // your code goes here
    }

    console.log(toRoman(128)); // should return "CXXVIII"
    console.log(toRoman(2000)); // should return "MM"
    console.log(toRoman(2017)); // should return "MMXVII"
    console.log(toRoman(1999)); // should return "MCMXCIX"
    ```
    ## Ruby Starter Code
    ```rb
    def to_roman(num)
    # your code goes here
    end

    puts to_roman(128) # should return "CXXVIII"
    puts to_roman(2000) # should return "MM"
    puts to_roman(2017) # should return "MMXVII"
    puts to_roman(1999) # should return "MCMXCIX"
    ```