« first day (224 days earlier)
← previous day
next day →
last day (377 days later) »
Robin Ryder
1:50 PM
Is there some way of writing
a <- 1 ; b <- a <- 2
which ends with a=2 and b=1?
(Apart from the obvious a <- 1; b <- a; a<- 2: I'd like to avoid the extra a.)
1 hour later…
Giuseppe
3:09 PM
@RobinRyder if you're not set on names, you could just use
T
in place of
b
and set
a=2
separately but I'm not sure how you're trying to use it
Robin Ryder
@Giuseppe a and b will be components of a vector, so it will be more like
(some value has been defined for m[1] earlier in a loop)
m[2] <- m[1]; m[1] <- 0
and I'd like not having to type m[1] twice
Giuseppe
3:26 PM
@RobinRyder you can't just do
m=c(0,m)
? you could link to a TIO of whatever problem you're working on
or else
m=c(0,m[-1])
er, I think that should be
m=c(0,m[-2])
but you get the idea
1 hour later…
Robin Ryder
4:37 PM
Thanks. I think the best I can do in my situation is
m[2:1]=m[1]*1:0
It's for the new chess problem. I'll post a link in a few minutes.
Robin Ryder
4:52 PM
Here is the link: https://codegolf.stackexchange.com/a/182543/86301
I was looking to improve on p[m[2:1]]=p[m[1]]*1:0
Giuseppe
@RobinRyder ah, I see. Yeah you could do
p[m[2:1]]=p[m]*1:0
instead since it'll just discard the remainder of
p[m]
, with a warning. 3 whole bytes!
Robin Ryder
5:20 PM
@Giuseppe Thanks! I like that solution.
« first day (224 days earlier)
← previous day
next day →
last day (377 days later) »
all rooms
Transcript for
Apr
1
Apr '19
2
Apr
4
golfR
R golfing Chatroom
join this room
about this room
00:00
06:00
12:00
18:00
all times are UTC
site design / logo © 2024 Stack Exchange Inc;
legal
mobile