Repository navigation
Recursion and stack #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Recursion and stack #485
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,11 @@ importance: 5 | |
|
|
||
| --- | ||
|
|
||
| # Sum all numbers till the given one | ||
| # Some todos os números até o dado | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Título ambíguo: "até o dado" pode ser lido como o substantivo "dado" (de jogar). Sugestão: "# Some todos os números até o número dado". |
||
|
|
||
| Write a function `sumTo(n)` that calculates the sum of numbers `1 + 2 + ... + n`. | ||
| Escreva uma função `sumTo(n)` que calcule a soma dos números `1 + 2 + ... + n`. | ||
|
|
||
| For instance: | ||
| Por exemplo: | ||
|
|
||
| ```js no-beautify | ||
| sumTo(1) = 1 | ||
|
|
@@ -17,20 +17,20 @@ sumTo(4) = 4 + 3 + 2 + 1 = 10 | |
| sumTo(100) = 100 + 99 + ... + 2 + 1 = 5050 | ||
| ``` | ||
|
|
||
| Make 3 solution variants: | ||
| Faça 3 variantes de solução: | ||
|
|
||
| 1. Using a for loop. | ||
| 2. Using a recursion, cause `sumTo(n) = n + sumTo(n-1)` for `n > 1`. | ||
| 3. Using the [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression) formula. | ||
| 1. Usando um laço for. | ||
| 2. Usando recursão, já que `sumTo(n) = n + sumTo(n-1)` para `n > 1`. | ||
| 3. Usando a fórmula da [progressão aritmética](https://pt.wikipedia.org/wiki/Progress%C3%A3o_aritm%C3%A9tica). | ||
|
|
||
| An example of the result: | ||
| Um exemplo do resultado: | ||
|
|
||
| ```js | ||
| function sumTo(n) { /*... your code ... */ } | ||
| function sumTo(n) { /*... seu código ... */ } | ||
|
|
||
| alert( sumTo(100) ); // 5050 | ||
| ``` | ||
|
|
||
| P.S. Which solution variant is the fastest? The slowest? Why? | ||
| P.S. Qual variante de solução é a mais rápida? A mais lenta? Por quê? | ||
|
|
||
| P.P.S. Can we use recursion to count `sumTo(100000)`? | ||
| P.P.S. Podemos usar recursão para calcular `sumTo(100000)`? | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ importance: 5 | |
|
|
||
| --- | ||
|
|
||
| # Output a single-linked list | ||
| # Exiba uma lista encadeada simples | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Terminologia inconsistente: o artigo traduz "linked list" como "lista ligada", mas as tarefas 04 e 05 usam "lista encadeada simples". A linha 7 diz "como descrito no capítulo info:recursion", só que o capítulo nunca usa "encadeada". Sugiro escolher um único termo nos 3 arquivos (por exemplo, "lista ligada simples"). |
||
|
|
||
| Let's say we have a single-linked list (as described in the chapter <info:recursion>): | ||
| Digamos que temos uma lista encadeada simples (como descrito no capítulo <info:recursion>): | ||
|
|
||
| ```js | ||
| let list = { | ||
|
|
@@ -22,8 +22,8 @@ let list = { | |
| }; | ||
| ``` | ||
|
|
||
| Write a function `printList(list)` that outputs list items one-by-one. | ||
| Escreva uma função `printList(list)` que exiba os itens da lista um por um. | ||
|
|
||
| Make two variants of the solution: using a loop and using recursion. | ||
| Faça duas variantes da solução: usando um laço e usando recursão. | ||
|
|
||
| What's better: with recursion or without it? | ||
| O que é melhor: com recursão ou sem ela? | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A frase repete "então" duas vezes ("...não vai precisar retomar a execução, então o motor..."), o que dificulta a leitura. Sugestão: "...não vai precisar retomar a execução e, portanto, o motor não precisa lembrar seu contexto de execução."