Locomotive_Engineer

Hi folks,
again I have some trouble with the declaration
I’ve read your concepts again and again and Collections and Data Structures · The Julia Language
but have no idea how to solve it.

I create an array:
a_stops =
where I put all stops in with push
and at the end I have an Array Any[
which should be just [
(see below)

any ideas, how to declare
I guess it is something with …, but how?

thanks for any help!

And, there are some typografically errors also (about to come) in the description

‘’’
function add_missing_stops(route, stops…)
a_stops =
d_route = Dict{String, Any}()
for i in eachindex(stops)
push!(a_stops, stops[i].second)
end
#= did not work:
d_route[“from”] = [route[“from”]]
d_route[“to”] = [route[“to”]]
d_route[“stops”] = a_stops
@show typeof(a_stops)
d_route=#
‘’‘# brings the same result:
Dict(“from” => route[“from”], “to” => route[“to”], “stops” => a_stops)
‘’’# route[“stops”].second = a_stops
‘’‘# for each
end
‘’’
I just saw in the hints, that map() will bring the solution.
…will look it up

Just catching up after a couple of days away, some points occur to me:

  1. Your code is unreadable in this format. Please use code blocks, which start with ```julia and end with ```.

  2. The Hints list 3 different ways that add_missing_stops() can be implemented, and we tested all of them successfully. There are links in the hints to official Julia documentation, but information within the track Concept docs should be enough. For this exercise, a comprehension over a vector is the same syntax as over a Python list, if you’re familiar with that. Broadcasting an anonymous function also works, and we give an example in the hints.

  3. You may need to splat the route when constructing the Dict.

Is that enough? If you need more help, please ask again with properly formatted code.

“Your code is unreadable in this format.”
sorry for that (i used ticks instead of backticks)

Okay, here’s the code again
after I initialised

String[]  

instead of

{String}[] 

it works

function add_missing_stops(route, stops...)
    a_stops = []
    d_route = Dict{String, Any}()
    for i in eachindex(stops)
        push!(a_stops, stops[i].second)
    end
#= did not work:
    d_route["from"] = [route["from"]]
    d_route["to"] = [route["to"]]
    d_route["stops"] = a_stops
        @show typeof(a_stops)
    d_route=#
'''# brings the same result:
    Dict("from" => route["from"], "to" => route["to"], "stops" => a_stops)
'''#    route["stops"].second = a_stops
'''#    for each 
end

I’m trying to figure out how

would work
I’m not

I programmed in PASCAL, C, VBA, Perl

I’m sorry but so far I couldn’t figure out how a comprehension works
I would be very thankful if you can give more hints, please

Nisang

In Perl, did you ever use the for statement modifier?

say transform($item) for $item (@mylist);

I cannot tell as it is to long ago

Dear Colin,

I want to thank you again for giving so much here in writing the concepts and being available on the course.

I’ve just solved task 3 in several ways with

  • comprehension and
  • map()
    (with some help of my friend and collegue)

I would like to report some errors and hints that I have found and where we think this should be corrected and added to make the concept more complete and easier as a guide for beginners to be able to solve the exercise.

do you want to read about this ??

1 Like

Certainly! Then @depial and myself can fix obvious errors and think about how to make things clearer.

Coverage of comprehensions is already a known issue. We introduce the simple case in the Loops Concept, though it is not part of the Mixed Juices exercise. A more complete description is given in the later Comprehensions Concept, but that includes complexities of handling multi-dimensional arrays, which are more advanced than anything in Locomotive Engineer.

1 Like

Dear Colin,

thanks for that
I just looked it up…

and found:
in the Instructions - of Mixed_Juices the concept of Comprehensions is missing!

that’s how I didn’t know anything about it.

and now my hints/errors:

  1. (this is outdated because of what I just found out):
    the solution of Task 1 is logical, but not foreseeable, because the effect of [] (Comprehension) in code is not explained before, is it?

  2. wrong dimension #

map(x -> 2x, 1:3)
4-element Vector{Int64}:
→ it should be
3-element Vector{Int64}:
  1. Task 3:

some typografical errors, eg

add_missing_stops(Dict("from" => "New York", "to" => "Miami"),
                      stop_1= > ..
  • at stop1: Space at the wrong place
  • missing „“ at stop1…5
→add_missing_stops(Dict("from" => "New York", "to" => "Miami"), "stop_1" => "Washington, DC", "stop_2" => "Charlotte", "stop_3" => "Atlanta", "stop_4" => "Jacksonville", "stop_5" => "Orlando")
  1. Task 4:

some typografical errors,

extend_route_information(Dict("from" => "Berlin", "to" => "Hamburg"), :length = "100", :speed = "50")

→

extend_route_information(Dict("from" => "Berlin", "to" => "Hamburg"), length = "100", speed = "50")
  • And: please explain map() a bit further, give some more examples

Thanks

Hi Nisang!

Thanks for the feedback! Would you be interested in opening a PR with a fix for the typos?

As @colinleach pointed out, the basics are shown in the Loops concept introduction (see link in the comment above). The concept introduction can be different from the exercise introduction (and it is in this case), and should be accessed from clicking on the concept in the syllabus. If you click on the exercise, you will see the exercise introduction instead. Students aren’t required or even encouraged to use comprehensions in the task, so this part was deleted to keep the exercise introduction shorter and more relevant.

map() is a higher order function, which has its own concept later in the syllabus. While potentially useful here, it’s not technically needed for this exercise, so further explanation is also beyond the scope of this introduction as we don’t want to overload students with too much information (also you can note we left links to the Julia documentation of map and comprehensions, broadcasting and anonymous functions in the hints).

The main aim of this exercise was to get students to practice with different argument type with a special emphasis on splatting and slurping. Judicious use of the latter two can greatly simplify a solution. Careful reading of that section can help a lot with this exercise. In fact, many exercises are designed to use things explicitly mentioned in the introduction, so it’s always a good idea to read that carefully and maybe reread when getting stuck, but also don’t forget about the hints!

As an example, a solution to Task 1 is

get_vector_of_wagons(args...) = [args...]

or instead of [args...] a use of collect(args) can do the trick too, with both of these ideas mentioned in the hints.

Again, we appreciate your feedback, and we’ll look into improving the clarity of everything. You have given me a couple of ideas to help with making the hints better and there is one somewhat bothersome aspect about Task 3 which you’ve reminded me of.

Please let us know if you want to open that PR, otherwise, we’ll be happy to take care of it!

2 Likes

Hi Depial,

I can do that, but where?

And: In my opinion I (re)read the instructions carefully and did’nt know how to solve and did’nt want to use the hints to early
So it seems I should read the concepts in the syllabus to avoid missing something in the future

thanks for the extra information!
I wrote:
“please explain map() a bit further, give some more examples”
here I meant to explain this prior to the exercise.

best wishes

Nisang

Great! Here is the Julia repo on GitHub and this is a link to the Exercism docs for contributing if you want to have a look.

We don’t explain it prior to the exercise because its explanation (and potentially use) requires knowledge of Higher Order Functions, which is a concept that already exists further down the syllabus. We’ve left links to the Julia docs on it in case students want to explore on their own at this stage.

This is a great idea because there is always material in the introduction which is directly relevant to the exercise.

Remember, there is an introduction with learning material directly before/above the instructions and you can always look back to that while doing the exercise (since that is the one that has the highest percentage of exercise specific content out of all of them), but it’s still good to read the full version on the concept page.

Dear Depal,
well in my opinion that’s exactly what I did…
but didn’t progress
And, I don’t know,
but what does it mean,
that the syntax-Errors weren’t recognized or let’s say reported to you earlier?

And, isn’t this request a RP of the code error or
why is it neccessary to report again?

best wishes

Nisang

actually I’ll be happy if you take care of it!
my task list is overcrowded

one more question

what is the recommended exercise after Locomotive Engineer?

I startet “dominoes” before Locomotive Engineer
and it was too difficult and now I see it “in-progress” and no recommended exercise…

??

thanks for your answer!

Nisang

I’m not sure where you are on your journey, but, on the road to learning independence, there is a point where learners are more used to programmatic solutions, of the “plug-and-chug” variety. This is where an example is given and then a follow-up problem closely matches that example with only some slight variation. In this light, I understand how the section on slurping and splatting can be overlooked as irrelevant, since there aren’t any specific examples that can be copied into the exercise.

The way to gain a hint in this case is to try to take in all of the information from the lesson (i.e. the introduction) with equal weight/importance for all parts (e.g. “This is probably here for some reason!”). Then, try to use all of it somewhere (anywhere!) in the exercise. In effect, we are trying to find if there is a place the information can be applied, rather than being told where to apply it. A related idea is to focus on using the new information rather than just focusing on solving the problem.

This requires a bit more learning independence than a “plug-and-chug” situation since the gap between instruction and exercise is larger. Of course, we don’t expect all students to be at that stage, so we also provide hints to make the gap smaller for those who have not arrived there yet.

In short, we have to pass through these different stages on our way to full learning independence, so they can’t be skipped. For that reason, we try to cater to students at all stages, while encouraging them to take the next step in their journey.

We’ll get that taken care of!

You can always report bugs or typos here, and we’ll fix them. If you want to contribute more directly in the future, we make all of our changes to the website code on GitHub.

If you want an exercise that continues to practice the Functions concept you can do Two-Fer or if you want to start another concept, you can check out Function Composition, Nothingness or Random and their exercises.

Can I ask how you are going through the exercises? Are you following the syllabus on Learning Mode?

Or another way?

@AnandNisang, here’s the PR#1051 on GitHub. You can have a look and/or comment on it if you’d like :)

Hi Depial,

thanks for the recommendation!
and for your explanations, that I will answer to later.

actually I’m on practice mode.
as we diskussed above I will now read the concepts from Learning Mode to not to miss any explanations.

And why is it that there’s no recommended exercise right now…
because ‘dominoes’ is still in progress?

with best wishes

Nisang

Tracks are not linear. There’s never any recommended exercises. Exercises are either locked (learning mode only) or unlocked. Once you complete Hello World, you can work on any unlocked exercise in any order. It’s generally a good idea to work on the Easy exercises first, then Medium and then Hard.

Also, if you have learning mode on, you can go to the Learn tab (as seen in the photo above). From there, you can see what concept is needed to be completed to unlock more exercises.

For example, if you completed Locomotive Engineer, then this will open the three concepts I recommended to you along with their exercises.

It will probably be more instructive to follow the syllabus on the Learn tab than to go through the exercises on the Practice tab