This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create a 9x9 Array | |
| string = ['E', 'B', 'D', 'R', 'T', 'U', 'P', 'W', 'F', 'Q', 'I', 'N', 'S', 'V', 'Z', 'D', 'R', 'T', 'U', 'P', 'W', 'D', 'R', 'T'] | |
| new_array = Array.new(4) {string.shift(6)} | |
| # => [["E", "B", "D", "R", "T", "U"], ["P", "W", "F", "Q", "I", "N"], ["S", "V", "Z", "D", "R", "T"], ["U", "P", "W", "D", "R", "T"]] | |
| puts | |
| # Print nicely | |
| new_array.map{|letter| letter.join(" ")}.join "\n" | |
| # => E B D R T U | |
| # P W F Q I N |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Baker | |
| end | |
| class Oven | |
| end | |
| class Cookies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $local_var1 = "A String" # This is defined in the global scope. The $ tells us that the variable is accessible globally | |
| def get_local_var1 | |
| $local_var1 # Without the $ this varible is undefined and we get and error. | |
| # local_var1 = 2 will override the global variable and return the 2. | |
| end | |
| puts get_local_var1 # the string is returned | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # PSEUDOCODE | |
| # Base case - Return solved grid if no num in grid less than 9 times | |
| # CREATE the board and numbers | |
| # Find the most common number | |
| # Loop through the boxes starting from the top left, searching for num | |
| # IF block has num | |
| # go to next box | |
| # ELSIF box does not have num | |
| # Look to respective columns and rows to see if num is there | |
| # ELSE where rows and columns do not contain num, add num to that respective square |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mean(numbers) | |
| sum = numbers.inject(:+) | |
| return sum / numbers.length | |
| end | |
| # Added brackets and created this as an array to make work | |
| sample_avg = mean([5, 3, 6, 10]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mean(*numbers) | |
| sum = numbers.inject(:+) | |
| return sum / numbers.length | |
| end | |
| # This will throw an error. Change this line so that it works. | |
| sample_avg = mean(5, 3, 6, 10) |