some sort of mentor help ?

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

some sort of mentor help ?

Pharo Smalltalk Users mailing list
Hello,

do not know if this is the right channel but is there someone or some book which can help me learn how to approach complex problems like the AdventOfCode challenges , I try that but im stuck because most of the time I have the feeling I choose a difficult solution where some easier one exist.
or I have a very bad plan
that is a wall I hit many times with my languages and I need a way to get out of it and make a step further with Pharo

Regards,

Roelof

Reply | Threaded
Open this post in threaded view
|

Re: some sort of mentor help ?

Pharo Smalltalk Users mailing list
I looked at the site and I knocked out day 1.  These are little programming puzzles you can do in a playground.

Day 1's first puzzles is literally a 1 liner.

The story telling obfuscates the problem and can make the problem seem harder than it is.  You have to learn to cut through the noise and see the problem.

You are supposed to find the amount of fuel required to launch a given mass into space in a rocket.  This is the key paragraph.

"Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2."

The code for this is:

fuel := (mass / 3) floor - 2.

The floor function rounds downwards.  To round up you use ceiling.

You have a list of modules though.  If you click to get your module mass list, its a page with one number per line.  Getting this into a collection is really easy.

masses := #( <paste contents of input data copied from web page here> )

and execute that in your playground.  This is your input data.

To get the fuel for each mass, a collect: seems like a winner.

fuels := masses collect: [:mass | (mass / 3) floor - 2 ].

The final thing he wants is the total amount of fuel required.  You just add up the numbers.

total := fuels sum.

I leave the second puzzle of day 1 to you, it is almost the same except you have to iteratively calculate the fuel to lift the fuel you add.  
To do this you end up putting a loop into the collect; block and executing it over and over until the amount of additional fuel is <= zero.

I hope this gets you going.  You can email me directly at [hidden email] if you get stuck.  

On Dec 3, 2019, at 2:54 PM, Roelof Wobben via Pharo-users <[hidden email]> wrote:


From: Roelof Wobben <[hidden email]>
Subject: some sort of mentor help ?
Date: December 3, 2019 at 2:54:19 PM PST


Hello,

do not know if this is the right channel but is there someone or some book which can help me learn how to approach complex problems like the AdventOfCode challenges , I try that but im stuck because most of the time I have the feeling I choose a difficult solution where some easier one exist.
or I have a very bad plan
that is a wall I hit many times with my languages and I need a way to get out of it and make a step further with Pharo

Regards,

Roelof