Forgetful_Lion has quit [Remote host closed the connection]
stamina has joined #ruby-lang
cornerman has quit [Killed (holmes.freenode.net (Nickname regained by services))]
cornerma1 is now known as cornerman
sepp2k has joined #ruby-lang
tbuehlmann has joined #ruby-lang
havenwood has joined #ruby-lang
fusillicode has quit [Ping timeout: 260 seconds]
cornerma1 has joined #ruby-lang
lsegal has quit [Quit: Quit: Quit: Quit: Stack Overflow.]
cornerman has quit [Ping timeout: 260 seconds]
cornerma1 is now known as cornerman
cornerma1 has joined #ruby-lang
ur5us has quit [Remote host closed the connection]
cornerman has quit [Ping timeout: 240 seconds]
cornerma1 is now known as cornerman
Guest75654 is now known as perry
perry has quit [Changing host]
perry has joined #ruby-lang
fusillicode has joined #ruby-lang
cornerma1 has joined #ruby-lang
toretore has joined #ruby-lang
cornerma1 has quit [Read error: Connection reset by peer]
fusillicode has quit [Ping timeout: 260 seconds]
cornerman has quit [Ping timeout: 260 seconds]
cornerman has joined #ruby-lang
cornerma1 has joined #ruby-lang
havenwood has quit [Ping timeout: 264 seconds]
cornerman has quit [Client Quit]
cornerma1 has quit [Client Quit]
jhass|off is now known as jhass
cornerman has joined #ruby-lang
snsei has joined #ruby-lang
fusillicode has joined #ruby-lang
snsei has quit [Ping timeout: 240 seconds]
fusillicode has quit [Ping timeout: 245 seconds]
hahuang65 has joined #ruby-lang
elia has joined #ruby-lang
hahuang65 has quit [Ping timeout: 272 seconds]
fusillicode has joined #ruby-lang
GBrawl has joined #ruby-lang
elia has quit [Quit: Computer has gone to sleep.]
fusillicode has quit [Ping timeout: 246 seconds]
x0f_ has joined #ruby-lang
x0f has quit [Ping timeout: 245 seconds]
SqREL___________ has joined #ruby-lang
Iskarlar has quit [Remote host closed the connection]
Iskarlar has joined #ruby-lang
emilsoman has joined #ruby-lang
fusillicode has joined #ruby-lang
SqREL___________ has quit [Ping timeout: 244 seconds]
emilsoman has quit [Client Quit]
fusillicode has quit [Ping timeout: 258 seconds]
allomov has joined #ruby-lang
ledestin has quit [Read error: Connection reset by peer]
mikecmpbll has quit [Quit: i've nodded off.]
ledestin has joined #ruby-lang
oleo__ has quit [Quit: Verlassend]
fusillicode has joined #ruby-lang
jds has joined #ruby-lang
fusillicode has quit [Ping timeout: 272 seconds]
postmodern has quit [Quit: Leaving]
snsei has joined #ruby-lang
snsei has quit [Ping timeout: 245 seconds]
SqREL___________ has joined #ruby-lang
allomov_ has joined #ruby-lang
allomov has quit [Read error: Connection reset by peer]
fusillicode has joined #ruby-lang
allomov_ has quit [Remote host closed the connection]
allomov has joined #ruby-lang
havenwood has joined #ruby-lang
emilsoman has joined #ruby-lang
jdecuirm has quit [Ping timeout: 260 seconds]
jdecuirm has joined #ruby-lang
havenwood has quit [Ping timeout: 264 seconds]
AKASkip has joined #ruby-lang
migbar has joined #ruby-lang
mikecmpbll has joined #ruby-lang
chungshirley has joined #ruby-lang
allomov_ has joined #ruby-lang
pskosinski has joined #ruby-lang
chungshirley has quit [Remote host closed the connection]
chungshirley has joined #ruby-lang
allomov has quit [Ping timeout: 246 seconds]
chungshirley has quit [Read error: Connection reset by peer]
chungshirley has joined #ruby-lang
allomov_ has quit []
chungshirley has quit [Remote host closed the connection]
chungshirley has joined #ruby-lang
emilsoman has quit [Quit: Leaving.]
apeiros_ has joined #ruby-lang
apeiros has quit [Disconnected by services]
apeiros_ is now known as apeiros
shubhamg_ has quit [Remote host closed the connection]
shubhamgoyal has joined #ruby-lang
chungshirley has quit [Ping timeout: 246 seconds]
shubhamgoyal has quit [Read error: Connection reset by peer]
shubhamgoyal has joined #ruby-lang
allomov has joined #ruby-lang
apeiros has quit []
yfeldblum has quit [Remote host closed the connection]
hahuang65 has joined #ruby-lang
hellangel7 has joined #ruby-lang
hahuang65 has quit [Ping timeout: 260 seconds]
araujo has joined #ruby-lang
araujo has quit [Changing host]
araujo has joined #ruby-lang
mikecmpbll has quit [Quit: i've nodded off.]
havenwood has joined #ruby-lang
<jds>
If I've got an AST from Racc, is there an easy way of transforming it back into a string that's functionality equivalent to the string it came from?
nathanstitt has joined #ruby-lang
havenwood has quit [Ping timeout: 264 seconds]
arBmind has joined #ruby-lang
yfeldblum has joined #ruby-lang
enkristoffer has joined #ruby-lang
emilsoman has joined #ruby-lang
emilsoman has quit [Client Quit]
yfeldblum has quit [Ping timeout: 244 seconds]
elia has joined #ruby-lang
havenwood has joined #ruby-lang
GBrawl_ has joined #ruby-lang
snsei has joined #ruby-lang
GBrawl has quit [Ping timeout: 260 seconds]
seank_ has quit [Read error: No route to host]
seank__ has joined #ruby-lang
dwknoxy has joined #ruby-lang
klmlfl has joined #ruby-lang
snsei has quit [Ping timeout: 245 seconds]
SuMo_D has joined #ruby-lang
hellangel7 has quit [Remote host closed the connection]
jgpawletko has joined #ruby-lang
klmlfl has quit [Remote host closed the connection]
<jleigh_>
right now it returns 50 with that array... because it isnt resetting
<havenwood>
jleigh_: what would the expected return value be for?: [5, -2, 10, 6, 0, 1]
<jleigh_>
i tried using the method .each_with_index....but i kept getting the error nil can't be coerced into Fixnum (TypeError), when i tried to increment the index
<jleigh_>
it should return 17
<jhass>
jleigh_: why not 20?
<jleigh_>
how do you come by 20?
<havenwood>
jleigh_: the sum of each element
<jleigh_>
o
<havenwood>
jleigh_: they're all contiguous
<jhass>
5-2=3+10=13+6=19+0=19+1=20
<havenwood>
ljarvis: so it'd be 20?
<havenwood>
ljarvis: oops, sorry, misstell
<havenwood>
dyslexia...
TheToad has quit [Read error: Connection reset by peer]
<jleigh_>
actually im not sure
<jleigh_>
im confused....
<jleigh_>
ok let me get the question....my appologies
<jleigh_>
Given a array arr[1..n] of integers. Write an algorithm to find the sum of contiguous subarray within the array which has the largest sum
GBrawl has joined #ruby-lang
<jhass>
sounds like 20 is valid to me
<jhass>
if we change -2 to -6 it would be 17
<jleigh_>
ok yes it does... but my code isnt returning that
<jleigh_>
where am i going wrong
pkondzior____ has joined #ruby-lang
pkondzior____ has left #ruby-lang [#ruby-lang]
michaeldeol has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<jhass>
for one your count variable should always be 1
SqREL___________ has joined #ruby-lang
<jhass>
since x is always 0
<havenwood>
jleigh_: you'd need to handle situations like: [5, -2, 3, -4, 5, -6, 7]
<jleigh_>
ok
skammer3 has joined #ruby-lang
<jleigh_>
yes i need to be able to handle those situations
<jleigh_>
thats why i choose the for loop
<jleigh_>
i figured a double for loop would do the trick
<jhass>
jleigh_: well think about what your two loops do
<jhass>
they both iterate over the whole array, always
<jhass>
if we take havenwood last example array
<jleigh_>
yea
<jleigh_>
i was looking ofr something similar to the javascript for loop
<jhass>
your outer loop could be at -4 or example
<jhass>
and your inner loop would start at the first 5 again
skammer2 has quit [Ping timeout: 245 seconds]
<jleigh_>
right thats my issue
SqREL___________ has quit [Ping timeout: 244 seconds]
<jhass>
so for the iterative approach you should look at methods like Array#each_with_index (which increments the index for you, you don't need to do it) and Fixnum#upto
Blaguvest has quit [Ping timeout: 244 seconds]
<jleigh_>
i tried that also and got this error
<jleigh_>
nil can't be coerced into Fixnum (TypeError)
michaeldeol has joined #ruby-lang
<jleigh_>
ill show you my code for that try
<jhass>
well, we don't see try
<jhass>
so just that error message means nothing to us
<jhass>
* see your try
<jleigh_>
right...im going to put it on gist give me a second
<jhass>
but ignore that, let's understand why yours fails
<havenwood>
jhass: just playing around with variations
<havenwood>
jhass: i don't think that's along the lines of the type of solution being sought
michaeldeol has joined #ruby-lang
<havenwood>
just an aside, never mind me
<jleigh_>
so this is practive for an interview... i doubt ill be able to re do what havenwood just produced...i am trying to come up with something more digestable
seank_ has quit [Remote host closed the connection]
<jleigh_>
practice*
<havenwood>
jhass: i always forget about flat_map :)
seank_ has joined #ruby-lang
<jhass>
havenwood: kinda need to force myself to it too still ;)
<jleigh_>
flat map?
<jhass>
jleigh_: anyway, did you understand now that arr[i+1] will return nil in your last iteration since it's not a valid index?
<jleigh_>
im going to look that one up
<jleigh_>
yes
<jleigh_>
i just realize this
hellangel7 has quit [Ping timeout: 272 seconds]
<jleigh_>
so that means i need a while loop to check the length of the array
michaeldeol has quit [Client Quit]
<jleigh_>
or something of that nature
<jhass>
or you just use .upto to generate your induces since you don't really use the provided e anyway
<jhass>
*indices
<havenwood>
seems nice to return: [starting_index, size]
<jhass>
or however you spell that
<havenwood>
unless you really only care about the size
<havenwood>
err, sum
<jhass>
I think the assignment is pretty clearly about the sum
<havenwood>
guess i was thinking more general purpose, good point on assignment
<jleigh_>
ok so upto
<havenwood>
if it wants the sum it wants the sum
<jleigh_>
so since i dont use e...i can do each index
<jleigh_>
.each_index*
<jleigh_>
and then use .up to
<havenwood>
i want the slice!
<jleigh_>
.slice!
<jleigh_>
?
<jleigh_>
im kind of confused about how to use up to
<jhass>
yep, off by one, 0.upto(arr.size-1) do |i| 0.upto(arr.size-i-1) do |n| p i.upto(i+n) do |j| is right
<jhass>
(except for the extra p)
sarkyniin has quit [Quit: Quitte]
zz_dlu has joined #ruby-lang
<jleigh_>
so i am trying to replace arr[i+1] with the .upto method in some way
<jhass>
jleigh_: well, look at the problem, what do you need to compute? the sum over _what_ do you need? how do you get to that _what_?
GaelanAintAround has joined #ruby-lang
<jhass>
your both attempts have a problem: they start over at the beginning of the inner loop
emmesswhy has quit [Quit: This computer has gone to sleep]
<jleigh_>
right
<jhass>
that yields to series of idices like [3, 0, 1, 2, 3]
migbar has joined #ruby-lang
<jleigh_>
what do you mean by that
TheToad has quit [Read error: Connection reset by peer]
snsei has quit [Remote host closed the connection]
<jhass>
you don't actually do anything with the index of the inner loop, for each element you just add the element that comes after it arr.size times to it
<jleigh_>
ok....i got that
<jhass>
and if you would do something with the index of the inner loop, you would work with, for arr.size = 3, you would work with [0, 0, 1, 2], [1, 0, 1, 2], [2, 0, 1, 2]
nathanstitt has quit [Ping timeout: 260 seconds]
<jhass>
what you want is [0], [1], [2], [0, 1], [1, 2], [0, 1, 2]
danijoo has quit [Read error: Connection reset by peer]
michaeldeol has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<jhass>
my example uses the outer loop to compute the start index (i), the middle loop for the subarray length to look at (n) and the inner loop for the subarray indices into the actual array (j)
nathanstitt has joined #ruby-lang
<jleigh_>
i need [0,1,2] then [1, 2] then [2]
<jhass>
no more than that
havenwood has quit []
<jhass>
for example [-1, -2, 200, -3] should yield 200