How to take care that the + before a number is ignored

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: How to take care that the + before a number is ignored

Roelof
I know,

that output is given by the AdventOfCode 2018 challenge.

Roelof


Op 2-12-2018 om 20:36 schreef Richard O'Keefe:
Thinking about this functionally, you want
   to sum
   the array elements that are not + .
So,
   (array select: [:each | each ~~ #+]) sum
The *best* approach is not to put the + symbols
into the array in the first place.

On Sun, 2 Dec 2018 at 23:46, Roelof Wobben <[hidden email]> wrote:
Op 2-12-2018 om 11:15 schreef Hilaire:
> #(+1 -8) inject: 0 into: [:sum :each | each ~= #+ ifTrue: [sum +  each]
> ifFalse: [sum]] .

Thanks,

Now to stretch my mind I will try to make one with double-dispatch.

Roelof



Reply | Threaded
Open this post in threaded view
|

Re: How to take care that the + before a number is ignored

Roelof
In reply to this post by Richard O'Keefe
and I do not want to delete all numbers that begin with a + but remove the trailing +  from a string which look like this +15

Op 2-12-2018 om 20:36 schreef Richard O'Keefe:
Thinking about this functionally, you want
   to sum
   the array elements that are not + .
So,
   (array select: [:each | each ~~ #+]) sum
The *best* approach is not to put the + symbols
into the array in the first place.

On Sun, 2 Dec 2018 at 23:46, Roelof Wobben <[hidden email]> wrote:
Op 2-12-2018 om 11:15 schreef Hilaire:
> #(+1 -8) inject: 0 into: [:sum :each | each ~= #+ ifTrue: [sum +  each]
> ifFalse: [sum]] .

Thanks,

Now to stretch my mind I will try to make one with double-dispatch.

Roelof



Reply | Threaded
Open this post in threaded view
|

Re: How to take care that the + before a number is ignored

Richard O'Keefe
Who said anything about deleting any numbers?  The code
fragment I posted did not delete any numbers; it merely
made a new array with everything that was not #+.  In
the original post there were no strings.  (By the way,
you wrote "trailing" where you meant "leading".)

On Mon, 3 Dec 2018 at 08:40, Roelof Wobben <[hidden email]> wrote:
and I do not want to delete all numbers that begin with a + but remove the trailing +  from a string which look like this +15

Op 2-12-2018 om 20:36 schreef Richard O'Keefe:
Thinking about this functionally, you want
   to sum
   the array elements that are not + .
So,
   (array select: [:each | each ~~ #+]) sum
The *best* approach is not to put the + symbols
into the array in the first place.

On Sun, 2 Dec 2018 at 23:46, Roelof Wobben <[hidden email]> wrote:
Op 2-12-2018 om 11:15 schreef Hilaire:
> #(+1 -8) inject: 0 into: [:sum :each | each ~= #+ ifTrue: [sum +  each]
> ifFalse: [sum]] .

Thanks,

Now to stretch my mind I will try to make one with double-dispatch.

Roelof



Reply | Threaded
Open this post in threaded view
|

Re: How to take care that the + before a number is ignored

Roelof
sorry, then I misunderstood your code.

Roelof



Op 2-12-2018 om 20:48 schreef Richard O'Keefe:
Who said anything about deleting any numbers?  The code
fragment I posted did not delete any numbers; it merely
made a new array with everything that was not #+.  In
the original post there were no strings.  (By the way,
you wrote "trailing" where you meant "leading".)

On Mon, 3 Dec 2018 at 08:40, Roelof Wobben <[hidden email]> wrote:
and I do not want to delete all numbers that begin with a + but remove the trailing +  from a string which look like this +15

Op 2-12-2018 om 20:36 schreef Richard O'Keefe:
Thinking about this functionally, you want
   to sum
   the array elements that are not + .
So,
   (array select: [:each | each ~~ #+]) sum
The *best* approach is not to put the + symbols
into the array in the first place.

On Sun, 2 Dec 2018 at 23:46, Roelof Wobben <[hidden email]> wrote:
Op 2-12-2018 om 11:15 schreef Hilaire:
> #(+1 -8) inject: 0 into: [:sum :each | each ~= #+ ifTrue: [sum +  each]
> ifFalse: [sum]] .

Thanks,

Now to stretch my mind I will try to make one with double-dispatch.

Roelof




12