Skip to content

Instantly share code, notes, and snippets.

View 1UnboundedSentience's full-sized avatar

Jason Xu 1UnboundedSentience

View GitHub Profile
@1UnboundedSentience
1UnboundedSentience / find maximum contiguous sequence of 1s in an Array of 0s and 1s, given that you can change k number of 0s to 1s
Last active February 22, 2016 02:24
find maximum contiguous sequence of 1s in an Array of 0s and 1s, given that you can change k number of 0s to 1s
def max_contig(array, k)
max_len = 0
sliding_window = []
window_start = 0
potential_len = 0
array.each_index do |idx|
p "#{idx} #{sliding_window[0]}---#{sliding_window[-1]}"
potential_len += 1
if array[idx] == 0
sliding_window << idx
each card has attribute
controller.launch
input:
output: calls greeting
view.display_greeting
input: a greeting as a string
output: printing greeting to screen as a string
Messages are the foundation of OO, but classes are the most visible org structure. You must decide what your classes are, how many, behavior, how much they know about other classes, how much they expose. Group methods into classes. How you decide will forever influence how you think of your application.
Good princpiple is to allow for "easy changes": meaning
-changes have no side effects
-small changes in req require small change sin code
-code easy to reuse
TRUE - transparent, reasonable, useable, exemplary -
If something has both data and behavior (the gears on a bike have chainrigs, cogs, ratios) there should be a separate class for it, assuming modelling wheel size vs distance travelled is important.