havenwood changed the topic of #ruby to: Rules & more: https://ruby-community.com | Ruby 2.6.0, 2.5.3, 2.4.5: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.de/ and select Ruby as the language | Rails questions? Ask in #RubyOnRails | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | Can't talk? Register/identify with Nickserv first!
al2o3-cr has joined #ruby
laaron- has joined #ruby
ellcs has quit [Ping timeout: 264 seconds]
comet23 has joined #ruby
<comet23> where can we submit new language features ideas?
cschneid has joined #ruby
laaron has quit [Remote host closed the connection]
garyserj_ has joined #ruby
<comet23> thank you :D
<comet23> we need an unshift operator!
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<phaul> what would it do and how would it look like?
tdy has quit [Read error: error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac]
<al2o3-cr> &>> class Array; def >>(val) unshift val end end; [1,2,3] >> :foo
<rubydoc> # => [:foo, 1, 2, 3] (https://carc.in/#/r/5vr9)
<al2o3-cr> i like that.
nchambers has quit [Quit: WeeChat 2.2]
<phaul> hi al2o3-cr
<al2o3-cr> hi phaul ;)
<phaul> check this out:
<phaul> &ri RubyVM
<al2o3-cr> nice!
<phaul> though the eval is still on 2.5, I need carc.in to be updated first
cschneid has quit [Ping timeout: 268 seconds]
<phaul> also I *think* it will require actual changes even if small ones, as dissass, ast APIs have changed
<al2o3-cr> phaul: yes, minor changes i think.
NightMonkey has quit [Ping timeout: 246 seconds]
<al2o3-cr> &ri Proc#>>
NightMonkey has joined #ruby
<al2o3-cr> i'm sure jhass will update asap.
<catphish> is the behaviour of modifying an array while iterating over it defined?
<catphish> looks like i should probably use Array#delete_if to iterate and allow me to delete items at the same time
hutch has joined #ruby
connermcd has quit [Quit: WeeChat 2.3]
venmx has quit [Ping timeout: 244 seconds]
dviola has quit [Quit: WeeChat 2.3]
houhoulis has quit [Remote host closed the connection]
<comet23> yeah the unshift operator will look like >>
<comet23> because the shift operator looks like <<
<phaul> well, the language has an unshift operator then.
<phaul> even though here they claim it's binary shift, really many types implement >> in a way that has nothing to do with bit shifting
bmurt has joined #ruby
hutch has quit [Ping timeout: 250 seconds]
spacesuitdiver has joined #ruby
nowhere_man has quit [Ping timeout: 252 seconds]
bmurt has quit [Client Quit]
d10n-work has joined #ruby
blackmesa1 has joined #ruby
GodFather has quit [Ping timeout: 244 seconds]
sameerynho has quit [Ping timeout: 240 seconds]
tag has quit [Quit: Connection closed for inactivity]
blackmesa1 has quit [Ping timeout: 252 seconds]
blackmesa1 has joined #ruby
garyserj_ has quit [Quit: garyserj_]
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
blackmesa1 has quit [Ping timeout: 252 seconds]
Averna has joined #ruby
segy has quit [Ping timeout: 272 seconds]
blackmesa1 has joined #ruby
segy has joined #ruby
cd has quit [Remote host closed the connection]
ellcs has joined #ruby
blackmesa1 has quit [Ping timeout: 260 seconds]
blackmesa1 has joined #ruby
Nicmavr has quit [Read error: Connection reset by peer]
RougeR has quit [Ping timeout: 245 seconds]
ellcs has quit [Ping timeout: 260 seconds]
Nicmavr has joined #ruby
jordanm has quit [Ping timeout: 240 seconds]
jordanm has joined #ruby
s3nd1v0g1us has quit [Quit: WeeChat 2.2]
cschneid has joined #ruby
blackmesa1 has quit [Ping timeout: 252 seconds]
tdy has joined #ruby
garyserj_ has joined #ruby
laaron- has joined #ruby
laaron has quit [Remote host closed the connection]
code_zombie has joined #ruby
tdy has quit [Ping timeout: 245 seconds]
nchambers has joined #ruby
nchambers is now known as uplime
BTRE has quit [Remote host closed the connection]
BTRE has joined #ruby
<comet23> So if it has it then why is it not able to be implemented for arrays?
cschneid has quit [Ping timeout: 245 seconds]
patteh has quit [Ping timeout: 250 seconds]
nowhere_man has joined #ruby
patteh has joined #ruby
jottr has quit [Ping timeout: 244 seconds]
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
tdy has joined #ruby
Swyper has joined #ruby
patteh has quit [Ping timeout: 268 seconds]
<Swyper> Can someone help me figure out why my tests are failing ?
patteh has joined #ruby
patteh has quit [Ping timeout: 268 seconds]
<comet23> Swyper: what exercises are you doing?
cschneid has joined #ruby
uplime has quit [Ping timeout: 250 seconds]
Swyper has quit [Ping timeout: 256 seconds]
jottr has joined #ruby
hutch has joined #ruby
jottr has quit [Ping timeout: 240 seconds]
<leftylink> too bad
<leftylink> I guess I can still help by commenting on the gist, but apparently that requires a github acct
Swyper has joined #ruby
hiroaki has quit [Ping timeout: 246 seconds]
<Swyper> hi, not sure who was talking to me before but I'm doing practice questions from App Academy
<Swyper> comet23 and leftylink , just looked through logs and it was you two :)
<leftylink> notice that 1: your `ordered_vowel_word?` requires that the word contains all vowels, which the tests do *not* require. 2: "i before e" is a spelling rule not an alphabet order rule
<Swyper> https://dpaste.de/ktM9 if you prefer it on dpaste
<Swyper> 1) Yeah you are right.. I have to think of a way to check for all combinations of vowels in order I guess I could do this with a bunch of OR statements
<Swyper> 2) oh, so it should be AEIOU ?
<Swyper> for 1) I'm thinking there has to be a more efficient way to do this then to pile up a a few OR statements
<Swyper> is there a way to check if a string is a subset of another string ?
<Swyper> way = method in ruby :P
<leftylink> &>> p ["asdf".include?("a"), "asdf".include?("b")]
<rubydoc> # => [true, false] ...check link for more (https://carc.in/#/r/5vt8)
<leftylink> but I think I have misunderstood your question
<leftylink> &>> p ["asdf".include?("as"), "asdf".include?("ad")]
<rubydoc> # => [true, false] ...check link for more (https://carc.in/#/r/5vt9)
cschneid has quit [Ping timeout: 246 seconds]
uplime has joined #ruby
<Swyper> https://dpaste.de/19ox leftylink
<Swyper> ignore the first one it pasted way to much ;x
<Swyper> expected: ["word", "pale", "word", "random", "pry"] got: ["word", "pale", "word", "pry"], why should random even be returned it skips e and i o-o
<leftylink> because: of the vowels that appear (a, o), they are in order.
<leftylink> there is no requirement that any particular vowel must appear
<leftylink> only a requirement on the vowels that do appear
laaron- has joined #ruby
<Swyper> hmm
<Swyper> # Define a method that accepts an array of words and returns an array of those # words whose vowels appear in order. You may wish to write a helper method: # ordered_vowel_word?
<Swyper> it does say in order in the comments they gave o-o
<leftylink> sure
<leftylink> random's vowels (a, o) appear in order
<leftylink> okra's vowels (o, a) don't
laaron has quit [Remote host closed the connection]
<Swyper> So where my confusion is that to me in order would mean a, e, i ,o, u and a word that skips one of those is not in order, and I'm obviously understanding it wrong but what does in order even mean, then ?
<leftylink> "a word that skips one of those is not in order" - that would be the case if the question asked "the word must contain all the vowels in order"
braincrash has quit [Quit: bye bye]
<leftylink> instead, the question asks "the words vowels must be in order", therefore it only applies to whichever vowels happen to be in the word
<Swyper> okay that makes sense
<Swyper> so my include statement at the moment is not good enough, any ideas on how to improve it to pass the test cases?
<Swyper> or function as it should instead of just pass test cases xD
* baweaver wanders in
masterasia has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
braincrash has joined #ruby
<Swyper> feel free to give me any suggestions :P
<Swyper> I could be lame and just pass the test causes by adding ao to the end of the string but that would lame
<Swyper> *be lame
<leftylink> well, a lot of the time my process is "how would I do it with pen and paper" and translate that to code. by the by, what *would* be your approach, if you were to be asked to do it with pen and paper?
<Swyper> I guess broke the vowels up into an array, find the index of the array where the first element of the string we are evaluating (the vowels we parsed from the string) appears, discard all elements in the array of vowels prior to where the index was and return false if there is ever a vowel that cannot be found in the array
<Swyper> though I wrote pretty messy so what I wrote above might be hard to follow ^
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<al2o3-cr> &>> "random".scan(/[aeiou]/)
<rubydoc> # => ["a", "o"] (https://carc.in/#/r/5vtd)
<Swyper> "random".scan(/[aeiou]/), /[aeiou]/ is regex ?
<al2o3-cr> Swyper: yes.
<al2o3-cr> &>> "random".scan(/[aeiou]/).tap { |vowels| break vowels == vowels.sort }
<rubydoc> # => true (https://carc.in/#/r/5vte)
<Swyper> interesting
masterasia has joined #ruby
jottr has joined #ruby
<Swyper> is there an answer that does not involve regex ? one approach could be to have a bunch of messy if statements nested inside one another
hutch has quit [Ping timeout: 240 seconds]
jottr has quit [Ping timeout: 250 seconds]
<leftylink> your current approach splits the problem into two parts: 1) get the list of vowels of a word. 2) is this list in order?. your approach to 1 was already working, regardless of whether it uses regex. you were needing to find a way to do part 2. a possible way to do part 2 has now been revealed above, which you can combine with your way to do part 1 if you want.
<leftylink> or, you can come up with your own way to do part 2 if you want
<leftylink> in which case, we ask "how do we figure out whether a list of things is in order?"
<leftylink> the approach you described, if I understood it correctly, does work. you are free to use it or any other way you devise or find
kapil____ has joined #ruby
r29v has joined #ruby
r29v has quit [Ping timeout: 240 seconds]
Swyper has quit [Quit: Page closed]
hutch has joined #ruby
<havenwood> Swyper: A nit, but it's a bit nicer to use `%w[a e i o u]` instead of `"a i e o u".split` for the same result faster with less memory. In your case it doesn't matter but just mentioning.
<havenwood> Ah, they left. Was gunna suggest they take a look at #each_cons.
<leftylink> shame
<leftylink> (the leaving, I mean)
AJA4350 has quit [Quit: AJA4350]
ogres has joined #ruby
ur5us has quit [Remote host closed the connection]
hutch has quit [Ping timeout: 268 seconds]
d10n-work has quit [Quit: Connection closed for inactivity]
lytol has joined #ruby
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
davidw_ has quit [Ping timeout: 244 seconds]
<comet23> what is ruby 3 going to be like?
* al2o3-cr gets out his crystal ball...
masterasia has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
davidw_ has joined #ruby
rawrg has joined #ruby
davidw_ has quit [Ping timeout: 246 seconds]
patteh has joined #ruby
<al2o3-cr> for Swyper's next one: Array#reverse, Array#combination, Integer#pred, Enumerable#map and Enumerable#inject
patteh has quit [Ping timeout: 250 seconds]
Swyper has joined #ruby
<Swyper> hi
<Swyper> def array_product(array, i) counter = 0 array.map = { |int| counter *= int } end
<Swyper> array.map = { |int| int *= counter }is causing me a syntax error any idea why ?
<havenwood> Swyper: get rid of the equal sign in `.map = {`
<havenwood> Swyper: `.map { |int|` instead of `.map = { |int|`
<Swyper> ah okay
<Swyper> thank you
<Swyper> its returning [0,0,0,0] atm >_>
<baweaver> What happens when you multiply a number by 0?
<baweaver> Also map is the wrong function for this.
<havenwood> &>> require 'prime'; (0..).lazy.select { |n| n.prime? && (n * 9 + 4).prime? }.map { |n| (n + 94).chr }.first 5
<rubydoc> # => (https://carc.in/#/r/5vty)
<havenwood> oh, right - no 2.6 yet :)
<havenwood> &>> require 'prime'; 1.step.lazy.select { |n| n.prime? && (n * 9 + 4).prime? }.map { |n| (n + 94).chr }.first 5
<rubydoc> # => ["a", "e", "i", "o", "u"] (https://carc.in/#/r/5vtz)
<baweaver> wat
<baweaver> How did you find that one?
<havenwood> baweaver: an earlier question was about vowels, and I thought there *must* be a good way to find vowels. >.>
<baweaver> ....how did you figure that out?
<baweaver> They're just conveniently spaced?
<Swyper> return (order_of_vowels.sort.join == order_of_vowels.join)
<Swyper> just compared the sorted vowels with the actual vowels, I can post the whole solution if your curious
<baweaver> duplicates
Menteb has joined #ruby
<havenwood> baweaver: i found an OEIS sequence that matched an offset of the bytes >.>
<baweaver> Interesting.
<Swyper> sort removes duplicates ?
<Swyper> ^ solution
rawrg has quit [Ping timeout: 240 seconds]
<havenwood> baweaver: this is actually the one I wanted to implement, since it aligns with the position of the vowels in the alphabet - but I couldn't figure out what the heck the `a(n)-a(n-1)` part is meant to be.
<havenwood> baweaver: https://oeis.org/A161536
laaron- has joined #ruby
<havenwood> It's not the previous binary palindrome or the previous index, so... what is it?
laaron has quit [Remote host closed the connection]
<Swyper> Also sorry I left midway, I use webchat to connect since everything else for mac costs money (textual) or is outdated or to technical for me to use :P
<havenwood> Swyper: LimeChat is the open source project that Textual is based off of: https://github.com/psychs/limechat
<havenwood> Swyper: Or you can build Textual yourself with Xcode: https://github.com/Codeux-Software/Textual
<Swyper> oh thank you
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
<havenwood> Swyper: You can catch up on what you miss with the logs: https://irclog.whitequark.org/ruby
spacesuitdiver has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood> Swyper: Many of us use a bouncer like ZNC to replay history to our IRC client for what we missed.
Swyper has quit [Quit: Page closed]
spacesuitdiver has joined #ruby
Swyper has joined #ruby
<Swyper> yay I'm on through limechat now, thanks
<havenwood> nice, you're welcome
<havenwood> Swyper: Just showing you that ^ for the #each_cons bit on line 6. (Ignore the silly way to find the vowels.)
<Swyper> neat thank you
<havenwood> Swyper: It's a handy way to compare each element to the next.
Menteb has quit [Quit: Menteb]
Swyper has quit [Remote host closed the connection]
Swyper has joined #ruby
<leftylink> Swyper: sort does not remove duplicates
rippa has joined #ruby
<leftylink> &>> [1, 1].sort
<rubydoc> # => [1, 1] (https://carc.in/#/r/5vu0)
akosednar has quit [Ping timeout: 268 seconds]
<Swyper> ah okay
akosednar has joined #ruby
cschneid has joined #ruby
<al2o3-cr> so a(n) = smallest integer > a(n-1) that is an odd palindome when written in base 2
<al2o3-cr> i'm struggling with this, i'll tell thee.
aupadhye has joined #ruby
hutch has joined #ruby
<al2o3-cr> i think i've got it.
armyriad has quit [Ping timeout: 250 seconds]
Averna has quit [Ping timeout: 250 seconds]
_whitelogger has joined #ruby
m0w has quit [Ping timeout: 268 seconds]
cschneid has quit [Ping timeout: 245 seconds]
laaron- has joined #ruby
laaron has quit [Remote host closed the connection]
Menteb has joined #ruby
<uplime> if i have a function (foo(**opts)), is there a way to pass another hash (ie foo **bar), but have it retain the changes afterwards?
<uplime> i could return the updated one, but i'm already returning an array so i thought i'd check
tdy has quit [Ping timeout: 240 seconds]
Swyper has quit [Remote host closed the connection]
hutch has quit [Ping timeout: 272 seconds]
Swyper has joined #ruby
tiff has joined #ruby
Swyper has quit [Ping timeout: 250 seconds]
_whitelogger has joined #ruby
ogres has quit [Quit: Connection closed for inactivity]
Zarthus is now known as updime
updime is now known as uprime
uprime is now known as upmime
Menteb has quit [Quit: Menteb]
upmime is now known as up|ime
Menteb has joined #ruby
raulp has quit [Read error: Connection reset by peer]
raulp has joined #ruby
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
patteh has joined #ruby
DTZUZO has quit [Ping timeout: 240 seconds]
reber has joined #ruby
Menteb has quit [Remote host closed the connection]
patteh has quit [Ping timeout: 272 seconds]
gitness has left #ruby [#ruby]
_whitelogger has joined #ruby
jottr has joined #ruby
dellavg_ has joined #ruby
cschneid has joined #ruby
_whitelogger has joined #ruby
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
gix has joined #ruby
hiroaki has joined #ruby
cnsvc has joined #ruby
cnsvc has quit [Ping timeout: 256 seconds]
idiocrash has joined #ruby
cschneid has quit [Ping timeout: 240 seconds]
masterasia has joined #ruby
jottr has quit [Ping timeout: 245 seconds]
DTZUZO has joined #ruby
laaron- has joined #ruby
exchgr has quit [Ping timeout: 252 seconds]
laaron has quit [Remote host closed the connection]
exchgr` has joined #ruby
lxsameer has joined #ruby
sandelius has joined #ruby
comet23 has quit [Quit: Connection closed for inactivity]
towo has joined #ruby
blackmesa1 has joined #ruby
havenwood has quit [Quit: ZNC 1.7.1 - https://znc.in]
za1b1tsu has joined #ruby
cpallares has quit [Ping timeout: 246 seconds]
<towo> Hey, I'm trying to use Net::SSH::Authentication::Agent to sign something, but when passing the key (for the public key) argument, it apparently expects an OpenSSL::PKey::RSA or similar object. I'm not seeing any way of actually saying "read this string as a public key" anywhere in the whole module. Any hints on how to generate that without reimplementing half the module?
havenwood has joined #ruby
cpallares has joined #ruby
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
conta has joined #ruby
roshanavand has joined #ruby
za1b1tsu has quit [Remote host closed the connection]
code_zombie has quit [Quit: Leaving]
cschneid has joined #ruby
sandelius has quit [Quit: Textual IRC Client: www.textualapp.com]
sidepocket has joined #ruby
thinkpad has quit [Ping timeout: 246 seconds]
thinkpad has joined #ruby
roshanavand has quit [Quit: Gone planting!]
vutral1 has joined #ruby
blackmesa1 has quit [Ping timeout: 250 seconds]
dviola has joined #ruby
reber has quit [Remote host closed the connection]
cschneid has quit [Ping timeout: 250 seconds]
laaron- has joined #ruby
laaron has quit [Remote host closed the connection]
m0w has joined #ruby
AJA4350 has joined #ruby
Nicmavr has quit [Read error: Connection reset by peer]
Nicmavr has joined #ruby
patteh has joined #ruby
clemens3 has quit [Ping timeout: 245 seconds]
sandelius has joined #ruby
jottr has joined #ruby
<sandelius> Happy New Year's Eve everyone
szulak_ has joined #ruby
exchgr has joined #ruby
exchgr` has quit [Ping timeout: 252 seconds]
cschneid has joined #ruby
cschneid has quit [Remote host closed the connection]
cschneid has joined #ruby
cschneid has quit [Ping timeout: 250 seconds]
_whitelogger has joined #ruby
garyserj_ has quit [Ping timeout: 272 seconds]
cschneid has joined #ruby
cschneid has quit [Remote host closed the connection]
despai has joined #ruby
dviola has quit [Ping timeout: 245 seconds]
Azure has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
GodFather has joined #ruby
catphish has left #ruby ["Leaving"]
agent_white has joined #ruby
n01 has joined #ruby
m0w has quit [Ping timeout: 246 seconds]
laaron- has quit [Remote host closed the connection]
szulak_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mostlybadfly has joined #ruby
laaron has joined #ruby
jgpawletko has quit [Ping timeout: 245 seconds]
jgpawletko has joined #ruby
MyMind has joined #ruby
Sembei has quit [Ping timeout: 246 seconds]
vutral1 has quit [Ping timeout: 252 seconds]
polishdub has joined #ruby
n01 has quit [Read error: Connection reset by peer]
m0w has joined #ruby
ellcs has joined #ruby
masterasia has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
laaron has quit [Remote host closed the connection]
blackmesa1 has joined #ruby
laaron has joined #ruby
uplime has quit [Ping timeout: 272 seconds]
aupadhye has quit [Quit: Leaving]
blackmesa1 has quit [Quit: WeeChat 2.3]
d^sh has quit [Ping timeout: 244 seconds]
d^sh has joined #ruby
sandelius has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Rapture has joined #ruby
DTZUZO has quit [Ping timeout: 245 seconds]
GodFather has quit [Ping timeout: 268 seconds]
mikecmpbll has joined #ruby
despai has quit [Quit: ...]
d10n-work has joined #ruby
szulak_ has joined #ruby
GodFather has joined #ruby
jthomas1 has joined #ruby
davidw_ has joined #ruby
Renich has joined #ruby
DTZUZO has joined #ruby
jthomas2 has joined #ruby
jthomas1 has quit [Ping timeout: 268 seconds]
mostlybadfly has quit [Quit: Connection closed for inactivity]
armyriad has joined #ruby
donofrio has joined #ruby
Aqo has joined #ruby
GodFather has quit [Ping timeout: 244 seconds]
donofrio has quit [Ping timeout: 240 seconds]
armyriad has quit [Ping timeout: 250 seconds]
Dbugger has joined #ruby
GodFather has joined #ruby
armyriad has joined #ruby
Dbugger has quit [Remote host closed the connection]
mostlybadfly has joined #ruby
szulak_ has quit [Quit: Textual IRC Client: www.textualapp.com]
Mike11 has joined #ruby
idiocrash has quit [Read error: Connection reset by peer]
dviola has joined #ruby
donofrio has joined #ruby
masterasia has joined #ruby
masterasia has quit [Client Quit]
laaron- has joined #ruby
laaron has quit [Remote host closed the connection]
kapil____ has quit [Quit: Connection closed for inactivity]
donofrio has quit [Ping timeout: 246 seconds]
despai has joined #ruby
masterasia has joined #ruby
ellcs has quit [Ping timeout: 250 seconds]
Swyper has joined #ruby
<Swyper> hi
<Swyper> expected: [24, 12, 8, 6]
<Swyper> got: [24, 288, 27648, 191102976]
<baweaver> Swyper: lead with the problem description
cthulchu has joined #ruby
<Swyper> baweaver ?
<Swyper> on the gist it leads with the description :P
GodFather has quit [Ping timeout: 245 seconds]
<Swyper> https://dpaste.de/QwDJ - dpaste
<baweaver> line 6 doesn't actually make a new list.
<Swyper> oh it just points to the old one? >_>
<Swyper> how do I make a deep copy of that list then ?
<baweaver> You don't need one.
<baweaver> numbers.map instead
masterasia has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<baweaver> Though you could use map.with_index to get the index, which you probably need for this anyways.
despai has quit [Quit: ...]
<leftylink> doable w/o index, but I guess it depends on how one wants to think about it
<baweaver> True.
hiroaki has quit [Ping timeout: 250 seconds]
<baweaver> One could just invert that singular number considering how multiplication works.
<baweaver> Commutative property wasn't it?
<baweaver> yep
sameerynho has joined #ruby
<baweaver> a * b * c == c * b * a
<baweaver> which could be done in any order.
hutch has joined #ruby
<baweaver> Swyper: If I add one to a number, how would I undo that?
<Swyper> https://dpaste.de/TsyX - got it working
<Swyper> that's what I'm doing, using commutative property multiplying everything out and then dividing it by whatever number was not supposed to be included in the multiplication
<baweaver> True, but that's not the business of the array_product function
<baweaver> the name becomes a lie by doing that.
<baweaver> That, and you want to likely use sum or reduce instead for getting a product.
lxsameer has quit [Ping timeout: 246 seconds]
GodFather has joined #ruby
<baweaver> well, reduce.
<Swyper> True, do you want to show me how it would work using reduce instead of what I'm using now ?
<baweaver> &>> [1, 2, 3].reduce(1) { |accumulator, v| accumulator * v }
<rubydoc> # => 6 (https://carc.in/#/r/5vzg)
<Swyper> neato
<baweaver> &>> [1, 2, 3].reduce(1) { |a, v| a * v }
<rubydoc> # => 6 (https://carc.in/#/r/5vzh)
<baweaver> &>> [1, 2, 3].reduce(1, :*)
<rubydoc> # => 6 (https://carc.in/#/r/5vzj)
<baweaver> This will give you a whole view into how reduce works: https://medium.com/@baweaver/reducing-enumerable-part-one-the-journey-begins-ddc1d4108490
conta has quit [Quit: conta]
<Swyper> one thing that sort of bugs me is I don't know the difference between map and each
<Swyper> and when to use each one
<baweaver> each only iterates a list
<baweaver> map is used to transform a list and return a new list
<Swyper> got it
<Swyper> thanks
Rapture has quit [Quit: Textual IRC Client: www.textualapp.com]
<baweaver> Hrm, maybe I should go through a tutorial of basics on how Enumerable works overall and going through usecases of each of the methods.
<baweaver> s/go through/write/
<Swyper> sure I'd love to read that
tdy has joined #ruby
Mike11 has quit [Quit: Leaving.]
armyriad has quit [Quit: Leaving]
<livcd> interesting atm r/elixir has many more readers than r/ruby + r/rails
KeyJoo has joined #ruby
<Swyper> jeez, FP is a beast I will go through another day
<Swyper> so I'm trying to create a method that just checks to see if a certain character repeats or not, I know uniq exists - but afaik it modifies the list and uniq? will modify the list aswell or return nil
<Swyper> is there a better approach to accomplishing what I am trying to do ?
orbyt_ has joined #ruby
<Swyper> the find method looks promising.
<leftylink> regardless of that, to answer the question "does it repeat", consider phrasing it as "have I seen it before?"
sanscoeur has joined #ruby
<baweaver> uniq doesn't modify the list.
<baweaver> uniq! will
<baweaver> Yep yep
KeyJoo has quit [Quit: KeyJoo]
idiocrash has joined #ruby
ua has quit [Quit: Leaving]
ua has joined #ruby
laaron has joined #ruby
tdy has quit [Remote host closed the connection]
laaron- has quit [Remote host closed the connection]
sanscoeur has quit [Remote host closed the connection]
tiff has joined #ruby
catbusters has joined #ruby
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tdy has joined #ruby
<Swyper> does compact remove all nil and '' elements from an array aswell? The docs only show it removing nil, I think
tiff has joined #ruby
<Swyper> my failing test, has one nil at the front I can't seem to get rid of, not sure why
<baweaver> &>> 'aabbcccdef'.chars.group_by(&:itself).select { |ch, count| count == 1 }.keys
<rubydoc> # => [] (https://carc.in/#/r/5w00)
<baweaver> ah, right
<baweaver> &>> 'aabbcccdef'.chars.group_by(&:itself).select { |ch, chs| chs.size == 1 }.keys
<rubydoc> # => ["d", "e", "f"] (https://carc.in/#/r/5w01)
<baweaver> &>> 'aabbcccdef'.chars.group_by(&:itself)
<rubydoc> # => {"a"=>["a", "a"], "b"=>["b", "b"], "c"=>["c", "c", "c"], "d"=>["d"], "e"=>["e"], "f"=>["f"]} (https://carc.in/#/r/5w02)
m0w has quit [Ping timeout: 246 seconds]
* baweaver really wants a count_by function
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Swyper> o-o
nowhere_man has quit [Ping timeout: 252 seconds]
<Swyper> repeated_char = string.each_char.select { |c| (string.count(c) > 1) && !(c.empty?)}
<Swyper> I'm just confused as to how select is still allowing "" as a repeating character
<Swyper> && !(c.empty?) should have taken care of that no?
<Swyper> though I see what you did with .size but I am still curious as to why what I am doing is incorrect
Rapture has joined #ruby
davidw_ has quit [Ping timeout: 246 seconds]
tdy has quit [Ping timeout: 268 seconds]
<Swyper> baweaver
<leftylink> because " " isn't empty
<leftylink> &>> " ".empty?
<rubydoc> # => false (https://carc.in/#/r/5w0a)
<leftylink> only "" is empty.
<leftylink> &>> "".empty?
<rubydoc> # => true (https://carc.in/#/r/5w0b)
<Swyper> ah
kapil____ has joined #ruby
<Swyper> repeated_char = string.each_char.select { |c| (string.count(c) > 1) && !(c.empty?) && c != " "} works =D
mostlybadfly has quit [Quit: Connection closed for inactivity]
<leftylink> it is helpful to remove code that does nothing, so that it does not confuse readers. the c.empty? part is doing nothing
<Swyper> true
<Swyper> &>> "xyz!".count(a..z)
<rubydoc> # => undefined local variable or method `a' for main:Object (NameError) (https://carc.in/#/r/5w0c)
<Swyper> &>> "xyz!".count("a..z")
<rubydoc> # => 1 (https://carc.in/#/r/5w0d)
<Swyper> anyway to use count with a range?
<Swyper> in this case I want all letters from a-z
<leftylink> as the docs will say, no... but see the docs for Enumerable#count with a block.
<Swyper> ary.count{ |x| x%2==0 } #=> 3, so I count string.count { |x| ("a..z").include?(x) } or something like this?
yokel has quit [Remote host closed the connection]
hutch has quit [Ping timeout: 246 seconds]
yokel has joined #ruby
<Swyper> ?
laaron has quit [Remote host closed the connection]
laaron has joined #ruby
Dbugger has joined #ruby
tiff has joined #ruby
cthulchu has quit [Read error: Connection reset by peer]
cthulchu has joined #ruby
<phaul> For strings the count can count a string range, but not a normal range. 'a-z' would count chars from a to z
<phaul> &ri String#count
<phaul> &>> "xyz!".count("a-z")
<rubydoc> # => 3 (https://carc.in/#/r/5w1a)
<leftylink> that is cool
<Swyper> oh neat
jottr has quit [Ping timeout: 268 seconds]
<Swyper> &>> "xyzZZ!".count("a-z")
<rubydoc> # => 3 (https://carc.in/#/r/5w1m)
<Swyper> &>> "xyzZZ!".count("a-z" || "A-Z")
<rubydoc> # => 3 (https://carc.in/#/r/5w1o)
<Swyper> phaul: anyway to make it inclusive for uppercase character aswell?
<phaul> &>> "xyz!".count("a-zA-Z")
<rubydoc> # => 3 (https://carc.in/#/r/5w1p)
<phaul> hm
<phaul> &>> "xyz!".downcase.count("a-z")
<rubydoc> # => 3 (https://carc.in/#/r/5w1q)
<phaul> im an idiot
<phaul> &>> "xyzZZ!".count("a-zA-Z")
<rubydoc> # => 5 (https://carc.in/#/r/5w1s)
<phaul> that's what I meant
<leftylink> Swyper: it's improtant to note, there's nothing magical about the syntax "a-z" || "A-Z". the expression evaluates to "a-z".
<Swyper> leftylink: I'm just trying to figure out the logic with which it works
<leftylink> so the attempt of `"xyzZZ!".count("a-z" || "A-Z")` is exactly equal to `"xyzZZ!".count("a-z")`
<leftylink> to understand the logic of how it works, it is useful to understand that there is nothing magical going on with the syntax there
<leftylink> `"a-z" || "A-Z"` is evaluated just as it would be in any other context
<phaul> also worth noting that 'a-z' or 'a-zA-Z' are just strings and String#count implements some special behaviour for them if the argument matches a certain pattern
Mike11 has joined #ruby
KazeFX has joined #ruby
<phaul> &>> %w(a A).map(&:ord)
<rubydoc> # => [97, 65] (https://carc.in/#/r/5w2e)
<phaul> so it would seem that string.count(A-z) would also work, but it would count chars in in between the lower alpha and upper alpha ranges
hutch has joined #ruby
<Iambchop> &>> (?Z..?a).to_a.join
<rubydoc> # => "Z[\\]^_`a" (https://carc.in/#/r/5w2n)
tdy has joined #ruby
tdy has quit [Remote host closed the connection]
donofrio has joined #ruby
dviola has quit [Quit: WeeChat 2.3]
jottr has joined #ruby
<Swyper> copy_of_string = string.map.with_index { |word, i| word.count("a-zA-Z") }
<Swyper> I need to get the two longest strings without accounting for anything thats not a letter
<Swyper> if I do .sort then I end up just the counts in numerical order
<Swyper> any ideas for how I can get the top 2 longest alphabetical strings?
<Swyper> using what i have now, ideally
<leftylink> &ri Enumerable#max_by
<leftylink> is my suggestion
dinfuehr has quit [Ping timeout: 245 seconds]
jottr has quit [Ping timeout: 246 seconds]
laaron- has joined #ruby
dinfuehr has joined #ruby
<leftylink> or, if you insist on keeping the separate array of # of letters of each string, then you want Array#zip
agent_white has quit [Quit: bbl]
laaron has quit [Ping timeout: 256 seconds]
<Swyper> I suppose I need the words sorted in order by word.count("a-zA-Z")
<Swyper> this map would just give me a count of each element in the array with the parameters given in Count
<Swyper> but I need to output the original elements
<Swyper> the top 2 longest alphabetical elements
<leftylink> my suggestion stnads.
<leftylink> or I guess you can use Enumerable#sort_by if you want
uplime has joined #ruby
sidepocket has quit [Ping timeout: 256 seconds]
<Swyper> I'm finding this one to be *very* confusing
<Swyper> tests + current code
<phaul> Swyper: what are the two things passed to the block of sort_by?
<phaul> &ri Enumerable#sort_by
<Swyper> sorry that should not be there
<Swyper> but the errors are still the same
<Swyper> copy_of_string = string.split.sort_by { |word| word.count("a-zA-Z") }
<Swyper> return copy_of_string[copy_of_string.length-1] + copy_of_string[copy_of_string.length-2]
<phaul> which part of the error confuses you? we can explain
raulp has quit [Ping timeout: 272 seconds]
raulp has joined #ruby
<phaul> first is really just coomplaining that 2 != 14. The test is not the best that's why it's outputting that small novel about oobjects not being the same. If you change it to expect(longest_two_words(string).length).to eq 2 it would output something more sane
polishdub has quit [Quit: leaving]
<Swyper> ah phaul thanks I'll update the test and report back
garyserj has joined #ruby
<Swyper> phaul:
<Swyper> gives me an error xD
<leftylink> you forgot to say what error.
Aqo has quit [Quit: ChatZilla 0.9.92-rdmsoft [XULRunner 35.0.1/20150122214805]]
<Swyper> undefined local variable or method `actual' for #<RSpec::ExampleGroups::EnumerablesPart2::LongestTwoWords:0x00007f804c99fec0>
<leftylink> then you should define it
<leftylink> if you expect the test to work
venmx has joined #ruby
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tiff has joined #ruby
tiff has quit [Client Quit]
tiff has joined #ruby
tiff has quit [Client Quit]
laaron has joined #ruby
laaron- has quit [Remote host closed the connection]
SeepingN has joined #ruby
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
BTRE has quit [Ping timeout: 250 seconds]
donofrio has quit [Read error: Connection reset by peer]
BTRE has joined #ruby
Swyper has quit [Remote host closed the connection]
sandelius has joined #ruby
tiff has joined #ruby
dellavg_ has quit [Ping timeout: 244 seconds]
<phaul> they are gone ... they were trying to fix the eq, but followed the rspec recommendation which just used generic terms like expected , actual.
connermcd has joined #ruby
hutch has quit [Ping timeout: 244 seconds]
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kapil____ has quit [Quit: Connection closed for inactivity]
hutch has joined #ruby
tiff has joined #ruby
nowhere_man has joined #ruby
irdr has quit [Remote host closed the connection]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
m0w has joined #ruby
Rapture has quit [Quit: Textual IRC Client: www.textualapp.com]
SeepingN has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
hutch has quit [Ping timeout: 250 seconds]
hutch has joined #ruby
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
cd has joined #ruby
Mike11 has quit [Quit: Leaving.]
uplime has quit [Ping timeout: 250 seconds]
hutch has quit [Ping timeout: 246 seconds]
kapil____ has joined #ruby
masterasia has joined #ruby
Swyper has joined #ruby
<Swyper> object identity in this example.
<Swyper> why are the objects not the same? is it because string is immutable ?
<leftylink> because 2 != 14
<phaul> Swyper: sorry I was away from keyboard I coulnt respond
<Swyper> no problem
<leftylink> or, well, 2.equal?(14) was false, to be more precise
irdr has joined #ruby
<leftylink> but I was imprecise and just said !=
<Swyper> so how do I fix the error can you give me some hints
masterasia has quit [Client Quit]
<phaul> first of just insert the .to eq(2) instead of .to be(2) , don't replace the whole thing
<phaul> that should get rid of some of the confusing parts.
<phaul> Then you will have to figure out why your algorithm is returning 14 instead of 2
<phaul> the actual and expected are just generic terms in the rspec message, and if you take them literarly they are not defined
<baweaver> also
<baweaver> &>> [1,2,3,4,5].last(2)
<rubydoc> # => [4, 5] (https://carc.in/#/r/5w3k)
<baweaver> `return` isn't really needed in ruby either.
<baweaver> Also you're quite literally returning both of the strings as one string
<baweaver> instead of as an array, which is probably what you intended.
<baweaver> &>> 'some words are longer than other words, who would have thought?'.split.max_by(2) { |w| w.count('a-zA-Z') }
<rubydoc> # => ["thought?", "longer"] (https://carc.in/#/r/5w3l)
<baweaver> Interesting part is that that _includes_ punctuation
<baweaver> not in the count, but in the return.
tdy has joined #ruby
<Swyper> I made that so much harder then it needed to be
<baweaver> That phrase gets far more common the more programming one does.
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
memofun has joined #ruby
memofun has quit [Ping timeout: 240 seconds]
hiroaki has joined #ruby
dviola has joined #ruby
sandelius has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
davidw_ has joined #ruby
orbyt_ has joined #ruby
laaron- has joined #ruby
laaron has quit [Remote host closed the connection]
Swyper has quit [Remote host closed the connection]
uplime has joined #ruby
hutch has joined #ruby
m0w has quit [Ping timeout: 244 seconds]
catbusters has quit [Quit: Connection closed for inactivity]
khanred has joined #ruby
venmx has quit [Ping timeout: 244 seconds]
rkazak has joined #ruby
lytol has quit [Remote host closed the connection]
khanred has left #ruby ["Leaving"]
umjisus has joined #ruby
jthomas2 has quit [Ping timeout: 245 seconds]
nowhere_man has quit [Ping timeout: 252 seconds]
nowhere_man has joined #ruby
masterasia has joined #ruby
SeepingN has joined #ruby
connermcd has quit [Quit: WeeChat 2.3]
hutch has quit [Ping timeout: 244 seconds]