3
Knowing that:
[]
denotes an array
[A|B]
extracts the first element of the array in A
and the rest of the array in B
[X, Y] ++ [Z]
creates a concatenated array [X, Y, Z]
[ X || X <- [1, 2, 3, 4], X > 2]
returns the array [3, 4]
(read: create a array
with the following values [1, 2, 3, 4]
which are larger than 2)
What is the name of this algorithm?
bla([A|B]) -> bla([ X || X <- B, X < A]) ++ [A] ++ bla([ X || X <- B, X >= A]);
bla([]) -> [].
This is real java?
– user28595
this is a problem related to java, I did not understand very well what I should answer in "What is the name of this algorithm?" but this problem is more connected to logic than to java
– Celina Shigetomi
@diegofm I think this missing "context", the question should be part of a whole thing, the way this really has no way to answer. Celina if you can confirm if there is such a context could help
– Guilherme Nascimento
Celina there is more information about this exercise, like the context or something else that can make it clearer?
– gato
no, there is no information, only this context was passed.
– Celina Shigetomi
maybe the shape I wrote is a little confusing. [ ] denotes an array. [A|B] extracts the first element of the array in A and the rest of the array in B. [X, Y] ++ [Z] creates a concatenated array [X, Y, Z]. [ X || X <- [1, 2, 3, 4], X > 2] returns array [3, 4]. (read: create array with values contained in array [1, 2, 3, 4] that are greater than 2)
– Celina Shigetomi
This looks like a pseudo-code, had some exercise about how this code style works?
– Guilherme Nascimento
No, this question is a Challenge, where it contains steps, these steps have exercises of each genre, I solved one of html code, another of programming in java and this one here. The exercises are given without any guidance, just been given what this in this question (Knowing that [] ...).
– Celina Shigetomi
@Celinashigetomi but the teacher gave no guidance at any time of pseudo code style, type || means one thing, <- means something else and etc?
– Guilherme Nascimento
then, I had no guidance on this exercise, but in my academic life I see them as operators (my vision according to the java syntax). | must be "or". a<b = less than b. ++ ="increment" and so on (according to java syntax). But I might be looking at the expressions wrong.
– Celina Shigetomi
I thought, to start: let’s create an array with values contained in array [1, 2, 3, 4] that are greater than 2. So, would I use only values 3 and 4? And then put 3 in array A and 4 in B?
– Celina Shigetomi
This sounds like a sort algorithm. Something like mergesort or quicksort.
– Pablo Almeida
Friend, you solved my problem, I typed "quicksort" and it directed me to the next challenge. I would never guess this, it was just a name. My God! Thank you
– Celina Shigetomi
Accurate guess, rs.
– Pablo Almeida
That sounds like job interview challenge to me
– MarceloBoni
@Guilhermenascimento This code is Erlang. I put it working on ideone: http://ideone.com/miMswx - In fact it makes a quicksort.
– Victor Stafusa
@Victorstafusa a great addition.
– Guilherme Nascimento