00:06
va5c0 has joined #ruby
00:16
peirik__ has joined #ruby
00:21
peirik__ has quit [Ping timeout: 256 seconds]
00:23
ur5us has quit [Ping timeout: 260 seconds]
00:28
supay has quit [Quit: Connection closed for inactivity]
00:42
peirik__ has joined #ruby
00:43
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
00:43
boey89 has quit [Ping timeout: 256 seconds]
00:45
Aminda has joined #ruby
00:48
lucasb has quit [Quit: Connection closed for inactivity]
00:48
va5c0 has quit [Quit: WeeChat 3.7.1]
00:59
markong has quit [Ping timeout: 256 seconds]
01:00
va5c0 has joined #ruby
01:05
va5c0 has quit [Quit: WeeChat 3.7.1]
01:07
John_Ivan__ has joined #ruby
01:12
John_Ivan_ has quit [Ping timeout: 256 seconds]
01:13
va5c0 has joined #ruby
01:14
cartdrige has joined #ruby
01:17
Aminda has quit [Remote host closed the connection]
01:18
Aminda has joined #ruby
01:22
va5c0 has quit [Quit: WeeChat 3.7.1]
01:24
peirik__ has quit [Ping timeout: 260 seconds]
01:26
dviola has left #ruby [WeeChat 3.7.1]
01:26
dviola has joined #ruby
01:36
KaitoDaumoto has quit [Read error: Connection reset by peer]
01:39
wand has quit [Remote host closed the connection]
01:49
wand has joined #ruby
02:23
donofrio has joined #ruby
02:25
donofrio_ has quit [Ping timeout: 252 seconds]
02:26
crax23 has joined #ruby
02:29
cartdrige has quit [Ping timeout: 260 seconds]
02:31
crax23 has quit [Ping timeout: 268 seconds]
02:35
va5c0 has joined #ruby
02:41
goldfish has quit [Ping timeout: 260 seconds]
02:41
va5c0 has quit [Quit: WeeChat 3.7.1]
02:42
Rounin has quit [Ping timeout: 268 seconds]
02:58
cartdrige has joined #ruby
03:16
goepsilongo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
03:16
goepsilongo has joined #ruby
03:25
reset has quit [Quit: reset]
04:26
CrazyEddy has joined #ruby
04:39
cek has quit [Quit: Connection closed for inactivity]
04:46
cartdrige has quit [Quit: Leaving]
06:33
phenom has quit [Read error: Connection reset by peer]
06:36
phenom has joined #ruby
07:28
D_A_N has quit [Quit: leaving]
07:32
Sankalp has quit [Ping timeout: 256 seconds]
07:32
Sankalp- has joined #ruby
07:33
Sankalp- is now known as Sankalp
07:44
okivz has joined #ruby
07:46
<
okivz >
I got a 'bus error' whilst trying to (json) encode a 'circular' array.
07:49
<
okivz >
is there anyway of detecting 'circular' array: for example; a=[]; a<<a
07:49
<
okivz >
when encoding to JSON
07:59
peirik__ has joined #ruby
08:00
<
okivz >
is there anyway of detecting 'circular' array: for example; a=[]; a<<a, to avoid 'bus error'
08:02
<
leftylink >
there surely must be a way of detecting one. for example, `a.include?(a)` is true
08:06
<
okivz >
yep, that works, thanks
08:10
okivz has quit [Remote host closed the connection]
08:43
wand has quit [Remote host closed the connection]
08:49
wand has joined #ruby
08:56
peirik__ has quit [Ping timeout: 252 seconds]
09:06
dionysus69 has joined #ruby
09:23
jvalleroy has joined #ruby
09:51
nmollerup has joined #ruby
09:55
Sankalp has quit [Ping timeout: 260 seconds]
09:56
Sankalp has joined #ruby
10:01
mahlon has quit [Ping timeout: 248 seconds]
10:03
_ht has joined #ruby
10:05
mahlon has joined #ruby
10:21
Rounin has joined #ruby
10:21
Rounin has quit [Changing host]
10:21
Rounin has joined #ruby
10:54
Aminda has quit [Remote host closed the connection]
10:55
Aminda has joined #ruby
11:04
Aminda has quit [Remote host closed the connection]
11:11
Aminda has joined #ruby
11:14
reset has joined #ruby
11:52
rvalue has quit [Read error: Connection reset by peer]
11:52
peirik__ has joined #ruby
11:52
rvalue has joined #ruby
11:59
peirik__ has quit [Ping timeout: 268 seconds]
12:03
cryptkeeper has quit [Quit: Connection closed for inactivity]
12:04
<
meuk >
Question is why does the test for lowercase passes while I feed it a string with capitalized characters?
12:05
<
meuk >
I initialize the class with .downcase on a string but removing that still makes the test pass.
12:05
<
meuk >
So, I'm scratching my head here
12:16
__ht has joined #ruby
12:18
_ht has quit [Ping timeout: 260 seconds]
12:19
_ht has joined #ruby
12:21
__ht has quit [Ping timeout: 256 seconds]
12:22
z4kz has quit [Ping timeout: 260 seconds]
12:25
cek has joined #ruby
12:32
cek has left #ruby [#ruby]
12:33
markong has joined #ruby
12:34
<
leftylink >
there are no assertions in `it "is written in lowercase"` at all. it is not testing anything
12:35
cartdrige has joined #ruby
12:35
<
leftylink >
so since it is not testing anything, it will always pass no matter what
12:44
<
meuk >
Hmm, let me look into that. Thanks leftylink ^^
12:47
cartdrige has quit [Quit: Leaving]
12:47
<
meuk >
Right, I forgot the .should method and assigned the object instead of comparing it >.<
12:53
goepsilongo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
12:53
goepsilongo has joined #ruby
12:56
dionysus69 has quit [Ping timeout: 260 seconds]
14:00
<
leah2 >
good argument against magic methods
14:01
<
meuk >
Can you eloborate on that? :)
14:25
c10l has quit [Quit: See ya! o/]
14:33
c10l has joined #ruby
14:39
alexherbo2 has joined #ruby
14:43
peirik__ has joined #ruby
14:48
cartdrige has joined #ruby
14:48
<
leah2 >
ages ago i wrote a testing library called bacon that also used this (2+3).should == 5 style
14:49
<
leah2 >
which is cute, but has it's issues too
14:50
<
leah2 >
but less verbose than rspec at least :D
14:50
<
leah2 >
one should add some code to make a warning if a test case has no assertions
14:51
c10l has quit [Quit: See ya! o/]
14:58
gr33n7001 has joined #ruby
14:58
gr33n7007h is now known as Guest335
14:58
Guest335 has quit [Killed (platinum.libera.chat (Nickname regained by services))]
14:58
gr33n7001 is now known as gr33n7007h
14:58
c10l has joined #ruby
14:58
Guest335 has joined #ruby
15:00
crax23 has joined #ruby
15:03
cartdrige has quit [Ping timeout: 256 seconds]
15:03
Y05hito__ has joined #ruby
15:06
cartdrige has joined #ruby
15:06
crax23 has quit [Ping timeout: 252 seconds]
15:07
mineflaptop has joined #ruby
15:08
Y05hito__ has quit [Ping timeout: 240 seconds]
15:09
FullMetalStacker has joined #ruby
15:15
szkl has joined #ruby
15:19
mineflaptop has quit [Ping timeout: 268 seconds]
15:21
<
FullMetalStacker >
Hi all! I am stuck with the following exercise:
15:21
<
FullMetalStacker >
"Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements."
15:21
<
FullMetalStacker >
arr.each_with_index { |n, i| (arr.delete_at(i) and arr << 0) if n.to_i == 0 }
15:21
<
FullMetalStacker >
My solution so far is this:
15:21
<
FullMetalStacker >
It works well with e.g. this arr = [1, 2, 0, 1, 0, 1, 0, 3, 0, 1]
15:21
<
FullMetalStacker >
But with this array I have a strange problem:
15:21
<
FullMetalStacker >
[9, 0.0, 0, 9, 1, 2, 0, 1, 0, 1, 0.0, 3, 0, 1, 9, 0, 0, 0, 0, 9]
15:21
<
FullMetalStacker >
Instead of the expected one:
15:21
<
FullMetalStacker >
[9, 9, 1, 2, 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
15:21
<
FullMetalStacker >
I get this one:
15:21
<
FullMetalStacker >
[9, 0, 9, 1, 2, 1, 1, 3, 1, 9, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0]
15:21
<
FullMetalStacker >
So obviously there seems to be a problem with the float on index 1.
15:21
<
FullMetalStacker >
This is strange to me because there is no problem with the float on index 10!
15:21
<
FullMetalStacker >
Also I have tried various things to also take care of floats, which all don't provide any cure, e.g. adding at the end "if n == 0 or n == 0.0 } or as I have it now, turn the n to integer first.
15:21
<
FullMetalStacker >
What am I doing wrong can someone help me out?
15:31
<
FullMetalStacker >
dfdfgdsfg
15:32
mineflaptop has joined #ruby
15:32
mineflaptop has quit [Remote host closed the connection]
15:33
D_A_N has joined #ruby
15:34
<
wnd >
I don't really understand what it is you're trying to do, but deleting elements of an array by index while you're interating over it (with an index) sounds like asking for trouble
15:34
cartdrige has quit [Ping timeout: 252 seconds]
15:35
<
FullMetalStacker >
hi wnd! Thank you for that hint, I will try to solve it with creating a new array and see if that solves my issues!
15:37
<
wnd >
ah, you're moving the zeros (and non-numbers) to the end of the array
15:38
dionysus69 has joined #ruby
15:38
<
FullMetalStacker >
exactly, see the mission statement in line 2
15:38
<
wnd >
ah, I'm just being blind
15:38
<
FullMetalStacker >
np :)
15:40
<
gr33n7007h >
FullMetalStacker: arr.group_by(&:zero?).values.sum([])
15:40
<
gr33n7007h >
god knows how efficient that is though, lol
15:44
peirik__ has quit [Ping timeout: 260 seconds]
15:44
Vonter has quit [Ping timeout: 256 seconds]
15:45
<
wnd >
or Array#partition { |v| !v.zero? }.flatten, but that's not much of a learning experience - and perhaps a bit hard to read
15:46
peirik__ has joined #ruby
15:49
<
gr33n7007h >
wnd: partition was my initial idea xD
15:50
<
gr33n7007h >
but i was doing something wrong, obviously, coz i couldn't get it to work lol
15:50
<
wnd >
group_by is unstable here becase if you don't control input array, you don't control the order of hash keys it returns
15:50
peirik__ has quit [Ping timeout: 256 seconds]
15:51
<
wnd >
[0, 1].group_by(&:zero?).values != [1, 0].group_by(&:zero?).values
15:51
Vonter has joined #ruby
15:52
jdmark has quit [Remote host closed the connection]
15:53
legit has quit [Ping timeout: 255 seconds]
15:53
legit has joined #ruby
15:53
<
gr33n7007h >
wnd: good observation! this is what happens when you don't unit-test xD
15:54
jdmark has joined #ruby
15:54
<
gr33n7007h >
and write spontaneous code :)
15:57
___nick___ has joined #ruby
15:57
___nick___ has quit [Client Quit]
15:58
___nick___ has joined #ruby
16:08
<
FullMetalStacker >
alright, back :-) I fixed my solution to not fiddle with the existing array, and it worked now :-)
16:08
<
FullMetalStacker >
arr2 = Array.new
16:08
<
FullMetalStacker >
return arr2
16:08
<
FullMetalStacker >
arr.each{ |n| arr2 << n if (n != 0) }.each{ |n| arr2 << 0 if n == 0 }
16:08
<
FullMetalStacker >
Now let me check your obvious much more elegant solutions, too :-)
16:11
<
Rounin >
Does it just take any 0 and put it at the end?
16:12
<
Rounin >
I mean, "just"... It's a perfectly fine thing to do
16:13
<
FullMetalStacker >
@Rounin: Yes, and it also solves the issue that I get floats 0.0 and it expects me to put them to the end as integers 0
16:17
<
FullMetalStacker >
@gr33n7007h arr.group_by(&:zero?).values.sum([]) this is so elegant :-) Thanks, I learned again new stuff!
16:18
<
FullMetalStacker >
how would I integrate that the floats are converted to integers with this solution?
16:19
<
FullMetalStacker >
ah got it
16:19
<
FullMetalStacker >
arr.group_by(&:zero?).values.sum([]).map(&:to_i)
16:20
<
gr33n7007h >
FullMetalStacker: that has gotchas! read what wnd wrote above.
16:24
<
Rounin >
You could go (arr.filter{|n| n != 0} + arr.filter{|n| n == 0}).map{|n| n.to_f}
16:25
<
FullMetalStacker >
Oh, I see. The group_by puts the group of zeros to the beginning if the first digit in the array is a 0 and if not, to the end. this is of course a problem
16:25
<
Rounin >
Or to only convert the zeros to floats: arr.filter{|n| n != 0} + arr.filter{|n| n == 0}.map{|n| n.to_f}
16:26
<
Rounin >
A little bit of code golf on the weekend is good fun
16:26
jidar has quit [Ping timeout: 246 seconds]
16:26
<
Rounin >
Oh, was it to integer... to_i then, of course
16:28
<
Rounin >
arr.filter{|n| n != 0} + arr.filter(&:zero?).map(&:to_i) Haha
16:28
<
Rounin >
Or, well, (arr.filter{|n| n != 0} + arr.filter(&:zero?)).map(&:to_i) to map all of them
16:30
<
Rounin >
Man, Ruby is fun
16:40
jidar has joined #ruby
16:41
<
FullMetalStacker >
@wnd what does the !v do?
16:41
<
FullMetalStacker >
ah, !v.zero? = not zero?
16:45
<
gr33n7007h >
FullMetalStacker: arr.sort{_1}.reverse.map(&:to_i)
16:46
<
FullMetalStacker >
this puts the zeros to the end, but also changes the others, no?
16:46
<
FullMetalStacker >
@Runin: Ruby is the most beautiful language of all, including human languages :-)
16:47
<
gr33n7007h >
FullMetalStacker: other integers barring zero are in the same order.
16:50
<
gr33n7007h >
i know the problem code doesn't have negative integers so this passes xD
16:52
<
gr33n7007h >
no it still passes.
16:57
<
gr33n7007h >
Rounin: it really is the greatest language ever created imho [fact] xD
17:01
<
Rounin >
I mean... We've taken a fair and unbiased poll
17:06
alexherbo2 has quit [Remote host closed the connection]
17:07
alexherbo2 has joined #ruby
17:09
<
gr33n7007h >
Rounin: first rule of ruby channel: do not talk bad about ruby channel. second rule of ruby channel: do
*NOT TALK* bad about ruby channel. third rule of ruby channel: if someone has bias towards ruby they are wrong! fourth rule of ruby channel: Ruby is Aweome!
17:10
eddof13 has joined #ruby
17:11
<
gr33n7007h >
i quite like lua too, it's a great language tbh.
17:14
<
Rounin >
Hmmm... Is this according to the rules of the Ruby channel I wonder
17:14
<
Rounin >
I suppose it's also OK to like other things
17:17
peirik__ has joined #ruby
17:18
sagax has joined #ruby
17:19
<
sagax >
rubygems has broken?
17:20
<
gr33n7007h >
Rounin: it's only a joke xD official rules are in the topic
17:20
<
gr33n7007h >
sagax: o/
17:20
<
gr33n7007h >
sagax: broken?
17:20
<
sagax >
>> This gem could not be found
17:20
<
sagax >
yes, gem could not be found
17:20
<
sagax >
when i change any version, >> gem could not be found
17:22
<
sagax >
what it's is? i don't understand
17:23
peirik__ has quit [Ping timeout: 268 seconds]
17:24
<
havenwood >
FullMetalStacker: my first thought without looking at other solutions is:
17:24
<
havenwood >
zeros = Array.new(array.count(0), 0); array.delete(0); [*array, *zeros]
17:26
<
havenwood >
or maybe:
17:26
<
havenwood >
zeros = [0] * array.count(0); array.delete(0); [*array, *zeros]
17:27
<
havenwood >
FullMetalStacker: On second thought:
17:27
<
havenwood >
[*array.reject(&:zero?), *[0] * array.count(0)]
17:28
<
havenwood >
Or I think I like the slightly longer Array.new version: [*array.reject(&:zero?), *Array.new(array.count(0), 0)]
17:32
<
havenwood >
FullMetalStacker: My first destructive way seems to be about 3x as fast, FWIW.
17:34
gcd has quit [Ping timeout: 246 seconds]
17:34
peirik__ has joined #ruby
17:35
<
havenwood >
Here's a derivation of Rounin's solution: [*array.filter(&:nonzero?), *array.filter(&:zero?).map(&:floor)]
17:35
some14u has joined #ruby
17:36
<
havenwood >
That's about 8x slower than the destructive version. Might want to be going on readability rather than speed, but I don't know the judgement criteria. :)
17:37
<
havenwood >
Eww, I meant to write `&:to_i` not `&:floor` after considering for a sec and wrote the wrong one.
17:38
<
havenwood >
Or it a `filter_map` speeds it up a bit.
17:39
peirik__ has quit [Ping timeout: 260 seconds]
17:39
<
havenwood >
That gets it to about 6 times slower than destructive + counting.
17:39
* havenwood
would rather race than golf :P
17:40
<
havenwood >
It's probably good to generally assume readability is prioritized above speed above golf.
17:47
cognemo has joined #ruby
17:47
alexherbo2 has quit [Remote host closed the connection]
17:48
alexherbo2 has joined #ruby
18:09
finsternis has joined #ruby
18:17
<
gr33n7007h >
speed is always good though for certain circumstances.
18:45
eddof13 has quit [Quit: My MacBook Air has gone to sleep. ZZZzzz…]
18:48
markong has quit [Ping timeout: 256 seconds]
18:48
alexherbo2 has quit [Remote host closed the connection]
18:49
alexherbo2 has joined #ruby
19:08
aindilis_ has quit [Remote host closed the connection]
19:08
aindilis has joined #ruby
19:15
infernix has quit [Ping timeout: 240 seconds]
19:19
alexherbo2 has quit [Remote host closed the connection]
19:19
<
leftylink >
|(a-[0]).concat([0]*a.count(0))
19:19
<
leftylink >
(a-[0]).concat([0]*a.count(0))
19:19
<
leftylink >
of course
19:20
alexherbo2 has joined #ruby
19:21
<
leftylink >
actually we should get rid of unnecessary parentheses
19:21
<
leftylink >
a-[0]+[0]*a.count(0)
19:21
<
leftylink >
perfect
19:22
alexherbo2 has quit [Remote host closed the connection]
19:23
alexherbo2 has joined #ruby
19:24
<
leftylink >
I want to use fill but the args fill wants are unsuitable
19:45
boey89 has joined #ruby
19:45
infernix has joined #ruby
19:52
smp has quit [Ping timeout: 260 seconds]
19:53
smp has joined #ruby
19:56
desnudopenguino has quit [Quit: desnudopenguino]
19:58
desnudopenguino has joined #ruby
20:03
cartdrige has joined #ruby
20:41
___nick___ has joined #ruby
20:42
___nick___ has quit [Client Quit]
20:43
stirl has joined #ruby
20:44
___nick___ has joined #ruby
20:54
ur5us has joined #ruby
20:56
ur5us has quit [Remote host closed the connection]
21:04
___nick___ has quit [Ping timeout: 256 seconds]
21:06
boey89 has quit [Ping timeout: 260 seconds]
21:24
johnsonrabbit has joined #ruby
21:25
<
FullMetalStacker >
guys thank you all for your super feedback & input, I checked all solutions and learned again a ton of new smart things! THANK YOU ALL!
21:25
<
FullMetalStacker >
This channel is pure gold, so great!
21:33
alexherbo2 has quit [Remote host closed the connection]
21:33
<
johnsonrabbit >
ah. Nevermind, it's comparing a String to an instance of MyClass
21:35
Guest335 has quit [Ping timeout: 252 seconds]
21:39
_ht has quit [Quit: _ht]
21:44
FullMetalStacker has quit [Read error: Connection reset by peer]
21:45
stirl_ has joined #ruby
21:45
stirl has quit [Read error: Connection reset by peer]
21:45
stirl_ is now known as stirl
21:47
stirl has quit [Client Quit]
21:50
stirl has joined #ruby
21:52
boey89 has joined #ruby
21:53
cartdrige has quit [Ping timeout: 256 seconds]
21:57
John_Ivan__ has quit [Read error: Connection reset by peer]
21:57
John_Ivan__ has joined #ruby
22:07
eddof13 has joined #ruby
22:07
gr33n7007h has quit [Quit: WeeChat 3.7.1]
22:25
dviola has quit [Ping timeout: 260 seconds]
22:32
dviola has joined #ruby
22:33
Aminda has quit [Ping timeout: 255 seconds]
22:34
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
22:35
boey89 has quit [Ping timeout: 256 seconds]
22:36
Aminda has joined #ruby
22:39
some14u has joined #ruby
22:40
Aminda has quit [Remote host closed the connection]
22:43
Aminda has joined #ruby
22:49
ur5us has joined #ruby
22:54
gr33n7007h has joined #ruby
22:57
boey89 has joined #ruby
22:58
eddof13 has quit [Quit: My MacBook Air has gone to sleep. ZZZzzz…]
22:59
ur5us has quit [Quit: Leaving]
23:00
ruby[bot] has quit [Remote host closed the connection]
23:00
ruby[bot] has joined #ruby
23:01
ur5us has joined #ruby
23:04
gcd has joined #ruby
23:10
peirik__ has joined #ruby
23:15
peirik__ has quit [Ping timeout: 268 seconds]
23:19
cryptkeeper has joined #ruby
23:21
markong has joined #ruby
23:35
peirik__ has joined #ruby
23:38
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
23:38
ur5us has quit [Ping timeout: 240 seconds]
23:44
some14u has joined #ruby
23:51
goepsilongo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
23:51
goepsilongo has joined #ruby
23:52
stirl has left #ruby [#ruby]
23:57
legit has quit [Quit: WeeChat 3.5]
23:57
legit has joined #ruby