jhass[m] changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.2, 3.0.4, 2.7.6: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
namkeleser has joined #ruby
comet23 has joined #ruby
<comet23> i'm looking for an experienced developer with teaching experience to donate their time and explain how to flatten an array recursively... i've been stuck on this problem for 3 days now... WILL PAY $$$
Joanna has joined #ruby
Joanna has left #ruby [#ruby]
Rounin has quit [Ping timeout: 256 seconds]
ttoh has joined #ruby
ttoh has quit [Ping timeout: 252 seconds]
namkeleser has quit [Quit: Client closed]
<weaksauce> what have you tried comet23
<comet23> i have tried combining recursion with iteration and recursion on its own as well
<havenwood> comet23: You tried Array#flatten already?
<comet23> no i can't do that
<havenwood> It just works, out of the box.
<comet23> i'm supposed to reinvent the wheel here
<weaksauce> i'm sure this is a school assignment
<comet23> kind of
<weaksauce> gist some code that you've tried
<havenwood> Ah, got it.
<weaksauce> how familiar are you with recursion?
<comet23> it's not an official school assignment as i'm not getting graded for it it's a free online course called app academy open
Ziyan has joined #ruby
<weaksauce> so the general thing you always want to know before tackling a recursive problem is what your base case will be
<comet23> weaksauce i'm familiar with the main idea and i think i understand how the values are stored... basically it stores a copy of a function with values that are to be executed only after the base case is ran?
<weaksauce> basically more or less
<comet23> what am i missing?
<weaksauce> nothing really other than some details but that's the gist of it
<comet23> i know the stack has a finite number of functions it can store before raising an error
<weaksauce> yeah ... probably better to think of them as stack frames but that's a bit more in the weeds
<weaksauce> but yeah a function that has a value passed into it
<havenwood> comet23: By default, yeah, but you can enable TCO if you really need to.
<weaksauce> what do you think the base case should return comet23
<comet23> i was getting a nil error when i was calling it recursively so... if argument.nil?
<comet23> return argument if argument.nil?
<comet23> data in this case
<weaksauce> would it make more sense to return an array at all times and then merge that
<weaksauce> nil is a smell
<weaksauce> what happens when you add an array with an empty array?
<comet23> i've never done that and never thought of a reason to do that... let me try
<comet23> a = [], b = [] a + b => []
<comet23> that's what irb told me
<weaksauce> and what happens when you do [1] + []
<comet23> i did p a + b
<weaksauce> or [1,2,3] + [4,5]
<comet23> how do you know this works like that?
<comet23> i would have never in a million years found this out
<weaksauce> i've programmed ruby for years :)
<weaksauce> also reading the docs on the basic fundamental data structures is essential really
<weaksauce> array, hash, enumerable are all foundational
<comet23> i did but the problem i have with reading the docs is the language is very hard for me to understand
<comet23> the way the things are written in there
<weaksauce> that's fair
<weaksauce> it's written for a familiar audience
<weaksauce> anyway if you always return an array the problem gets a bit easier
<weaksauce> since addition on arrays is well defined
<weaksauce> i find that any time you can avoid nil it's a good idea
<weaksauce> comet23 can you gist what you've tried?
<weaksauce> i don't like to just give answers as it's not really conductive to learning
<weaksauce> but the solution is only maybe 10 lines or so
<comet23> i don't want answers unless it's an answer to actually understanding something
shiru has joined #ruby
<weaksauce> try to get recursive flatten to work on those inputs as a basic test
<comet23> i have no idea what any of that is supposed to mean but all i see are return values of how the thing is supposed to work
<comet23> i wish i could look at that and think of an implementation right away
<weaksauce> what I like to do is have a base case, then build up the return value and then return that value
<weaksauce> you have to differentiate the array case and the value case
<comet23> so does that mean two separate base cases or an if statement that checks each value?
<weaksauce> you only have one base case
<weaksauce> the base case short circuits (generally)
<comet23> what if you pass in "hello" as the argument
<weaksauce> it'd crash work
<weaksauce> er s/crash//
<comet23> crash work?
<weaksauce> it depends on how you want to handle it
<comet23> one of the test cases passes in a string
<comet23> i'm going to work on it and be back later thank you so much again :)
<weaksauce> another thing to do is munge the data at the beginning of the call into a format you are prepared to use...
<weaksauce> so if you are passed a string instead of an array might as well convert it into an array of one item
<weaksauce> or do whatever the API says to do
<weaksauce> if that's an error or if that's return nil or whatever that's a design decision
<comet23> that sounds complicated to me because i have no idea how to implement that in code
<weaksauce> well case statements and respond_to? are useful tools for that
<weaksauce> many ways to do it though
<weaksauce> there's also is_a?
comet23 has quit [Quit: Client closed]
Al2O3 has joined #ruby
Al2O3 has quit [Client Quit]
Al2O3 has joined #ruby
Al2O3 has quit [Quit: I'm quitting, thanks for all the sharks.]
Al2O3 has joined #ruby
Al2O3 has joined #ruby
Al2O3 has quit [Changing host]
oxfuxxx has joined #ruby
Al2O3 has quit [Quit: I'm quitting, thanks for all the sharks.]
Al2O3_ has joined #ruby
Al2O3_ has quit [Remote host closed the connection]
Al2O3 has joined #ruby
oxfuxxx has quit [Read error: Connection reset by peer]
John_Ivan__ has quit [Ping timeout: 256 seconds]
teclator has joined #ruby
teclator has quit [Client Quit]
shiru has quit [Quit: Lost terminal]
reset has quit [Quit: reset]
dionysus69 has joined #ruby
comet23 has joined #ruby
<comet23> i know you guys said to not use .nil? for a base case but it's the only thing that makes sense in my head and my code isn't working but this is the closest i've gotten to any intelligible solution:/  https://bpa.st/JQBQ
<comet23> here's the code with the test case it tests for: https://bpa.st/55GQ
protektwar_ has joined #ruby
protektwar_ has joined #ruby
protektwar_ has quit [Changing host]
protektwar_ has quit [Client Quit]
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
comet23 has quit [Quit: Client closed]
Vonter has quit [Ping timeout: 276 seconds]
libsys has quit [Ping timeout: 246 seconds]
libsys has joined #ruby
Rounin has joined #ruby
Vonter has joined #ruby
dionysus69 has quit [Ping timeout: 276 seconds]
Vonter has quit [Ping timeout: 240 seconds]
Rounin has quit [Ping timeout: 272 seconds]
Vonter has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 272 seconds]
ssh073 has quit [Ping timeout: 240 seconds]
donofrio__ has joined #ruby
donofrio_ has quit [Ping timeout: 276 seconds]
oxfuxxx has joined #ruby
<oxfuxxx> hoi
oxfuxxx has quit [Ping timeout: 240 seconds]
oxfuxxx has joined #ruby
Glue has quit [Ping timeout: 252 seconds]
Al2O3 has quit [Quit: I'm quitting, thanks for all the sharks.]
_ht has joined #ruby
dionysus69 has joined #ruby
noname has joined #ruby
Vonter has quit [Ping timeout: 256 seconds]
Vonter has joined #ruby
Ziyan has quit [Ping timeout: 256 seconds]
Ziyan has joined #ruby
roadie has joined #ruby
Ziyan has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
Ziyan has joined #ruby
gr33n7007h has joined #ruby
noname has quit [Quit: Leaving]
Thanzex has quit [Read error: Connection reset by peer]
Thanzex has joined #ruby
Ziyan has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
John_Ivan__ has joined #ruby
oxfuxxx has quit [Quit: [H]EAT ROX FUCK R0X SHIT BRIX. = The Yankies M0th3Rphackers Coconut Aerospace =]
oxfuxxx has joined #ruby
oxfuxxx has quit [Remote host closed the connection]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 256 seconds]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 246 seconds]
Rounin has joined #ruby
Tempesta has quit [Quit: See ya!]
Hck has joined #ruby
Tempesta has joined #ruby
Hck has quit [Quit: WeeChat 3.6-dev]
favadi has joined #ruby
reset has joined #ruby
oxfuxxx has joined #ruby
donofrio__ has quit [Quit: Leaving]
donofrio__ has joined #ruby
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
<ox1eef> havenwood: oh interesting, especially that IRB::Abort part. I've been having troubles with that.
oxfuxxx has quit [Ping timeout: 256 seconds]
Glue has joined #ruby
oxfuxxx has joined #ruby
TCZ has joined #ruby
TCZ is now known as twosuns
Ziyan has joined #ruby
___nick___ has joined #ruby
niv has quit [Ping timeout: 240 seconds]
brw has quit [Read error: Connection reset by peer]
brw has joined #ruby
favadi has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gr33n7007h has quit [Ping timeout: 246 seconds]
gr33n7007h has joined #ruby
niv has joined #ruby
hololeap has joined #ruby
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
___nick___ has joined #ruby
oxfuxxx has quit [Ping timeout: 276 seconds]
AndreYuh1i has joined #ruby
AndreYuh1i has quit [Ping timeout: 256 seconds]
twosuns has quit [Quit: ...]
brw has quit [Quit: The Lounge - https://thelounge.chat]
brw has joined #ruby
mixfix41 has joined #ruby
lena64t has joined #ruby
roadie has quit [Ping timeout: 248 seconds]
gr33n7007h has quit [Ping timeout: 256 seconds]
gramps has joined #ruby
protektwar has quit [Ping timeout: 240 seconds]
moldorcoder7_ has joined #ruby
moldorcoder7 has quit [Ping timeout: 246 seconds]
brw has quit [Quit: The Lounge - https://thelounge.chat]
brw has joined #ruby
moldorcoder7_ has quit [Quit: %bye mirc%]
moldorcoder7 has joined #ruby
danjo0 has quit [Quit: danjo0]
roadie has joined #ruby
danjo00 has joined #ruby
roadie has quit [Ping timeout: 248 seconds]
gr33n7007h has joined #ruby
roadie has joined #ruby
oxfuxxx has joined #ruby
moldorcoder7 has quit [Ping timeout: 240 seconds]
moldorcoder7 has joined #ruby
Ziyan has quit [Quit: Textual IRC Client: www.textualapp.com]
danjo00 has quit [Quit: danjo00]
_ht has quit [Remote host closed the connection]
danjo00 has joined #ruby
some14u has joined #ruby
___nick___ has quit [Ping timeout: 272 seconds]
<havenwood> ox1eef: Here's another one with Enumerable rather than Enumerator, but I *really* don't like the `nil.instance_eval` hack necessary for Ractors since 3.1.
<havenwood> I really look forward to a sane way to use an existing Proc with Ractors. I didn't mind `self` not being frozen but get why they disabled it until there's a fix. :(
<havenwood> I need to make a nicer interface, but I think it'll be nice to have async and parallel enumerables. Maybe an Enumerator chain would be nicer? Yeah, need a better interface.
AndreYuhai has joined #ruby
<ox1eef> havenwood: i'm having this issue with irb, where when i run a trace using a project of mine (trip.rb), the last event apparently causes a hang. outside the scope of irb, it doesnt happen. i wonder could IRB::Abort be related? threads are included in this, where the trace happens on a new thread that's yielding control back and forth with the main (irb) thread. do you think IRB::Abort could be
<ox1eef> involved?
<ox1eef> very interesting code you pasted, seems cool
<ox1eef> youre the only person i know who uses refinements
<havenwood> ox1eef: Haha
<havenwood> ox1eef: Hem, unsure. Maybe try `gem install tracer` and `context.use_tracer = true` in IRB to debug?
AndreYuhai has quit [Ping timeout: 276 seconds]
oxfuxxx has quit [Ping timeout: 276 seconds]
<ox1eef> i might end up trying that, i havent dug deep yet, it might reveal itself in the internals of the lib too
<havenwood> ox1eef: I'm curious what the issue is but yeah, maybe involved?
<ox1eef> my thought was maybe the thread is getting some type of interrupt, wild guess though
<havenwood> ox1eef: I saw ioquatix was working on Fiber stuff with IRB to support Async. Yeah, that seems like a reasonable guess though.
<ox1eef> cool
<ox1eef> damnit, ive lost my reproduction case
<havenwood> bug solved!
<havenwood> :P
<ox1eef> i wish
<ox1eef> thats why delaying things to later is not a good idea
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
hololeap has quit [Ping timeout: 240 seconds]
hololeap has joined #ruby
danjo00 has quit [Quit: danjo00]
danjo00 has joined #ruby
hololeap has quit [Ping timeout: 240 seconds]
hololeap has joined #ruby
some14u has joined #ruby
comet23 has joined #ruby
<weaksauce> comet23 that code doesn't seem to work for me
<comet23> hi
<comet23> yeah the code doesn't work but the idea logically makes sense somewhat i think no?
<weaksauce> maybe write out your algorithm in english first
hololeap has quit [Ping timeout: 240 seconds]
hololeap has joined #ruby
<comet23> weaksauce how does this look? https://bpa.st/M3GQ
<weaksauce> looks good
<weaksauce> i'd add at the top something about munging the data into a form you want and something about a base case
<weaksauce> so now that you have those comments write each stage of the implementation under the description of it
crundar has joined #ruby
<comet23> i get the idea and the implementation but i have an impossible time writing code for this =(
<comet23> my logic doesn't work the way i indend it
<comet23> intend*
<weaksauce> the way you wrote the code is very confusing so maybe that's why it's giving you a hard time
<weaksauce> how do you go through an array one element at a time
<weaksauce> focus on that first
<weaksauce> what happens if you go through an empty array?
<comet23> i'm also very confused by my own code
<comet23> what i tried initially didn't work so i kept redoing it
<comet23> now i forgot what i wrote initially
<weaksauce> try it again in a new method but with those comments in there
<weaksauce> and fill it out one part at a time
<weaksauce> write it so that it does the stupid thing
<weaksauce> like taking an input array or element and returning an array with just that element in it or the original array
<weaksauce> but build up the original array as a new array and don't return the old one
<weaksauce> and only then should you try to do the recursion
trillp has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 276 seconds]
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
comet23 has quit [Ping timeout: 252 seconds]
trillp has left #ruby [Leaving]
some14u has joined #ruby
some14u has quit [Client Quit]
brw has quit [Quit: The Lounge - https://thelounge.chat]
brw has joined #ruby
brw has quit [Client Quit]
brw has joined #ruby
fowl has quit [Quit: cya pals]
fowl has joined #ruby
fowl has quit [Client Quit]
fowl has joined #ruby
dionysus69 has quit [Ping timeout: 246 seconds]
Al2O3 has joined #ruby
jpn has joined #ruby
lena64t has quit [Remote host closed the connection]
AEtherC0r3 has quit [Remote host closed the connection]
AEtherC0r3 has joined #ruby
Guest82 has joined #ruby