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
nu
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,
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
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 arr
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 wrote:
> Op 2-12-2018 om 11:15
--- Begin Message ---
Just realized that String>>#asNumber works differently in Pharo and in Squeak.
'+3' asNumber "Works in Squeak, not in Pharo"
BUT
'+3' asInteger "Works in both Squeak and Pharo"
-
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest
Again a memory message?Op 2 december 2018 om 17:06 schreef phil--- via Pharo-users :
--- Begin Message ---
I am not using a file, but copy/paste my puzzleInput into a puzzleInput
method.
Then I use lines from there.
e.g. shifts
^ self puzzleInput lines collect: [ :each | ((each beginsWith: '+')
ifTrue: [ each allButFirst ] ifFalse: [ each ]) asNumber ]
Because the challeng
On Sun, 2 Dec 2018 at 17:49, Roelof Wobben wrote:
> Hello,
>
> I have a collection that looks like this :
>
> sampleData1
> "comment stating purpose of message"
>
> ^ #( -8
> +7)
>
> I want to add those numbers up but the code chokes at the +
>
To get some insight, do
#( -
tual horizon of radius zero". (A. Einstein)
On Sunday, December 2, 2018, 6:26:12 a.m. EST, Sven Van Caekenberghe
wrote:
> On 2 Dec 2018, at 12:14, Benoit St-Jean via Pharo-users
> wrote:
>
>
> From: Benoit St-Jean
> Subject: Re: [Pharo-users] How to t
--- Begin Message ---
Exactly!
It's easier to manipulate that OrderedCollection that to open/reopen the file.
It'll be VERY handy for problem #2 where you will need to iterate multiple
times on the data! ;)
-
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Op 2-12-2018 om 12:19 schreef Benoit St-Jean via Pharo-users:
oke, and if I understand your code files is then the variable that holds
the file.
Roelof
> On 2 Dec 2018, at 12:14, Benoit St-Jean via Pharo-users
> wrote:
>
>
> From: Benoit St-Jean
> Subject: Re: [Pharo-users] How to take care that the + before a number is
> ignored
> Date: 2 December 2018 at 12:14:10 GMT+1
> To: pharo-users@lists.pharo.org
> On 2 Dec 2018, at 12:07, Roelof Wobben wrote:
>
> Nope, only the part how I can read the file.
For scripting (non-production) code, you can read the whole file (and split it
into lines) using
'file.log' asFileReference contents lines.
--- Begin Message ---
Oups!
Usually, it's way nicer/better/suggested to declare all variables... Forgot
"lines" !
.
Nicer version:
| file lines |
lines := OrderedCollection new.
file := StandardFileStream readOnlyFileNamed: 'day.1.input'.
[file atEnd] whileFalse: [lines add: file nextLine].
fi
--- Begin Message ---
You can do solve the problem without the "lines" variable but, believe me, you
want to keep those lines in a collection. It's gonna be a lot easier down the
road!
Hint (to solve the problem) : look at what "lines" contain (instances of which
class). That class has everyth
Op 2-12-2018 om 11:55 schreef Benoit St-Jean via Pharo-users:
Nope, only the part how I can read the file.
Roelof
--- Begin Message ---
Do you want the solution for the first one to get you going?
The part2 of problem 1 is somewhat a little more complex but once you get the
idea, the rest shouldn't be that hard!
-
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest:
--- Begin Message ---
You're giving yourself *A LOT* of trouble by not simply reading a file!
Besides, you'll have the same problem for every problem, twice per problem!
-
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Che
Op 2-12-2018 om 11:43 schreef Benoit St-Jean via Pharo-users:
if you can learn me that.
Right now., the input is a method.
I think I can do the rest from there
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
--- Begin Message ---
Roeloff,
Is this for the Advent of Code 2018?
The easiest way is to read the input file... Then, I can guide you from there!
;)
-
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamne
Hi Roelof,
Two problems:
1. + is a symbol so compare it to #+
2. A false case is needed to return the untouched sum, otherwise it
truns to nil
#(+1 -8) inject: 0 into: [:sum :each | each ~= #+ ifTrue: [sum + each]
ifFalse: [sum]] .
Hilaire
--
Dr. Geo
http://drgeo.eu
Hello,
I have a collection that looks like this :
sampleData1
"comment stating purpose of message"
^ #( -8
+7)
I want to add those numbers up but the code chokes at the +
so I did this :
FrequencyFinderData new class sampleData1 inject: 0 into: [:sum :each
| (each ~= $+) ifTr
24 matches
Mail list logo