chore(i18n,curriculum): processed translations (#42868)
This commit is contained in:
@ -11,7 +11,7 @@ dashedName: create-decimal-numbers-with-javascript
|
||||
|
||||
我們也可以把小數存儲到變量中。 小數有時候也被稱作<dfn>浮點數</dfn>或者 <dfn>floats</dfn>。
|
||||
|
||||
**提示:** 不是所有的實數都可以用浮點數(<dfn>floating point</dfn>)來表示。 因爲可能產生四捨五入的錯誤, [查看詳情](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)。
|
||||
**提示:** 不是所有的實數都可以用浮點數(<dfn>floating point</dfn>)來表示。 因爲可能產生四捨五入的錯誤, [點擊這裏瞭解細節](https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems)。
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -26,13 +26,15 @@ name=John+Doe&age=25
|
||||
|
||||
# --instructions--
|
||||
|
||||
在 `package.json` 中安裝 `body-parser` 模塊, 然後在文件頂部 `require` 進來, 用變量 `bodyParser` 保存它。 通過中間件的 `bodyParser.urlencoded({extended: false})` 方法處理 URL 編碼數據, 將調用上個方法返回的函數傳給 `app.use()`, 中間件通常掛載在所有需要它的路由之前。
|
||||
在 `package.json` 中安裝 `body-parser` 模塊, 然後在文件頂部 `require` 進來, 用變量 `bodyParser` 保存它。 通過中間件的 `bodyParser.urlencoded({extended: false})` 方法處理 URL 編碼數據, Pass the function returned by the previous method call to `app.use()`. As usual, the middleware must be mounted before all the routes that depend on it.
|
||||
|
||||
**注意:**`extended=false` 是一個告訴解析器使用經典編碼的配置選項, 當使用它時,值只能是字符串或者數組, 拓展版本數據更加靈活,但稍遜於 JSON。
|
||||
**Note:** `extended` is a configuration option that tells `body-parser` which parsing needs to be used. When `extended=false` it uses the classic encoding `querystring` library. When `extended=true` it uses `qs` library for parsing.
|
||||
|
||||
When using `extended=false`, values can be only strings or arrays. The object returned when using `querystring` does not prototypically inherit from the default JavaScript `Object`, which means functions like `hasOwnProperty`, `toString` will not be available. The extended version allows more data flexibility, but it is outmatched by JSON.
|
||||
|
||||
# --hints--
|
||||
|
||||
應該掛載“body-parser”中間件
|
||||
The 'body-parser' middleware should be mounted
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c14d
|
||||
title: Data Analysis Example A
|
||||
title: 數據分析 案例 A
|
||||
challengeType: 11
|
||||
videoId: nVAaxZ34khk
|
||||
dashedName: data-analysis-example-a
|
||||
@ -8,34 +8,34 @@ dashedName: data-analysis-example-a
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/FreeCodeCamp-Pandas-Real-Life-Example)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/FreeCodeCamp-Pandas-Real-Life-Example)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What does the shape of our dataframe tell us?
|
||||
數據框架的形狀表示了什麼意義?從中我們又能夠了解到什麼?
|
||||
|
||||
## --answers--
|
||||
|
||||
The size in gigabytes the dataframe we loaded into memory is.
|
||||
我們加載到內存中的數據幀大小爲千兆字節。
|
||||
|
||||
---
|
||||
|
||||
How many rows and columns our dataframe has.
|
||||
我們的數據框架有多少行和多少列?
|
||||
|
||||
---
|
||||
|
||||
How many rows the source data had before loading.
|
||||
在加載數據前,源數據中有多少行?
|
||||
|
||||
---
|
||||
|
||||
How many columns the source data had before loading.
|
||||
在加載數據前,源數據中有多少列?
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: data-analysis-example-b
|
||||
|
||||
# --description--
|
||||
|
||||
*您可以使用 Google Colab,而不是像視頻中顯示的那樣使用 notebooks.ai。*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
更多資源:
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c160
|
||||
title: Data Cleaning and Visualizations
|
||||
title: 數據清理和可視化
|
||||
challengeType: 11
|
||||
videoId: mHjxzFS5_Z0
|
||||
dashedName: data-cleaning-and-visualizations
|
||||
@ -8,18 +8,18 @@ dashedName: data-cleaning-and-visualizations
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/data-cleaning-rmotr-freecodecamp)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/data-cleaning-rmotr-freecodecamp)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
When using Matplotlib's global API, what does the order of numbers mean here?
|
||||
當使用 Matplotlib 的全局 API 時,數字的順序在這裏意味着什麼?
|
||||
|
||||
```py
|
||||
plt.subplot(1, 2, 1)
|
||||
@ -27,15 +27,15 @@ plt.subplot(1, 2, 1)
|
||||
|
||||
## --answers--
|
||||
|
||||
My figure will have one column, two rows, and I am going to start drawing in the first (left) plot.
|
||||
這裏將創建一個圖像包括一列、兩行,並且我將開始在第一個圖(左)繪圖。
|
||||
|
||||
---
|
||||
|
||||
I am going to start drawing in the first (left) plot, my figure will have two rows, and my figure will have one column.
|
||||
我將開始在第一個圖表(左)繪圖,同時我的圖像將有兩行,也將有一列。
|
||||
|
||||
---
|
||||
|
||||
My figure will have one row, two columns, and I am going to start drawing in the first (left) plot.
|
||||
這裏將創建一個圖像包括一行、兩列,並且我將開始在第一個圖表(左)繪圖。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c15f
|
||||
title: Data Cleaning Duplicates
|
||||
title: 數據 清理重複項
|
||||
challengeType: 11
|
||||
videoId: kj7QqjXhH6A
|
||||
dashedName: data-cleaning-duplicates
|
||||
@ -8,30 +8,30 @@ dashedName: data-cleaning-duplicates
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/data-cleaning-rmotr-freecodecamp)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/data-cleaning-rmotr-freecodecamp)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
The Python method `.duplicated()` returns a boolean Series for your DataFrame. `True` is the return value for rows that:
|
||||
Python 方法 `.duplicated()` 將針對你的 DataFrame 返回一個儲存着布爾值的 Series。 `True` 是行的返回值:
|
||||
|
||||
## --answers--
|
||||
|
||||
contain a duplicate, where the value for the row contains the first occurrence of that value.
|
||||
包含一個重複值,並且它表示了在這一行這一重複值第一次出現。
|
||||
|
||||
---
|
||||
|
||||
contain a duplicate, where the value for the row is at least the second occurrence of that value.
|
||||
包含一個重複值,並且它表示了在這一行這一重複值至少第二次出現。
|
||||
|
||||
---
|
||||
|
||||
contain a duplicate, where the value for the row contains either the first or second occurrence.
|
||||
包含一個重複值,並且它表示了在這一行這一重複值第一次或第二次出現。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: data-cleaning-introduction
|
||||
|
||||
# --description--
|
||||
|
||||
*您可以使用 Google Colab,而不是像視頻中顯示的那樣使用 notebooks.ai。*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
以下有更多的資料:
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c15e
|
||||
title: Data Cleaning with DataFrames
|
||||
title: DataFrames 中的數據清理
|
||||
challengeType: 11
|
||||
videoId: sTMN_pdI6S0
|
||||
dashedName: data-cleaning-with-dataframes
|
||||
@ -8,18 +8,18 @@ dashedName: data-cleaning-with-dataframes
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/data-cleaning-rmotr-freecodecamp)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/data-cleaning-rmotr-freecodecamp)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
import pandas as pd
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c14f
|
||||
title: How to use Jupyter Notebooks Intro
|
||||
title: 如何使用 Jupyter Notebook
|
||||
challengeType: 11
|
||||
videoId: h8caJq2Bb9w
|
||||
dashedName: how-to-use-jupyter-notebooks-intro
|
||||
@ -8,19 +8,18 @@ dashedName: how-to-use-jupyter-notebooks-intro
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/ds-content-interactive-jupyterlab-tutorial)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [Twitter Cheat Sheet](https://twitter.com/rmotr_com/status/1122176794696847361)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/ds-content-interactive-jupyterlab-tutorial)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What is **not** allowed in a Jupyter Notebook's cell?
|
||||
以下哪個是 Jupyter Notebook 單元格中**不**允許的?
|
||||
|
||||
## --answers--
|
||||
|
||||
@ -28,11 +27,11 @@ Markdown
|
||||
|
||||
---
|
||||
|
||||
Python code
|
||||
Python 代碼
|
||||
|
||||
---
|
||||
|
||||
An Excel sheet
|
||||
Excel 工作表
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c14c
|
||||
title: Introduction to Data Analysis
|
||||
title: 數據分析簡介
|
||||
challengeType: 11
|
||||
videoId: VJrP2FUzKP0
|
||||
dashedName: introduction-to-data-analysis
|
||||
@ -8,33 +8,32 @@ dashedName: introduction-to-data-analysis
|
||||
|
||||
# --description--
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
\- [Slides](https://docs.google.com/presentation/d/1fDpjlyMiOMJyuc7_jMekcYLPP2XlSl1eWw9F7yE7byk)
|
||||
\- [幻燈片](https://docs.google.com/presentation/d/1cUIt8b2ySz-85_ykfeuuWsurccwTAuFPn782pZBzFsU/edit?usp=sharing)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
Why should you choose R over Python for data analysis?
|
||||
以下哪一項 **不是** 數據分析的一部分?
|
||||
|
||||
## --answers--
|
||||
|
||||
It's simple to learn.
|
||||
建立統計模型和數據可視化。
|
||||
|
||||
---
|
||||
|
||||
It's better at dealing with advanced statistical methods.
|
||||
爲分析選擇所需的結論。
|
||||
|
||||
---
|
||||
|
||||
There are many powerful libraries that support R.
|
||||
修復不正確的值並刪除無效數據。
|
||||
|
||||
---
|
||||
|
||||
It's free and open source.
|
||||
將數據轉換爲適當的數據結構。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
2
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c150
|
||||
title: Jupyter Notebooks Cells
|
||||
title: Jupyter Notebooks 單元格
|
||||
challengeType: 11
|
||||
videoId: 5PPegAs9aLA
|
||||
dashedName: jupyter-notebooks-cells
|
||||
@ -8,31 +8,30 @@ dashedName: jupyter-notebooks-cells
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/ds-content-interactive-jupyterlab-tutorial)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [Twitter Cheat Sheet](https://twitter.com/rmotr_com/status/1122176794696847361)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/ds-content-interactive-jupyterlab-tutorial)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What are the three main types of Jupyter Notebook Cell?
|
||||
Jupyter Notebook 單元格支持的三種主要類型是什麼?
|
||||
|
||||
## --answers--
|
||||
|
||||
Code, Markdown, and Python
|
||||
Code、Markdown 和 Python
|
||||
|
||||
---
|
||||
|
||||
Code, Markdown, and Raw
|
||||
Code、Markdown 和 Raw
|
||||
|
||||
---
|
||||
|
||||
Markdown, Python, and Raw
|
||||
Markdown、Python 和 Raw
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c151
|
||||
title: Jupyter Notebooks Importing and Exporting Data
|
||||
title: 在 Jupyter Notebooks 中導入和導出數據
|
||||
challengeType: 11
|
||||
videoId: k1msxD3JIxE
|
||||
dashedName: jupyter-notebooks-importing-and-exporting-data
|
||||
@ -8,39 +8,38 @@ dashedName: jupyter-notebooks-importing-and-exporting-data
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/ds-content-interactive-jupyterlab-tutorial)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [Twitter Cheat Sheet](https://twitter.com/rmotr_com/status/1122176794696847361)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/ds-content-interactive-jupyterlab-tutorial)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What kind of data can you import and work with in a Jupyter Notebook?
|
||||
你可以在 Jupyter Notebook 中導入和使用什麼樣的數據?
|
||||
|
||||
## --answers--
|
||||
|
||||
Excel files.
|
||||
Excel 文件。
|
||||
|
||||
---
|
||||
|
||||
CSV files.
|
||||
CSV 文件。
|
||||
|
||||
---
|
||||
|
||||
XML files.
|
||||
XML 文件
|
||||
|
||||
---
|
||||
|
||||
Data from an API.
|
||||
來自 API 的數據
|
||||
|
||||
---
|
||||
|
||||
All of the above.
|
||||
以上全部內容
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c157
|
||||
title: Numpy Algebra and Size
|
||||
title: Numpy 代數和大小
|
||||
challengeType: 11
|
||||
videoId: XAT97YLOKD8
|
||||
dashedName: numpy-algebra-and-size
|
||||
@ -8,34 +8,34 @@ dashedName: numpy-algebra-and-size
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What is the relationship between size of objects (such as lists and datatypes) in memory in Python's standard library and the NumPy library? Knowing this, what are the implications for performance?
|
||||
內存中,對象的大小(例如列表和數據類型)在 Python 標準庫和 NumPy 庫之間有什麼關係? 知道這一點,對性能有何影響?
|
||||
|
||||
## --answers--
|
||||
|
||||
Standard Python objects take up much more memory to store than NumPy objects; operations on comparable standard Python and NumPy objects complete in roughly the same time.
|
||||
標準的 Python 對象佔用了比 NumPy 對象更多的內存;標準的 Python 和 NumPy 對象完成的操作時間是大致相同的。
|
||||
|
||||
---
|
||||
|
||||
NumPy objects take up much more memory than standard Python objects; operations on NumPy objects complete very quickly compared to comparable objects in standard Python.
|
||||
Numpy 對象比標準的 Python 對象佔用更多的內存;Numpy 的對象相比較標準的 Python 更快地完成操作。
|
||||
|
||||
---
|
||||
|
||||
NumPy objects take up much less memory than Standard Python objects; operations on Standard Python objects complete very quickly compared to comparable objects on NumPy Object.
|
||||
Numpy 對象比標準的 Python 對象佔用更少的內存;標準 Python 的對象相比較 Numpy 的對象更快地完成操作。
|
||||
|
||||
---
|
||||
|
||||
Standard Python objects take up more memory than NumPy objects; operations on NumPy objects complete very quickly compared to comparable objects in standard Python.
|
||||
標準 Python 的對象比 Numpy 的對象佔用更多的內存;Numpy 的對象相比較標準 Python 的對象更快地完成操作。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c154
|
||||
title: Numpy Arrays
|
||||
title: Numpy 數組
|
||||
challengeType: 11
|
||||
videoId: VDYVFHBL1AM
|
||||
dashedName: numpy-arrays
|
||||
@ -8,18 +8,18 @@ dashedName: numpy-arrays
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
A = np.array([
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c156
|
||||
title: Numpy Boolean Arrays
|
||||
title: Numpy 布爾值的數組
|
||||
challengeType: 11
|
||||
videoId: N1ttsMmcVMM
|
||||
dashedName: numpy-boolean-arrays
|
||||
@ -8,18 +8,18 @@ dashedName: numpy-boolean-arrays
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
a = np.arange(5)
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c152
|
||||
title: Numpy Introduction A
|
||||
title: Numpy 簡介 A
|
||||
challengeType: 11
|
||||
videoId: P-JjV6GBCmk
|
||||
dashedName: numpy-introduction-a
|
||||
@ -8,30 +8,30 @@ dashedName: numpy-introduction-a
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
Why is Numpy an important, but unpopular Python library?
|
||||
爲什麼 Numpy 是一個重要的卻又不流行的 Python 庫?
|
||||
|
||||
## --answers--
|
||||
|
||||
Often you won't work directly with Numpy.
|
||||
你常常不會直接使用 Numpy。
|
||||
|
||||
---
|
||||
|
||||
It is extremely slow.
|
||||
它是極其緩慢的。
|
||||
|
||||
---
|
||||
|
||||
Working with Numpy is difficult.
|
||||
使用 Numpy 的難度是很大的。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c153
|
||||
title: Numpy Introduction B
|
||||
title: Numpy 簡介 B
|
||||
challengeType: 11
|
||||
videoId: YIqgrNLAZkA
|
||||
dashedName: numpy-introduction-b
|
||||
@ -8,34 +8,34 @@ dashedName: numpy-introduction-b
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
About how much memory does the integer `5` consume in plain Python?
|
||||
整數 `5` 在 Python 中消耗多少內存?
|
||||
|
||||
## --answers--
|
||||
|
||||
32 bits
|
||||
32 位
|
||||
|
||||
---
|
||||
|
||||
20 bytes
|
||||
20 字節
|
||||
|
||||
---
|
||||
|
||||
16 bytes
|
||||
16 字節
|
||||
|
||||
---
|
||||
|
||||
8 bits
|
||||
8 位
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c155
|
||||
title: Numpy Operations
|
||||
title: Numpy 的運算
|
||||
challengeType: 11
|
||||
videoId: eqSVcJbaPdk
|
||||
dashedName: numpy-operations
|
||||
@ -8,18 +8,18 @@ dashedName: numpy-operations
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-numpy)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What is the value of `a` after you run the following code?
|
||||
運行以下代碼後, `a` 的值是多少?
|
||||
|
||||
```py
|
||||
a = np.arange(5)
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c15b
|
||||
title: Pandas Conditional Selection and Modifying DataFrames
|
||||
title: Pandas 條件選擇和 DataFrames 的修改
|
||||
challengeType: 11
|
||||
videoId: BFlH0fN5xRQ
|
||||
dashedName: pandas-conditional-selection-and-modifying-dataframes
|
||||
@ -8,18 +8,18 @@ dashedName: pandas-conditional-selection-and-modifying-dataframes
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
import pandas as pd
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c15c
|
||||
title: Pandas Creating Columns
|
||||
title: Pandas 創建列
|
||||
challengeType: 11
|
||||
videoId: _sSo2XZoB3E
|
||||
dashedName: pandas-creating-columns
|
||||
@ -8,18 +8,18 @@ dashedName: pandas-creating-columns
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What code would add a "Certificates per month" column to the `certificates_earned` DataFrame like the one below?
|
||||
哪段代碼可以向 DataFrame `certificates_earned` 中添加一個 “Certificates per month” 列,就像下面所展示的?
|
||||
|
||||
<pre> Certificates Time (in months) Certificates per month
|
||||
Tom 8 16 0.50
|
||||
|
@ -8,18 +8,18 @@ dashedName: pandas-dataframes
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
import pandas as pd
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c159
|
||||
title: Pandas Indexing and Conditional Selection
|
||||
title: Pandas 索引和條件選擇
|
||||
challengeType: 11
|
||||
videoId: '-ZOrgV_aA9A'
|
||||
dashedName: pandas-indexing-and-conditional-selection
|
||||
@ -8,18 +8,18 @@ dashedName: pandas-indexing-and-conditional-selection
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
import pandas as pd
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c158
|
||||
title: Pandas Introduction
|
||||
title: Pandas 簡介
|
||||
challengeType: 11
|
||||
videoId: 0xACW-8cZU0
|
||||
dashedName: pandas-introduction
|
||||
@ -8,18 +8,18 @@ dashedName: pandas-introduction
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/freecodecamp-intro-to-pandas)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print out?
|
||||
以下代碼會打印出什麼?
|
||||
|
||||
```py
|
||||
import pandas as pd
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c164
|
||||
title: Parsing HTML and Saving Data
|
||||
title: 解析 HTML 和保存數據
|
||||
challengeType: 11
|
||||
videoId: bJaqnTWQmb0
|
||||
dashedName: parsing-html-and-saving-data
|
||||
@ -8,18 +8,18 @@ dashedName: parsing-html-and-saving-data
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas/tree/master/unit-1-reading-data-with-python-and-pandas/lesson-17-reading-html-tables/files)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What Python library has the `.read_html()` method we can we use for parsing HTML documents and extracting tables?
|
||||
爲了解析 HTML 文本和提取表格,`.read_html()` 位於哪個 Python 的庫?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c166
|
||||
title: Python Functions and Collections
|
||||
title: Python 函數和集合
|
||||
challengeType: 11
|
||||
videoId: NzpU17ZVlUw
|
||||
dashedName: python-functions-and-collections
|
||||
@ -8,30 +8,30 @@ dashedName: python-functions-and-collections
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/ds-content-python-under-10-minutes)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/ds-content-python-under-10-minutes)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What is the main difference between lists and tuples in Python?
|
||||
在 Python 中,列表和元組有什麼主要的區別?
|
||||
|
||||
## --answers--
|
||||
|
||||
Tuples are immutable.
|
||||
元組是不可改變的。
|
||||
|
||||
---
|
||||
|
||||
Lists are ordered.
|
||||
列表是有順序的。
|
||||
|
||||
---
|
||||
|
||||
Tuples are unordered.
|
||||
元組是無序的。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c165
|
||||
title: Python Introduction
|
||||
title: Python 簡介
|
||||
challengeType: 11
|
||||
videoId: PrQV9JkLhb4
|
||||
dashedName: python-introduction
|
||||
@ -8,34 +8,34 @@ dashedName: python-introduction
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/ds-content-python-under-10-minutes)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/ds-content-python-under-10-minutes)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
How do we define blocks of code in the body of functions in Python?
|
||||
我們如何在 Python 函數中定義代碼塊?
|
||||
|
||||
## --answers--
|
||||
|
||||
We use a set of curly braces, one on either side of each new block of our code.
|
||||
我們可以在代碼的每個新區塊的兩側使用一組大括號。
|
||||
|
||||
---
|
||||
|
||||
We use indentation, usually right-aligned 4 spaces.
|
||||
我們使用縮進,通常是右對齊的 4 個空格。
|
||||
|
||||
---
|
||||
|
||||
We do not denote blocks of code.
|
||||
我們不用指示出代碼塊。
|
||||
|
||||
---
|
||||
|
||||
We could use curly braces or indentation to denote blocks of code.
|
||||
我們可以使用大括號或縮進來指示出代碼塊。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c167
|
||||
title: Python Iteration and Modules
|
||||
title: Python 迭代和模塊
|
||||
challengeType: 11
|
||||
videoId: XzosGWLafrY
|
||||
dashedName: python-iteration-and-modules
|
||||
@ -8,18 +8,18 @@ dashedName: python-iteration-and-modules
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
更多資源:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/ds-content-python-under-10-minutes)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/ds-content-python-under-10-minutes)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
How would you iterate over and print the keys and values of a dictionary named `user`?
|
||||
您將如何迭代並打印名爲 `user` 的字典的鍵和值?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c162
|
||||
title: Reading Data CSV and TXT
|
||||
title: 從 CSV 和 TXT 中讀取數據
|
||||
challengeType: 11
|
||||
videoId: ViGEv0zOzUk
|
||||
dashedName: reading-data-csv-and-txt
|
||||
@ -8,18 +8,18 @@ dashedName: reading-data-csv-and-txt
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas/tree/master/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
How would you import the CSV file `data.csv` and store it in a DataFrame using the Pandas module?
|
||||
你如何使用 Pandas 模塊導入 CSV 文件 `data.csv` 並且存儲到 DataFrame 中?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c163
|
||||
title: Reading Data from Databases
|
||||
title: 從數據庫中讀取數據
|
||||
challengeType: 11
|
||||
videoId: MtgXS1MofRw
|
||||
dashedName: reading-data-from-databases
|
||||
@ -8,30 +8,30 @@ dashedName: reading-data-from-databases
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas/tree/master/unit-1-reading-data-with-python-and-pandas/lesson-11-reading-data-from-relational-databases/files)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
What method does a `Cursor` instance have and what does it allow?
|
||||
`Cursor` 實例中都有什麼方法,這些方法能用來做什麼?
|
||||
|
||||
## --answers--
|
||||
|
||||
The `Cursor` instance has a `.run()` method which allows you to run SQL queries.
|
||||
`Cursor` 實例中有方法 `.run()` ,它允許你運行 SQL 查詢語句。
|
||||
|
||||
---
|
||||
|
||||
The `Cursor` instance has a `.select()` method which allows you to select records.
|
||||
`Cursor` 實例中有方法 `.select()` ,它允許你選擇記錄。
|
||||
|
||||
---
|
||||
|
||||
The `Cursor` instance has an `.execute()` method which will receive SQL parameters to run against the database.
|
||||
`Cursor` 實例有方法 `.execute()` , 它能夠接收在數據庫中運行的 SQL 參數。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a093a74c4063ca6f7c161
|
||||
title: Reading Data Introduction
|
||||
title: 讀取數據簡介
|
||||
challengeType: 11
|
||||
videoId: cDnt02BcHng
|
||||
dashedName: reading-data-introduction
|
||||
@ -8,18 +8,18 @@ dashedName: reading-data-introduction
|
||||
|
||||
# --description--
|
||||
|
||||
*Instead of using notebooks.ai like it shows in the video, you can use Google Colab instead.*
|
||||
*在視頻中我們使用的編輯器工具是在 notebook.ai 這個平臺,你也可以選擇用其他的平臺,比如說 Google Colab 也是一個不錯的選擇。*
|
||||
|
||||
More resources:
|
||||
以下有更多的資料:
|
||||
|
||||
- [Notebooks on GitHub](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas)
|
||||
- [How to open Notebooks from GitHub using Google Colab.](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
- [在 GitHub 平臺的 Notebooks](https://github.com/ine-rmotr-curriculum/RDP-Reading-Data-with-Python-and-Pandas/tree/master/unit-1-reading-data-with-python-and-pandas/lesson-1-reading-csv-and-txt-files/files)
|
||||
- [如何使用 Google Colab 來打開 GitHub 上的 Notebooks](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
|
||||
|
||||
# --question--
|
||||
|
||||
## --text--
|
||||
|
||||
Given a file named `certificates.csv` with these contents:
|
||||
文件 `certificates.csv` 有以下內容:
|
||||
|
||||
<pre>
|
||||
Name$Certificates$Time (in months)
|
||||
@ -29,7 +29,7 @@ Ahmad$5$9
|
||||
Beau$6$12
|
||||
</pre>
|
||||
|
||||
Fill in the blanks for the missing arguments below:
|
||||
請填寫以下缺失的參數:
|
||||
|
||||
```py
|
||||
import csv
|
||||
|
@ -1,23 +1,24 @@
|
||||
---
|
||||
id: 5e46f7e5ac417301a38fb929
|
||||
title: Demographic Data Analyzer
|
||||
title: 人口統計數據分析器
|
||||
challengeType: 10
|
||||
forumTopicId: 462367
|
||||
dashedName: demographic-data-analyzer
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this challenge you must analyze demographic data using Pandas. You are given a dataset of demographic data that was extracted from the 1994 Census database.
|
||||
在這個挑戰中,你必須使用 Pandas 對人口統計進行分析。 你將獲得從 1994 年人口普查數據庫中提取的人口統計數據數據集。
|
||||
|
||||
You can access [the full project description and starter code on Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-demographic-data-analyzer).
|
||||
你可以[在 Replit 上查看整個項目的具體描述和初始代碼](https://replit.com/github/freeCodeCamp/boilerplate-demographic-data-analyzer)。
|
||||
|
||||
After going to that link, fork the project. Once you complete the project based on the instructions in 'README.md', submit your project link below.
|
||||
點擊此鏈接,fork 這個項目。 一旦你根據 “README.md” 中的說明完成項目,請提交你的項目鏈接到下面。
|
||||
|
||||
We are still developing the interactive instructional part of the data analysis with Python curriculum. For now, you will have to use other resources to learn how to pass this challenge.
|
||||
我們仍在開發 Python 數據分析課程的交互式教學。 現在,你需要使用其他資源來學習如何通過這一挑戰。
|
||||
|
||||
# --hints--
|
||||
|
||||
It should pass all Python tests.
|
||||
它應該通過所有的 Python 測試。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,23 +1,24 @@
|
||||
---
|
||||
id: 5e46f7f8ac417301a38fb92a
|
||||
title: Medical Data Visualizer
|
||||
title: 醫療數據可視化工具
|
||||
challengeType: 10
|
||||
forumTopicId: 462368
|
||||
dashedName: medical-data-visualizer
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this project, you will visualize and make calculations from medical examination data using matplotlib, seaborn, and pandas.
|
||||
在這個項目中,你將要使用 matplotlib,seaborn 和 pandas 來對健康檢查數據進行數據可視化和計算。
|
||||
|
||||
You can access [the full project description and starter code on Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-medical-data-visualizer).
|
||||
你可以[在 Replit 上查看整個項目的具體描述和初始代碼](https://replit.com/github/freeCodeCamp/boilerplate-medical-data-visualizer)。
|
||||
|
||||
After going to that link, fork the project. Once you complete the project based on the instructions in 'README.md', submit your project link below.
|
||||
打開此鏈接後,fork 這個項目。 一旦你根據 “README.md” 中的說明完成項目,請提交你的項目到下面的鏈接。
|
||||
|
||||
We are still developing the interactive instructional part of the data analysis with Python curriculum. For now, you will have to use other resources to learn how to pass this challenge.
|
||||
我們仍在開發 Python 數據分析課程的交互式課程部分。 現在,你需要使用其他資源來學習如何通過這一挑戰。
|
||||
|
||||
# --hints--
|
||||
|
||||
It should pass all Python tests.
|
||||
它應該通過所有的 Python 測試。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,23 +1,24 @@
|
||||
---
|
||||
id: 5e46f802ac417301a38fb92b
|
||||
title: Page View Time Series Visualizer
|
||||
title: 頁面訪問量的時間序列可視化工具
|
||||
challengeType: 10
|
||||
forumTopicId: 462369
|
||||
dashedName: page-view-time-series-visualizer
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
For this project you will visualize time series data using a line chart, bar chart, and box plots. You will use Pandas, matplotlib, and seaborn to visualize a dataset containing the number of page views each day on the freeCodeCamp.org forum from 2016-05-09 to 2019-12-03. The data visualizations will help you understand the patterns in visits and identify yearly and monthly growth.
|
||||
對於這個項目,你將使用線圖、條形圖和箱形圖對時間序列數據進行可視化。 你將要使用 Pandas、matplotlib 和 seaborn 來對數據集進行可視化,這個數據集包含從 2016-05-09 到 2019-12-03 每一天在 freeCodeCamp.org 論壇的頁面訪問量。 這個數據可視化將幫助你瞭解訪問的模式,並且顯示年增長和月增長情況。
|
||||
|
||||
You can access [the full project description and starter code on Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-page-view-time-series-visualizer).
|
||||
你可以 [在 Replit 上查看整個項目的具體描述和初始代碼](https://replit.com/github/freeCodeCamp/boilerplate-page-view-time-series-visualizer)。
|
||||
|
||||
After going to that link, fork the project. Once you complete the project based on the instructions in 'README.md', submit your project link below.
|
||||
點擊此鏈接,fork 這個項目。 一旦你根據 “README.md” 中的說明完成項目,請提交你的項目到下面的鏈接。
|
||||
|
||||
We are still developing the interactive instructional part of the data analysis with Python curriculum. For now, you will have to use other resources to learn how to pass this challenge.
|
||||
我們仍在開發 Python 數據分析課程的交互式課程部分。 現在,你將需要使用其他資源來學習如何通過這一挑戰。
|
||||
|
||||
# --hints--
|
||||
|
||||
It should pass all Python tests.
|
||||
它應該通過所有的 Python 測試。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,23 +1,24 @@
|
||||
---
|
||||
id: 5e4f5c4b570f7e3a4949899f
|
||||
title: Sea Level Predictor
|
||||
title: 海平面預報器
|
||||
challengeType: 10
|
||||
forumTopicId: 462370
|
||||
dashedName: sea-level-predictor
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this project, you will analyze a dataset of the global average sea level change since 1880. You will use the data to predict the sea level change through year 2050.
|
||||
在本項目中,您將分析自 1880 年以來全球平均海平面變化的數據集。 您將使用這些數據來預測到 2050 年的海平面變化。
|
||||
|
||||
You can access [the full project description and starter code on Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-sea-level-predictor).
|
||||
你可以在 [Replit 上查看整個項目的具體描述和初始代碼](https://replit.com/github/freeCodeCamp/boilerplate-sea-level-predictor)。
|
||||
|
||||
After going to that link, fork the project. Once you complete the project based on the instructions in 'README.md', submit your project link below.
|
||||
打開此鏈接後,fork 這個項目。 一旦你根據 “README.md” 中的說明完成項目,請提交你的項目到下面的鏈接。
|
||||
|
||||
We are still developing the interactive instructional part of the data analysis with Python curriculum. For now, you will have to use other resources to learn how to pass this challenge.
|
||||
我們仍在開發 Python 數據分析課程的交互式課程部分。 現在,你需要使用其他資源來學習如何通過這一挑戰。
|
||||
|
||||
# --hints--
|
||||
|
||||
It should pass all Python tests.
|
||||
它應該通過所有的 Python 測試。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed4
|
||||
title: 'Accessing and Changing Elements, Rows, Columns'
|
||||
title: '訪問與更改元素、行和列'
|
||||
challengeType: 11
|
||||
videoId: v-7Y7koJ_N0
|
||||
dashedName: accessing-and-changing-elements-rows-columns
|
||||
@ -10,7 +10,7 @@ dashedName: accessing-and-changing-elements-rows-columns
|
||||
|
||||
## --text--
|
||||
|
||||
What code would change the values in the 3rd column of both of the following Numpy arrays to 20?
|
||||
以下哪行代碼將下面的 Numpy 數組的第三行的數值都更改成 20?
|
||||
|
||||
```py
|
||||
a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed3
|
||||
title: Basics of Numpy
|
||||
title: Numpy 的基礎知識
|
||||
challengeType: 11
|
||||
videoId: f9QrZrKQMLI
|
||||
dashedName: basics-of-numpy
|
||||
@ -10,7 +10,7 @@ dashedName: basics-of-numpy
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print?
|
||||
以下代碼將打印出什麼?
|
||||
|
||||
```python
|
||||
b = np.array([[1.0,2.0,3.0],[3.0,4.0,5.0]])
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed7
|
||||
title: Copying Arrays Warning
|
||||
title: 複製數組警告
|
||||
challengeType: 11
|
||||
videoId: iIoQ0_L0GvA
|
||||
dashedName: copying-arrays-warning
|
||||
@ -10,7 +10,7 @@ dashedName: copying-arrays-warning
|
||||
|
||||
## --text--
|
||||
|
||||
What is the value of `a` after running the following code?
|
||||
運行以下代碼後, `a` 的值是多少?
|
||||
|
||||
```py
|
||||
import numpy as np
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed6
|
||||
title: Initialize Array Problem
|
||||
title: 初始化數組問題
|
||||
challengeType: 11
|
||||
videoId: 0jGfH8BPfOk
|
||||
dashedName: initialize-array-problem
|
||||
@ -10,7 +10,7 @@ dashedName: initialize-array-problem
|
||||
|
||||
## --text--
|
||||
|
||||
What is another way to produce the following array?
|
||||
產生以下數組的另一種方式是什麼?
|
||||
|
||||
```py
|
||||
[[0. 0. 0. 0. 0. 0. 0.]
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed5
|
||||
title: Initializing Different Arrays
|
||||
title: 初始化不同的數組
|
||||
challengeType: 11
|
||||
videoId: CEykdsKT4U4
|
||||
dashedName: initializing-different-arrays
|
||||
@ -10,7 +10,7 @@ dashedName: initializing-different-arrays
|
||||
|
||||
## --text--
|
||||
|
||||
What will the following code print?
|
||||
以下代碼將打印出什麼?
|
||||
|
||||
```py
|
||||
a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed8
|
||||
title: Mathematics
|
||||
title: 數學
|
||||
challengeType: 11
|
||||
videoId: 7txegvyhtVk
|
||||
dashedName: mathematics
|
||||
@ -10,7 +10,7 @@ dashedName: mathematics
|
||||
|
||||
## --text--
|
||||
|
||||
What is the value of `b` after running the following code?
|
||||
運行以下代碼後, `b` 的值是多少?
|
||||
|
||||
```py
|
||||
import numpy as np
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e9a0a8e09c5df3cc3600ed9
|
||||
title: Reorganizing Arrays
|
||||
title: 重組數組
|
||||
challengeType: 11
|
||||
videoId: VNWAQbEM-C8
|
||||
dashedName: reorganizing-arrays
|
||||
@ -10,7 +10,7 @@ dashedName: reorganizing-arrays
|
||||
|
||||
## --text--
|
||||
|
||||
What code would produce the following array?
|
||||
哪個代碼會生成下面的數組?
|
||||
|
||||
```py
|
||||
[[1. 1.]
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d824a367417b2b2512c45
|
||||
title: Anonymous Message Board
|
||||
title: 匿名留言板
|
||||
challengeType: 4
|
||||
forumTopicId: 301568
|
||||
dashedName: anonymous-message-board
|
||||
@ -8,38 +8,38 @@ dashedName: anonymous-message-board
|
||||
|
||||
# --description--
|
||||
|
||||
Build a full stack JavaScript app that is functionally similar to this: <https://anonymous-message-board.freecodecamp.rocks/>.
|
||||
構建一個功能上與此相似的全棧式 JavaScript 應用程序:<https://anonymous-message-board.freecodecamp.rocks/>。
|
||||
|
||||
Working on this project will involve you writing your code using one of the following methods:
|
||||
在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-messageboard/) and complete your project locally.
|
||||
- Use [our repl.it starter project](https://repl.it/github/freeCodeCamp/boilerplate-project-messageboard) to complete your project.
|
||||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo.
|
||||
- 克隆[這個 GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-messageboard/) 並在本地完成你的項目。
|
||||
- 使用 [我們的 Replit 啓動項目](https://replit.com/github/freeCodeCamp/boilerplate-project-messageboard)來完成你的項目。
|
||||
- 使用一個你喜歡的站點生成器來完成項目。 需要確定包含了我們 GitHub 倉庫的所有文件。
|
||||
|
||||
When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link` field. Optionally, also submit a link to your projects source code in the `GitHub Link` field.
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --instructions--
|
||||
|
||||
1. Set `NODE_ENV` to test without quotes when ready to write tests and DB to your databases connection string (in `.env`)
|
||||
2. Recommended to create controllers/handlers and handle routing in `routes/api.js`
|
||||
3. You will add any security features to `server.js`
|
||||
1. 當準備寫測試和數據庫連接字符串時,設置`NODE_ENV`爲不帶引號的變量(在`.env`文件中)。
|
||||
2. 建議在 `routes/api.js` 中創建控制器/處理器並處理路由。
|
||||
3. 你將在 `server.js` 中添加任何安全功能。
|
||||
|
||||
Write the following tests in `tests/2_functional-tests.js`:
|
||||
在 `tests/2_functional-tests.js` 中編寫下以下測試:
|
||||
|
||||
- Creating a new thread: POST request to `/api/threads/{board}`
|
||||
- Viewing the 10 most recent threads with 3 replies each: GET request to `/api/threads/{board}`
|
||||
- Deleting a thread with the incorrect password: DELETE request to `/api/threads/{board}` with an invalid `delete_password`
|
||||
- Deleting a thread with the correct password: DELETE request to `/api/threads/{board}` with a valid `delete_password`
|
||||
- Reporting a thread: PUT request to `/api/threads/{board}`
|
||||
- Creating a new reply: POST request to `/api/replies/{board}`
|
||||
- Viewing a single thread with all replies: GET request to `/api/replies/{board}`
|
||||
- Deleting a reply with the incorrect password: DELETE request to `/api/threads/{board}` with an invalid `delete_password`
|
||||
- Deleting a reply with the correct password: DELETE request to `/api/threads/{board}` with a valid `delete_password`
|
||||
- Reporting a reply: PUT request to `/api/replies/{board}`
|
||||
- 創建一個新的主題:發送 POST 請求到 `/api/threads/{board}`。
|
||||
- 查看最近的 10 個主題,每個主題有 3 個回覆:發送 GET 請求到 `/api/threads/{board}`
|
||||
- 使用錯誤密碼刪除主題:使用錯誤的`delete_password`向`/api/threads/{board}`發出DELETE請求
|
||||
- 用正確的密碼刪除一個主題:向`/api/threads/{board}`發出DELETE請求,並提供有效的`delete_password`。
|
||||
- 報告一個主題:發送 PUT 請求到 `/api/threads/{board}`。
|
||||
- 創建一個新的回覆:發送 POST 請求到 `/api/replies/{board}`。
|
||||
- 查看一個帶有所有回覆的主題:發送 GET 請求到`/api/replies/{board}`。
|
||||
- 使用錯誤密碼刪除一個回覆:使用無效的`delete_password`向`/api/replies/{board}`發出DELETE請求。
|
||||
- 使用正確密碼刪除一個回覆:使用有效的`delete_password`向`/api/replies/{board}`發出DELETE請求。
|
||||
- 報告一個回覆:發送 PUT 請求到 `/api/replies/{board}`。
|
||||
|
||||
# --hints--
|
||||
|
||||
You can provide your own project, not the example URL.
|
||||
提交自己的項目,而不是示例的 URL。
|
||||
|
||||
```js
|
||||
(getUserInput) => {
|
||||
@ -51,7 +51,7 @@ You can provide your own project, not the example URL.
|
||||
};
|
||||
```
|
||||
|
||||
Only allow your site to be loaded in an iFrame on your own pages.
|
||||
只允許你的網站在你自己的頁面上以 iFrame 方式加載。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -61,7 +61,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
Do not allow DNS prefetching.
|
||||
不允許 DNS 預取。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -71,7 +71,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
Only allow your site to send the referrer for your own pages.
|
||||
只允許你的網站爲你自己的頁面發送 referrer 請求頭。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -81,55 +81,81 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
You can send a POST request to `/api/threads/{board}` with form data including `text` and `delete_password`. The saved database record will have at least the fields `_id`, `text`, `created_on`(date & time), `bumped_on`(date & time, starts same as `created_on`), `reported` (boolean), `delete_password`, & `replies` (array).
|
||||
你可以向 `/api/threads/{board}` 發送一個 POST 請求,其中包括 `text` 和 `delete_password` 的表單數據。 保存的數據庫記錄將至少有 `_id`、`text`、`created_on`(date & time)、`bumped_on`(date & time, starts same as `created_on`)、`reported`(布爾值)、`delete_password`、& `replies`(數組)。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
const date = new Date();
|
||||
const text = `fcc_test_${date}`;
|
||||
const deletePassword = 'delete_me';
|
||||
const data = { text, delete_password: deletePassword };
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/threads/fcc_test', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (res.ok) {
|
||||
const checkData = await fetch(url + '/api/threads/fcc_test');
|
||||
const parsed = await checkData.json();
|
||||
try {
|
||||
assert.equal(parsed[0].text, text);
|
||||
assert.isNotNull(parsed[0]._id);
|
||||
assert.equal(new Date(parsed[0].created_on).toDateString(), date.toDateString());
|
||||
assert.equal(parsed[0].bumped_on, parsed[0].created_on);
|
||||
assert.isArray(parsed[0].replies);
|
||||
} catch (err) {
|
||||
throw new Error(err.responseText || err.message);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
你可以向 `/api/replies/{board}` 發送一個 POST 請求,其中包括字段 `text`、`delete_password` & `thread_id`。 這將更新 `bumped_on` 日期到評論日期。 在主題的 `replies` 數組中,將保存一個對象,至少有 `_id`、`text`、`created_on`、`delete_password`、& `reported` 這些屬性。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a POST request to `/api/replies/{board}` with form data including `text`, `delete_password`, & `thread_id`. This will update the `bumped_on` date to the comment's date. In the thread's `replies` array, an object will be saved with at least the properties `_id`, `text`, `created_on`, `delete_password`, & `reported`.
|
||||
你可以向 `/api/threads/{board}` 發送一個 GET 請求。 返回的將是一個數組,包括論壇上最近的 10 個被回覆的主題,及每個主題最新的 3 個回帖。 `reported` 和 `delete_password` 字段將不會被髮送到客戶端。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a GET request to `/api/threads/{board}`. Returned will be an array of the most recent 10 bumped threads on the board with only the most recent 3 replies for each. The `reported` and `delete_password` fields will not be sent to the client.
|
||||
你可以向 `/api/replies/{board}?thread_id={thread_id}` 發送一個 GET 請求。 返回的將是帶有所有的回覆的整個主題,不包括與之前測試相同的客戶端字段。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a GET request to `/api/replies/{board}?thread_id={thread_id}`. Returned will be the entire thread with all its replies, also excluding the same fields from the client as the previous test.
|
||||
你可以向 `/api/threads/{board}` 發送一個 DELETE 請求,並傳遞 `thread_id` & `delete_password` 來刪除該線程。 返回的將是字符串 `incorrect password` 或 `success`。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a DELETE request to `/api/threads/{board}` and pass along the `thread_id` & `delete_password` to delete the thread. Returned will be the string `incorrect password` or `success`.
|
||||
你可以向 `/api/replies/{board}` 發送一個 DELETE 請求,並傳遞 `thread_id`、`reply_id`、& `delete_password`。 返回的將是字符串 `incorrect password` 或 `success`。 成功後,`reply_id` 的文本將更改爲 `[deleted]`。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a DELETE request to `/api/replies/{board}` and pass along the `thread_id`, `reply_id`, & `delete_password`. Returned will be the string `incorrect password` or `success`. On success, the text of the `reply_id` will be changed to `[deleted]`.
|
||||
你可以向 `/api/threads/{board}` 發送一個 PUT 請求,並傳遞 `thread_id`。 返回的將是字符串 `success`。 `thread_id` 回覆的 `reported` 值將改爲 `true`。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a PUT request to `/api/threads/{board}` and pass along the `thread_id`. Returned will be the string `success`. The `reported` value of the `thread_id` will be changed to `true`.
|
||||
你可以通過向 `/api/replies/{board}` 發送 PUT 請求並傳遞 `thread_id` & `reply_id`。 返回的將是字符串 `success`。 `reply_id` 的 `reported` 值將被改變爲 `true`。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
You can send a PUT request to `/api/replies/{board}` and pass along the `thread_id` & `reply_id`. Returned will be the string `success`. The `reported` value of the `reply_id` will be changed to `true`.
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
All 10 functional tests are complete and passing.
|
||||
所有 10 項功能測試都已完成並通過。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,33 +1,34 @@
|
||||
---
|
||||
id: 5e46f979ac417301a38fb932
|
||||
title: Port Scanner
|
||||
title: 端口掃描器
|
||||
challengeType: 10
|
||||
forumTopicId: 462372
|
||||
helpCategory: Python
|
||||
dashedName: port-scanner
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Create a port scanner using Python.
|
||||
使用 Python 創建一個端口掃描器。
|
||||
|
||||
You can access [the full project description and starter code on Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-port-scanner).
|
||||
你可以訪問 [Replit 上的完整項目描述和啓動代碼](https://replit.com/github/freeCodeCamp/boilerplate-port-scanner)。
|
||||
|
||||
After going to that link, fork the project. Once you complete the project based on the instructions in 'README.md', submit your project link below.
|
||||
在打開鏈接之後 fork 該項目。 根據 “README.md” 中的指示完成整個項目,然後在下面提交你的項目鏈接。
|
||||
|
||||
We are still developing the interactive instructional part of the Python curriculum. For now, here are some videos on the freeCodeCamp.org YouTube channel that will teach you some of the Python skills required for this project:
|
||||
Python 課程的交互式教學部分仍在開發當中。 目前,freeCodeCamp YouTube 頻道上的一些視頻將會教授你這個項目要求的一些 Python 技能。
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href='https://www.freecodecamp.org/news/python-for-everybody/'>Python for Everybody Video Course</a> (14 hours)
|
||||
<a href='https://www.freecodecamp.org/news/python-for-everybody/'>Python for Everybody 視頻課程</a>(14 小時)
|
||||
</li>
|
||||
<li>
|
||||
<a href='https://www.freecodecamp.org/news/learn-python-basics-in-depth-video-course/'>Learn Python Video Course</a> (2 hours)
|
||||
<a href='https://www.freecodecamp.org/news/learn-python-basics-in-depth-video-course/'>Learn Python 視頻課程</a>(2 小時)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
It should pass all Python tests.
|
||||
它應該通過所有的 Python 測試。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,23 +1,28 @@
|
||||
---
|
||||
id: 5e601c775ac9d0ecd8b94aff
|
||||
title: Secure Real Time Multiplayer Game
|
||||
title: 安全的實時多人遊戲
|
||||
challengeType: 4
|
||||
forumTopicId: 462375
|
||||
dashedName: secure-real-time-multiplayer-game
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Develop a 2D real time multiplayer game using the HTML Canvas API and [Socket.io](https://socket.io/) that is functionally similar to this: <https://secure-real-time-multiplayer-game.freecodecamp.rocks/>. Working on this project will involve you writing your code using one of the following methods:
|
||||
使用 HTML Canvas API 和 [Socket.io](https://socket.io/) 開發一個 2D 實時多人遊戲,其功能與此類似:<https://secure-real-time-multiplayer-game.freecodecamp.rocks/>。 在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-secure-real-time-multiplayer-game/) and complete your project locally.
|
||||
- Use [our repl.it starter project](https://repl.it/github/freeCodeCamp/boilerplate-project-secure-real-time-multiplayer-game) to complete your project.
|
||||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo.
|
||||
- 克隆[這個 GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-secure-real-time-multiplayer-game/),並在本地完成你的項目。
|
||||
- 使用[我們的 Replit 初始項目](https://replit.com/github/freeCodeCamp/boilerplate-project-secure-real-time-multiplayer-game)來完成你的項目。
|
||||
- 使用您選擇的站點生成器來完成項目。 需要確定包含了我們 GitHub 倉庫的所有文件。
|
||||
|
||||
When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link` field. Optionally, also submit a link to your project's source code in the `GitHub Link` field.
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 框中提交你的項目 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --instructions--
|
||||
|
||||
**注意** :`helmet@^3.21.3` 是用戶故事所必需的。 這意味着你需要使用以前版本的 Helmet 的文檔,瞭解如何實現用戶故事的信息。
|
||||
|
||||
# --hints--
|
||||
|
||||
You can provide your own project, not the example URL.
|
||||
提交自己的項目,而不是示例的 URL。
|
||||
|
||||
```js
|
||||
(getUserInput) => {
|
||||
@ -29,112 +34,134 @@ You can provide your own project, not the example URL.
|
||||
};
|
||||
```
|
||||
|
||||
Multiple players can connect to a server and play.
|
||||
多個玩家可以連接到一臺服務器遊玩。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
Each player has an avatar.
|
||||
每個玩家都有頭像。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
Each player is represented by an object created by the `Player` class in `Player.mjs`.
|
||||
每個玩家都由在 `Player.mjs` 中創建的 `Player` 類對象來代表。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
At a minimum, each player object should contain a unique `id`, a `score`, and `x` and `y` coordinates representing the player's current position.
|
||||
至少,每個玩家對象應該包含一個唯一的 `id`、一個 `score`,以及代表玩家當前位置的 `x` 和 `y` 座標。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
The game has at least one type of collectible item. Complete the `Collectible` class in `Collectible.mjs` to implement this.
|
||||
遊戲至少有一種類型的可收藏物品。 在 `Collectible.mjs` 中完成 `Collectible` 類來實現這一點。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
At a minimum, each collectible item object created by the `Collectible` class should contain a unique `id`, a `value`, and `x` and `y` coordinates representing the item's current position.
|
||||
至少,每個由 `Collectible` 類創建的可收集物品對象應該包含一個唯一的 `id`、一個 `value`,以及代表該物品當前位置的 `x` 和 `y` 座標。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
Players can use the WASD and/or arrow keys to move their avatar. Complete the `movePlayer` method in `Player.mjs` to implement this.
|
||||
玩家可以使用 WASD 或方向鍵移動頭像。 完成 `Player.mjs` 中的 `movePlayer` 方法來實現這一功能。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
The `movePlayer` method should accept two arguments: a string of "up", "down", "left", or "right", and a number for the amount of pixels the player's position should change. `movePlayer` should adjust the `x` and `y` coordinates of the player object it's called from.
|
||||
`movePlayer` 方法應該接受兩個參數:一個是 “up”、“down”、“left” 或 “right” 的字符串,另一個是玩家角色位置應該改變的像素數量。 `movePlayer` 應該調整它所調用的玩家對象的 `x` 和 `y` 座標。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
The player's score should be used to calculate their rank among the other players. Complete the `calculateRank` method in the `Player` class to implement this.
|
||||
用玩家的分數來計算他們相對其他玩家的名次。 在 `Player` 類中完成 `calculateRank` 方法來實現這個。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
The `calculateRank` method should accept an array of objects representing all connected players and return the string `Rank: currentRanking/totalPlayers`. For example, in a game with two players, if Player A has a score of 3 and Player B has a score of 5, `calculateRank` for Player A should return `Rank: 2/2`.
|
||||
`calculateRank` 方法應該接受一個代表所有在線玩家的對象數組,並返回字符串 `Rank: currentRanking/totalPlayers`。 例如,在一局有兩個玩家的遊戲中,如果玩家 A 的分數是 3,玩家 B 的分數是 5,那麼玩家 A 的 `calculateRank` 應該返回 `Rank: 2/2`。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
Players can collide with a collectible item. Complete the `collision` method in `Player.mjs` to implement this.
|
||||
玩家可以與可收集物品發生碰撞。 完成 `Player.mjs` 中的 `collision` 方法來實現這一點。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
The `collision` method should accept a collectible item's object as an argument. If the player's avatar intersects with the item, the `collision` method should return `true`.
|
||||
`collision` 方法應該接受一個可收集物品的對象作爲參數。 如果玩家的頭像與物品相交,`collision` 方法應該返回 `true`。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
All players are kept in sync.
|
||||
所有玩家都保持遊戲狀態同步。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
Players can disconnect from the game at any time.
|
||||
玩家可以隨時斷開與遊戲的連接。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
Prevent the client from trying to guess / sniff the MIME type.
|
||||
阻止客戶端試圖猜測/嗅探 MIME 類型。
|
||||
|
||||
```js
|
||||
|
||||
async (getUserInput) => {
|
||||
const data = await fetch(getUserInput('url') + '/_api/app-info');
|
||||
const parsed = await data.json();
|
||||
assert.equal(parsed.headers['x-content-type-options'], 'nosniff');
|
||||
};
|
||||
```
|
||||
|
||||
Prevent cross-site scripting (XSS) attacks.
|
||||
防止跨站腳本(XSS)攻擊。
|
||||
|
||||
```js
|
||||
|
||||
async (getUserInput) => {
|
||||
const data = await fetch(getUserInput('url') + '/_api/app-info');
|
||||
const parsed = await data.json();
|
||||
assert.equal(parsed.headers['x-xss-protection'], '1; mode=block');
|
||||
};
|
||||
```
|
||||
|
||||
Nothing from the website is cached in the client.
|
||||
客戶端沒有緩存任何網站內容。
|
||||
|
||||
```js
|
||||
|
||||
async (getUserInput) => {
|
||||
const data = await fetch(getUserInput('url') + '/_api/app-info');
|
||||
const parsed = await data.json();
|
||||
assert.equal(parsed.headers['surrogate-control'], 'no-store');
|
||||
assert.equal(
|
||||
parsed.headers['cache-control'],
|
||||
'no-store, no-cache, must-revalidate, proxy-revalidate'
|
||||
);
|
||||
assert.equal(parsed.headers['pragma'], 'no-cache');
|
||||
assert.equal(parsed.headers['expires'], '0');
|
||||
};
|
||||
```
|
||||
|
||||
The headers say that the site is powered by "PHP 7.4.3" even though it isn't (as a security measure).
|
||||
請求頭顯示該網站是由 “PHP 7.4.3” 驅動的,儘管實際並非如此(作爲一種安全防禦措施)。
|
||||
|
||||
```js
|
||||
|
||||
async (getUserInput) => {
|
||||
const data = await fetch(getUserInput('url') + '/_api/app-info');
|
||||
const parsed = await data.json();
|
||||
assert.equal(parsed.headers['x-powered-by'], 'PHP 7.4.3');
|
||||
};
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -1,33 +1,34 @@
|
||||
---
|
||||
id: 5e46f983ac417301a38fb933
|
||||
title: SHA-1 Password Cracker
|
||||
title: SHA-1 密碼破解器
|
||||
challengeType: 10
|
||||
forumTopicId: 462374
|
||||
helpCategory: Python
|
||||
dashedName: sha-1-password-cracker
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
For this project you will learn about the importance of good security by creating a password cracker to figure out passwords that were hashed using SHA-1.
|
||||
在這個項目中,你將通過創建一個密碼破解器來找出使用 SHA-1 散列的密碼,從而瞭解到良好安全的重要性。
|
||||
|
||||
You can access [the full project description and starter code on Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-SHA-1-password-cracker).
|
||||
你可以訪問 [Replit 上的完整項目描述和啓動代碼](https://replit.com/github/freeCodeCamp/boilerplate-SHA-1-password-cracker)。
|
||||
|
||||
After going to that link, fork the project. Once you complete the project based on the instructions in 'README.md', submit your project link below.
|
||||
進入該鏈接後,fork 該項目。 一旦你根據 “README.md” 中的說明完成了項目,請在下面提交你的項目鏈接。
|
||||
|
||||
We are still developing the interactive instructional part of the Python curriculum. For now, here are some videos on the freeCodeCamp.org YouTube channel that will teach you some of the Python skills required for this project:
|
||||
我們仍在開發 Python 課程的交互式教學部分。 目前,freeCodeCamp.org YouTube 頻道上的一些視頻可以教你這個項目所需的一些 Python 技能。
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href='https://www.freecodecamp.org/news/python-for-everybody/'>Python for Everybody Video Course</a> (14 hours)
|
||||
<a href='https://www.freecodecamp.org/news/python-for-everybody/'>Python for Everybody 視頻課程</a>(14 小時)
|
||||
</li>
|
||||
<li>
|
||||
<a href='https://www.freecodecamp.org/news/learn-python-basics-in-depth-video-course/'>Learn Python Video Course</a> (2 hours)
|
||||
<a href='https://www.freecodecamp.org/news/learn-python-basics-in-depth-video-course/'>Learn Python 視頻課程</a>(2 小時)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
It should pass all Python tests.
|
||||
它應該通過所有的 Python 測試。
|
||||
|
||||
```js
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d824a367417b2b2512c44
|
||||
title: Stock Price Checker
|
||||
title: 股票價格查看器
|
||||
challengeType: 4
|
||||
forumTopicId: 301572
|
||||
dashedName: stock-price-checker
|
||||
@ -8,36 +8,36 @@ dashedName: stock-price-checker
|
||||
|
||||
# --description--
|
||||
|
||||
Build a full stack JavaScript app that is functionally similar to this: <https://stock-price-checker.freecodecamp.rocks/>.
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://stock-price-checker.freecodecamp.rocks/>。
|
||||
|
||||
Since all reliable stock price APIs require an API key, we've built a workaround. Use <https://stock-price-checker-proxy.freecodecamp.rocks/> to get up-to-date stock price information without needing to sign up for your own key.
|
||||
由於所有可靠的股票價格 API 都需要一個 API 密鑰,我們已經建立了一個解決方案。 使用 [https://stock-price-checer-proxy.freecodecamp.rocks/](https://stock-price-checker-proxy.freecodecamp.rocks/) 獲取最新的股票價格信息,而無需註冊您自己的密鑰。
|
||||
|
||||
Working on this project will involve you writing your code using one of the following methods:
|
||||
可以採用下面的任意一種方式完成這個挑戰:
|
||||
|
||||
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-stockchecker/) and complete your project locally.
|
||||
- Use [our repl.it starter project](https://repl.it/github/freeCodeCamp/boilerplate-project-stockchecker) to complete your project.
|
||||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo.
|
||||
- 克隆 [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-stockchecker/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 啓動項目](https://replit.com/github/freeCodeCamp/boilerplate-project-stockchecker)來完成你的項目。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link` field. Optionally, also submit a link to your projects source code in the `GitHub Link` field.
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --instructions--
|
||||
|
||||
1. SET `NODE_ENV` to `test` without quotes and set `DB` to your MongoDB connection string
|
||||
2. Complete the project in `routes/api.js` or by creating a handler/controller
|
||||
3. You will add any security features to `server.js`
|
||||
4. You will create all of the functional tests in `tests/2_functional-tests.js`
|
||||
1. 將 `NODE_ENV` 設置爲 `test`,不帶引號,並將 `DB` 設爲你的 MongoDB 連接字符串。
|
||||
2. 在 `routes/api.js` 中完成項目,或者通過創建一個處理程序/控制器來完成項目
|
||||
3. 添加安全功能到 `server.js`。
|
||||
4. 在 `tests/2_functional-tests.js` 中創建所有的功能測試
|
||||
|
||||
Write the following tests in `tests/2_functional-tests.js`:
|
||||
在 `tests/2_functional-tests.js` 中編寫下以下測試:
|
||||
|
||||
- Viewing one stock: GET request to `/api/stock-prices/`
|
||||
- Viewing one stock and liking it: GET request to `/api/stock-prices/`
|
||||
- Viewing the same stock and liking it again: GET request to `/api/stock-prices/`
|
||||
- Viewing two stocks: GET request to `/api/stock-prices/`
|
||||
- Viewing two stocks and liking them: GET request to `/api/stock-prices/`
|
||||
- 查看股價:發送 GET 請求到 `/api/stock-prices/`
|
||||
- 查看一個股票並關注它:發送 GET 請求到 `/api/stock-prices/`
|
||||
- 查看同一只股票並再次發送關注:發送 GET 請求到 `/api/stock-prices/`
|
||||
- 查看兩隻股票:發送 GET 請求到 `/api/stock-prices/`
|
||||
- 查看兩隻股票並關注它:發送 GET 請求到 `/api/stock-prices/`
|
||||
|
||||
# --hints--
|
||||
|
||||
You can provide your own project, not the example URL.
|
||||
提交自己的項目,而不是示例的 URL。
|
||||
|
||||
```js
|
||||
(getUserInput) => {
|
||||
@ -47,7 +47,7 @@ You can provide your own project, not the example URL.
|
||||
};
|
||||
```
|
||||
|
||||
You should set the content security policies to only allow loading of scripts and CSS from your server.
|
||||
將內容安全策略設置爲僅允許從服務器加載腳本和 CSS。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -62,7 +62,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
You can send a `GET` request to `/api/stock-prices` with form data containing a NASDAQ stock ticker. Returned will be an object with the property `stockData`.
|
||||
你可以向 `/api/stock-prices` 發送一個 `GET` 請求,將納斯達克股票代碼賦值給 `stock` 查詢參數。 返回的對象將包含一個名爲 `stockData` 的屬性。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -74,7 +74,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
The `stockData` property includes the `stock` ticker as a string, the `price` as a number, and `likes` as a number.
|
||||
`stockData` 屬性包括字符串 `stock` 代碼、數字 `price`,以及數字 `likes`。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -89,13 +89,13 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
You can also pass along a `like` field as `true` (boolean) to have your like added to the stock(s). Only 1 like per IP should be accepted.
|
||||
你也可以用作爲 `true`(布爾值)來傳遞 `like` 字段,讓你的偏好添加到股票中。 每個 IP 應該只接受 1 個贊。
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
If you pass along 2 stocks, the returned value will be an array with information about both stocks. Instead of `likes`, it will display `rel_likes` (the difference between the likes on both stocks) for both `stockData` objects.
|
||||
如果你傳遞了兩隻股票,返回值將是一個包含這兩隻股票信息的數組。 它將會顯示對於兩個 `stockData` 對象的 `rel_likes`(兩隻股票所獲得的贊同數的區別),而不是 `likes`。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -110,7 +110,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
All 5 functional tests are complete and passing.
|
||||
所有 5 項功能測試都已完成並通過。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8248367417b2b2512c3c
|
||||
title: Ask Browsers to Access Your Site via HTTPS Only with helmet.hsts()
|
||||
title: 用 helmet.hsts() 使瀏覽器只能通過 HTTPS 訪問你的網站。
|
||||
challengeType: 2
|
||||
forumTopicId: 301573
|
||||
dashedName: ask-browsers-to-access-your-site-via-https-only-with-helmet-hsts
|
||||
@ -8,19 +8,19 @@ dashedName: ask-browsers-to-access-your-site-via-https-only-with-helmet-hsts
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
HTTP Strict Transport Security (HSTS) is a web security policy which helps to protect websites against protocol downgrade attacks and cookie hijacking. If your website can be accessed via HTTPS you can ask user’s browsers to avoid using insecure HTTP. By setting the header Strict-Transport-Security, you tell the browsers to use HTTPS for the future requests in a specified amount of time. This will work for the requests coming after the initial request.
|
||||
HTTP 嚴格傳輸安全(HSTS)是一種網絡安全策略,有助於保護網站免受協議降級攻擊和 cookie 劫持。 如果你的網站可以通過 HTTPS 訪問,你可以要求用戶的瀏覽器避免使用不安全的 HTTP。 通過設置標頭 Strict-Transport-Security,你告訴瀏覽器在指定時間內對未來的請求使用 HTTPS。 這將對初始請求之後的請求起作用。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Configure `helmet.hsts()` to use HTTPS for the next 90 days. Pass the config object `{maxAge: timeInSeconds, force: true}`. You can create a variable `ninetyDaysInSeconds = 90*24*60*60;` to use for the `timeInSeconds`. Repl.it already has hsts enabled. To override its settings you need to set the field "force" to true in the config object. We will intercept and restore the Repl.it header, after inspecting it for testing.
|
||||
配置 `helmet.hsts()` 以在未來 90 天內使用 HTTPS。 傳遞配置對象 `{maxAge: timeInSeconds, force: true}`。 你可以創建一個變量 `ninetyDaysInSeconds = 90*24*60*60;` 來用於 `timeInSeconds`。 Replit 已經啓用了 hsts。 要覆蓋它的設置,你需要在配置對象中把 “force” 字段設置爲 true。 我們將攔截並在對其進行檢查測試後恢復 Replit 請求頭。
|
||||
|
||||
Note: Configuring HTTPS on a custom website requires the acquisition of a domain, and a SSL/TLS Certificate.
|
||||
注意:在自定義網站上配置 HTTPS 需要獲得一個域名,以及一個 SSL/TLS 證書。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.hsts() middleware should be mounted correctly
|
||||
helmet.hsts() 中間件應該被正確安裝。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
@ -35,7 +35,7 @@ helmet.hsts() middleware should be mounted correctly
|
||||
);
|
||||
```
|
||||
|
||||
maxAge should be equal to 7776000 s (90 days)
|
||||
maxAge 應該等於 7776000 秒(90 天)。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8248367417b2b2512c3a
|
||||
title: Avoid Inferring the Response MIME Type with helmet.noSniff()
|
||||
title: 用 helmet.noSniff() 避免推斷出響應的 MIME 類型。
|
||||
challengeType: 2
|
||||
forumTopicId: 301574
|
||||
dashedName: avoid-inferring-the-response-mime-type-with-helmet-nosniff
|
||||
@ -8,15 +8,15 @@ dashedName: avoid-inferring-the-response-mime-type-with-helmet-nosniff
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/). Browsers can use content or MIME sniffing to override response `Content-Type` headers to guess and process the data using an implicit content type. While this can be convenient in some scenarios, it can also lead to some dangerous attacks. This middleware sets the X-Content-Type-Options header to `nosniff`, instructing the browser to not bypass the provided `Content-Type`.
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。 瀏覽器可以使用內容或 MIME 嗅探來覆蓋響應的 `Content-Type` 頭,猜測並使用隱含的內容類型來處理數據。 雖然這在某些情況下可能很方便,但也可能導致一些危險的攻擊。 該中間件將 X-Content-Type-Options 頭設置爲 `nosniff`,指示瀏覽器不要繞過所提供的 `Content-Type`。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use the `helmet.noSniff()` method on your server.
|
||||
在你的服務器上使用 `helmet.noSniff()` 方法。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.noSniff() middleware should be mounted correctly
|
||||
helmet.noSniff() 中間件應該被正確安裝
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8249367417b2b2512c40
|
||||
title: Configure Helmet Using the ‘parent’ helmet() Middleware
|
||||
title: 使用 helmet() 中間件來配置 Helmet
|
||||
challengeType: 2
|
||||
forumTopicId: 301575
|
||||
dashedName: configure-helmet-using-the-parent-helmet-middleware
|
||||
@ -8,11 +8,11 @@ dashedName: configure-helmet-using-the-parent-helmet-middleware
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
`app.use(helmet())` will automatically include all the middleware introduced above, except `noCache()`, and `contentSecurityPolicy()`, but these can be enabled if necessary. You can also disable or configure any other middleware individually, using a configuration object.
|
||||
`app.use(helmet())` 將自動包括上面介紹的所有中間件,除了 `noCache()` 和 `contentSecurityPolicy()`,但如果有必要,這些可以被啓用。 你也可以使用配置對象,單獨禁用或配置任何其他中間件。
|
||||
|
||||
**Example:**
|
||||
**例如:**
|
||||
|
||||
```js
|
||||
app.use(helmet({
|
||||
@ -21,7 +21,7 @@ app.use(helmet({
|
||||
},
|
||||
contentSecurityPolicy: { // enable and configure
|
||||
directives: {
|
||||
defaultSrc: ["self"],
|
||||
defaultSrc: ["'self'"],
|
||||
styleSrc: ['style.com'],
|
||||
}
|
||||
},
|
||||
@ -29,11 +29,11 @@ app.use(helmet({
|
||||
}))
|
||||
```
|
||||
|
||||
We introduced each middleware separately for teaching purposes and for ease of testing. Using the ‘parent’ `helmet()` middleware is easy to implement in a real project.
|
||||
爲了教學目的和便於測試,我們分別介紹了每個中間件。 使用“父”`helmet()` 中間件很容易在真實項目中實現。
|
||||
|
||||
# --hints--
|
||||
|
||||
no tests - it's a descriptive challenge
|
||||
沒有測試 - 這是一個描述性的挑戰
|
||||
|
||||
```js
|
||||
assert(true);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8249367417b2b2512c3e
|
||||
title: Disable Client-Side Caching with helmet.noCache()
|
||||
title: 使用 helment.noCache() 禁用客戶端緩存
|
||||
challengeType: 2
|
||||
forumTopicId: 301576
|
||||
dashedName: disable-client-side-caching-with-helmet-nocache
|
||||
@ -8,17 +8,17 @@ dashedName: disable-client-side-caching-with-helmet-nocache
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。 你也可以從[GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/)上克隆。
|
||||
|
||||
If you are releasing an update for your website, and you want the users to always download the newer version, you can (try to) disable caching on client’s browser. It can be useful in development too. Caching has performance benefits, which you will lose, so only use this option when there is a real need.
|
||||
如果你正在爲你的網站發佈更新,而你希望用戶總是下載較新的版本,你可以(嘗試)在客戶的瀏覽器上禁用緩存。 它在開發中也很有用。 緩存具有性能優勢,你將失去這些優勢,因此只有在真正需要時才使用此選項。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use the `helmet.noCache()` method on your server.
|
||||
在你的服務器上使用 `helmet.noCache()` 方法。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.noCache() middleware should be mounted correctly
|
||||
應正確加載 helmet.noCache() 中間件
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8248367417b2b2512c3d
|
||||
title: Disable DNS Prefetching with helmet.dnsPrefetchControl()
|
||||
title: 使用 helmet.dnsPrefetchControl() 禁用 DNS 預獲取
|
||||
challengeType: 2
|
||||
forumTopicId: 301577
|
||||
dashedName: disable-dns-prefetching-with-helmet-dnsprefetchcontrol
|
||||
@ -8,17 +8,17 @@ dashedName: disable-dns-prefetching-with-helmet-dnsprefetchcontrol
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
To improve performance, most browsers prefetch DNS records for the links in a page. In that way the destination ip is already known when the user clicks on a link. This may lead to over-use of the DNS service (if you own a big website, visited by millions people…), privacy issues (one eavesdropper could infer that you are on a certain page), or page statistics alteration (some links may appear visited even if they are not). If you have high security needs you can disable DNS prefetching, at the cost of a performance penalty.
|
||||
爲了提高性能,大部分瀏覽器都會爲頁面上的鏈接預先加載 DNS 記錄。 這樣當用戶點擊一個鏈接的時候瀏覽器已經知道其 IP 地址了。 但這也會造成 DNS 服務的過度使用(如果你有一個百萬用戶數量級的大型網站)、隱私問題(竊聽者可以藉此推測出你在訪問哪個頁面)、頁面統計數據準確性(有些沒訪問過的鏈接會被標記成已訪問)。 如果你對安全性要求比較高,你應該禁用 DNS 預加載。 當然,這樣做會讓你損失一些性能。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use the `helmet.dnsPrefetchControl()` method on your server.
|
||||
應正確加載 helmet.dnsPrefetchControl() 中間件
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.dnsPrefetchControl() middleware should be mounted correctly
|
||||
應正確加載 helmet.dnsPrefetchControl() 中間件
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 58a25bcff9fc0f352b528e7d
|
||||
title: Hash and Compare Passwords Asynchronously
|
||||
title: 哈希和異步比較密碼
|
||||
challengeType: 2
|
||||
forumTopicId: 301578
|
||||
dashedName: hash-and-compare-passwords-asynchronously
|
||||
@ -8,9 +8,9 @@ dashedName: hash-and-compare-passwords-asynchronously
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-bcrypt), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-bcrypt/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。 你也可以從[GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/)上克隆。
|
||||
|
||||
As hashing is designed to be computationally intensive, it is recommended to do so asynchronously on your server as to avoid blocking incoming connections while you hash. All you have to do to hash a password asynchronous is call
|
||||
由於哈希運算會佔用很大計算機資源,並且會耗費比較多時間,因此比較推薦的做法是異步調用哈希算法,這樣就不會因此阻止其它連接或請求了。 異步調用哈希方法非常簡單,只需要:
|
||||
|
||||
```js
|
||||
bcrypt.hash(myPlaintextPassword, saltRounds, (err, hash) => {
|
||||
@ -20,9 +20,9 @@ bcrypt.hash(myPlaintextPassword, saltRounds, (err, hash) => {
|
||||
|
||||
# --instructions--
|
||||
|
||||
Add this hashing function to your server(we've already defined the variables used in the function for you to use) and log it to the console for you to see! At this point you would normally save the hash to your database.
|
||||
把這段哈希方法添加到你的服務器(我們已經定義好這個方法的變量給你直接使用了),然後你可以嘗試在控制檯輸出。 之後,我們通常需要把哈希的結果保存到數據庫。
|
||||
|
||||
Now when you need to figure out if a new input is the same data as the hash you would just use the compare function.
|
||||
當你需要對比用戶輸入的值是否和之前哈希過的值一樣的時候,只需要調用對比函數:
|
||||
|
||||
```js
|
||||
bcrypt.compare(myPlaintextPassword, hash, (err, res) => {
|
||||
@ -30,7 +30,7 @@ bcrypt.compare(myPlaintextPassword, hash, (err, res) => {
|
||||
});
|
||||
```
|
||||
|
||||
Add this into your existing hash function(since you need to wait for the hash to complete before calling the compare function) after you log the completed hash and log 'res' to the console within the compare. You should see in the console a hash then 'true' is printed! If you change 'myPlaintextPassword' in the compare function to 'someOtherPlaintextPassword' then it should say false.
|
||||
當控制檯輸出生成的哈希並在對比的回調中輸出結果後,我們就可以將其添加到現有的哈希函數中。 控制檯中會首先輸出一個哈希結果,然後輸出 true。 如果將比較函數中的 “myPlaintextPassword” 更改爲 “someOtherPlaintextPassword”,則比較的結果應顯示 false。
|
||||
|
||||
```js
|
||||
bcrypt.hash('passw0rd!', 13, (err, hash) => {
|
||||
@ -43,11 +43,11 @@ bcrypt.hash('passw0rd!', 13, (err, hash) => {
|
||||
|
||||
```
|
||||
|
||||
Submit your page when you think you've got it right.
|
||||
請在完成挑戰後提交你的頁面。
|
||||
|
||||
# --hints--
|
||||
|
||||
Async hash should be generated and correctly compared.
|
||||
應生成異步散列並正確比較。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 58a25bcff9fc0f352b528e7e
|
||||
title: Hash and Compare Passwords Synchronously
|
||||
title: 哈希和同步比較密碼
|
||||
challengeType: 2
|
||||
forumTopicId: 301579
|
||||
dashedName: hash-and-compare-passwords-synchronously
|
||||
@ -8,31 +8,31 @@ dashedName: hash-and-compare-passwords-synchronously
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-bcrypt), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-bcrypt/).
|
||||
請注意,本項目在 [這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-bcrypt) 的基礎上進行開發。 你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-bcrypt/) 上克隆。
|
||||
|
||||
Hashing synchronously is just as easy to do but can cause lag if using it server side with a high cost or with hashing done very often. Hashing with this method is as easy as calling
|
||||
同步執行哈希運算是非常簡單的,但這會在哈希計算量大並且次數多的情況下造成延遲。 用這個方法哈希就像調用函數一樣簡單。
|
||||
|
||||
```js
|
||||
var hash = bcrypt.hashSync(myPlaintextPassword, saltRounds);
|
||||
```
|
||||
|
||||
Add this method of hashing to your code and then log the result to the console. Again, the variables used are already defined in the server so you won't need to adjust them. You may notice even though you are hashing the same password as in the async function, the result in the console is different- this is due to the salt being randomly generated each time as seen by the first 22 characters in the third string of the hash. Now to compare a password input with the new sync hash, you would use the compareSync method:
|
||||
把同步哈希的方法添加到你的代碼,並在控制檯輸出。 和之前一樣,我們已經爲你定義好了你需要使用的變量,你不需要做任何改動。 你可能會注意到即使你使用與異步函數相同的密碼進行哈希處理,控制檯中的結果也不同,這是由於每次哈希值隨機生成,如第三個哈希字符串中的前 22 個字符所示。 現在,爲了比較一個密碼輸入和新的同步哈希值,你將使用 compareSync 方法。
|
||||
|
||||
```js
|
||||
var result = bcrypt.compareSync(myPlaintextPassword, hash);
|
||||
```
|
||||
|
||||
with the result being a boolean true or false.
|
||||
返回的結果爲 true 或 false。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Add the function in and log the result to the console to see it working.
|
||||
請添加這個方法,並把結果輸出到控制檯,以此來驗證同步哈希操作是否成功。
|
||||
|
||||
Submit your page when you think you've got it right.
|
||||
請在完成挑戰後提交你的頁面。
|
||||
|
||||
# --hints--
|
||||
|
||||
Sync hash should be generated and correctly compared.
|
||||
應同步地進行哈希並正確地執行對比
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8247367417b2b2512c37
|
||||
title: Hide Potentially Dangerous Information Using helmet.hidePoweredBy()
|
||||
title: 使用 helmet.hidePoweredBy() 隱藏潛在的危險信息
|
||||
challengeType: 2
|
||||
forumTopicId: 301580
|
||||
dashedName: hide-potentially-dangerous-information-using-helmet-hidepoweredby
|
||||
@ -8,13 +8,13 @@ dashedName: hide-potentially-dangerous-information-using-helmet-hidepoweredby
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
Hackers can exploit known vulnerabilities in Express/Node if they see that your site is powered by Express. X-Powered-By: Express is sent in every request coming from Express by default. The `helmet.hidePoweredBy()` middleware will remove the X-Powered-By header. You can also explicitly set the header to something else, to throw people off. e.g. `app.use(helmet.hidePoweredBy({ setTo: 'PHP 4.2.0' }))`
|
||||
如果黑客發現你的網站是用 Express 搭建的,那麼他們就可以利用 Express 或 Node 現存的漏洞來攻擊你的網站。 `X-Powered-By: Express` 默認在來自 Express 的每個請求中被髮送。 使用 `helmet.hidePoweredBy()` 中間件來移除 X-Powered-By 頭。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.hidePoweredBy() middleware should be mounted correctly
|
||||
應正確地安裝 helmet.hidePoweredBy() 中間件
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8247367417b2b2512c36
|
||||
title: Install and Require Helmet
|
||||
title: 安裝和引入 Helmet
|
||||
challengeType: 2
|
||||
forumTopicId: 301581
|
||||
dashedName: install-and-require-helmet
|
||||
@ -8,26 +8,33 @@ dashedName: install-and-require-helmet
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
你可以採用下面的任意一種編寫代碼的方式來完成這些挑戰:
|
||||
|
||||
Helmet helps you secure your Express apps by setting various HTTP headers.
|
||||
- 克隆 [這個 GitHub 倉庫](https://github.com/freeCodeCamp/boilerplate-infosec/) 並在本地完成這些挑戰。
|
||||
- 使用[我們在 Repl.it 上的初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)來完成這些挑戰。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。
|
||||
|
||||
Helmet 通過設置各種 HTTP 頭來保護你的 Express 應用程序。
|
||||
|
||||
# --instructions--
|
||||
|
||||
All your code for these lessons goes in the `myApp.js` file between the lines of code we have started you off with. Do not change or delete the code we have added for you.
|
||||
你在這些課程中寫的所有代碼都在 `myApp.js` 文件中,在初始代碼之間。 不要改變或刪除我們爲你添加的代碼。
|
||||
|
||||
Install Helmet version `3.21.3`, then require it.
|
||||
安裝 Helmet 的 `3.21.3` 版本,然後引入它。 你可以用 `npm install --save-exact package@version` 來安裝一個特定版本的軟件包,或者直接將其添加到你的 `package.json` 中。
|
||||
|
||||
# --hints--
|
||||
|
||||
`helmet` version `3.21.3` should be in `package.json`
|
||||
`helmet` 版本 `3.21.3` 應該在 `package.json` 中。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
$.get(getUserInput('url') + '/_api/package.json').then(
|
||||
(data) => {
|
||||
var packJson = JSON.parse(data);
|
||||
assert(packJson.dependencies.helmet === '3.21.3');
|
||||
const packJson = JSON.parse(data);
|
||||
const helmet = packJson.dependencies.helmet;
|
||||
assert(helmet === '3.21.3' || helmet === '^3.21.3');
|
||||
},
|
||||
(xhr) => {
|
||||
throw new Error(xhr.responseText);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8247367417b2b2512c38
|
||||
title: Mitigate the Risk of Clickjacking with helmet.frameguard()
|
||||
title: 使用 helmet.frameguard() 降低點擊劫持的風險
|
||||
challengeType: 2
|
||||
forumTopicId: 301582
|
||||
dashedName: mitigate-the-risk-of-clickjacking-with-helmet-frameguard
|
||||
@ -8,19 +8,19 @@ dashedName: mitigate-the-risk-of-clickjacking-with-helmet-frameguard
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在 [這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec) 的基礎上進行開發。 你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
Your page could be put in a `<frame>` or `<iframe>` without your consent. This can result in clickjacking attacks, among other things. Clickjacking is a technique of tricking a user into interacting with a page different from what the user thinks it is. This can be obtained executing your page in a malicious context, by mean of iframing. In that context a hacker can put a hidden layer over your page. Hidden buttons can be used to run bad scripts. This middleware sets the X-Frame-Options header. It restricts who can put your site in a frame. It has three modes: DENY, SAMEORIGIN, and ALLOW-FROM.
|
||||
你的網頁可能在未經你同意的情況下被放在 `<frame>` 或 `<iframe>` 中。 這可能會導致點擊劫持攻擊等情況。 點擊劫持是一種欺騙用戶的技術,使其與用戶認爲不同的頁面進行互動。 這可以通過使用 iframe 的方式,在一個惡意的環境中執行你的頁面而獲得。 在這種情況下,黑客可以在你的頁面上設置一個隱藏層。 隱藏的按鈕可以被用來運行壞的腳本。 該中間件設置 X-Frame-Options 頭。 它限制了誰可以把你的網站放在一個框架裏。 它有三種模式:DENY、SAMEORIGIN 和 ALLOW-FROM。
|
||||
|
||||
We don’t need our app to be framed.
|
||||
我們不需要讓我們的應用程序可以被嵌入。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use `helmet.frameguard()` passing with the configuration object `{action: 'deny'}`.
|
||||
使用 `helmet.frameguard()` 時應傳遞配置對象 `{action: 'deny'}`。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.frameguard() middleware should be mounted correctly
|
||||
應正確加載 helmet.frameguard() 中間件
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
@ -38,7 +38,7 @@ helmet.frameguard() middleware should be mounted correctly
|
||||
);
|
||||
```
|
||||
|
||||
helmet.frameguard() 'action' should be set to 'DENY'
|
||||
helmet.frameguard() 'action' 應該設置爲 “DENY”
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
id: 587d8247367417b2b2512c39
|
||||
title: >-
|
||||
Mitigate the Risk of Cross Site Scripting (XSS) Attacks with helmet.xssFilter()
|
||||
使用 helmet.xssFilter() 降低跨站點腳本(XSS)攻擊的風險
|
||||
challengeType: 2
|
||||
forumTopicId: 301583
|
||||
dashedName: mitigate-the-risk-of-cross-site-scripting-xss-attacks-with-helmet-xssfilter
|
||||
@ -9,23 +9,23 @@ dashedName: mitigate-the-risk-of-cross-site-scripting-xss-attacks-with-helmet-xs
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在 [這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec) 的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
Cross-site scripting (XSS) is a frequent type of attack where malicious scripts are injected into vulnerable pages, with the purpose of stealing sensitive data like session cookies, or passwords.
|
||||
跨站腳本(XSS)是一種常見的攻擊類型,惡意腳本被注入到易受攻擊的頁面,目的是竊取敏感數據,如會話 cookies 或密碼。
|
||||
|
||||
The basic rule to lower the risk of an XSS attack is simple: “Never trust user’s input”. As a developer you should always sanitize all the input coming from the outside. This includes data coming from forms, GET query urls, and even from POST bodies. Sanitizing means that you should find and encode the characters that may be dangerous e.g. <, >.
|
||||
降低 XSS 攻擊風險的基本規則很簡單:"永遠不要相信用戶的輸入"。 作爲一個開發者,你應該始終對所有來自外部的輸入進行消毒。 這包括來自表單、GET 查詢URL,甚至來自 POST 請求體的數據。 淨化意味着你應該找到並編碼可能有危險的字符,例如 <, >。
|
||||
|
||||
Modern browsers can help mitigating the risk by adopting better software strategies. Often these are configurable via http headers.
|
||||
現代瀏覽器通過採用更好的軟件策略來幫助降低風險。 通常情況下,這些都是可以通過 http 頭文件來配置的。
|
||||
|
||||
The X-XSS-Protection HTTP header is a basic protection. The browser detects a potential injected script using a heuristic filter. If the header is enabled, the browser changes the script code, neutralizing it. It still has limited support.
|
||||
X-XSS-Protection HTTP 消息頭是一種基本的保護。 瀏覽器使用啓發式過濾器檢測潛在的注入腳本。 如果請求頭被啓用,瀏覽器會改變腳本代碼,使其失效。 它得到的支持仍然有限。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use `helmet.xssFilter()` to sanitize input sent to your server.
|
||||
使用 `helmet.xssFilter()` 來淨化發送到服務器的輸入。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.xssFilter() middleware should be mounted correctly
|
||||
helmet.xssFilter() 中間件應正確安裝。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8248367417b2b2512c3b
|
||||
title: Prevent IE from Opening Untrusted HTML with helmet.ieNoOpen()
|
||||
title: 使用 helment.ieNoOpen() 防止 IE 打開不受信任的 HTML
|
||||
challengeType: 2
|
||||
forumTopicId: 301584
|
||||
dashedName: prevent-ie-from-opening-untrusted-html-with-helmet-ienoopen
|
||||
@ -8,17 +8,17 @@ dashedName: prevent-ie-from-opening-untrusted-html-with-helmet-ienoopen
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在[這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec)的基礎上進行開發。 你也可以從[GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/)上克隆。
|
||||
|
||||
Some web applications will serve untrusted HTML for download. Some versions of Internet Explorer by default open those HTML files in the context of your site. This means that an untrusted HTML page could start doing bad things in the context of your pages. This middleware sets the X-Download-Options header to noopen. This will prevent IE users from executing downloads in the trusted site’s context.
|
||||
有些網站會下載不安全的 HTML 文件。 某些版本的 IE 默認情況下還會在你網站的作用域下打開這些 HTML 文件。 換句話說,這些不安全的 HTML 頁面可以在你的網站做惡意行爲。 我們可以通過中間件來設置 header 中的 X-Download-Options 字段,讓它的值爲 noopen。 這樣就可以防止 IE 在不信任的網站下執行下載的文件。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use the `helmet.ieNoOpen()` method on your server.
|
||||
應正確加載 `helmet.ieNoOpen()` 中間件
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.ieNoOpen() middleware should be mounted correctly
|
||||
helmet.ieNoOpen() 中間件應正確安裝。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8249367417b2b2512c3f
|
||||
title: Set a Content Security Policy with helmet.contentSecurityPolicy()
|
||||
title: 使用 helment.contentSecurityPolicy() 設置內容安全策略
|
||||
challengeType: 2
|
||||
forumTopicId: 301585
|
||||
dashedName: set-a-content-security-policy-with-helmet-contentsecuritypolicy
|
||||
@ -8,21 +8,21 @@ dashedName: set-a-content-security-policy-with-helmet-contentsecuritypolicy
|
||||
|
||||
# --description--
|
||||
|
||||
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-infosec), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/).
|
||||
請注意,本項目在 [這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec) 的基礎上進行開發。你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
||||
|
||||
This challenge highlights one promising new defense that can significantly reduce the risk and impact of many type of attacks in modern browsers. By setting and configuring a Content Security Policy you can prevent the injection of anything unintended into your page. This will protect your app from XSS vulnerabilities, undesired tracking, malicious frames, and much more. CSP works by defining an allowed list of content sources which are trusted. You can configure them for each kind of resource a web page may need (scripts, stylesheets, fonts, frames, media, and so on…). There are multiple directives available, so a website owner can have a granular control. See HTML 5 Rocks, KeyCDN for more details. Unfortunately CSP is unsupported by older browser.
|
||||
在這個挑戰中,我們要重點討論現代瀏覽器中一種能有效減輕安全風險和防禦很多種類型常見攻擊的安全防護。 通過設置和配置內容安全策略,你可以防止在頁面中無意中注入任何內容。 這會讓你的應用遠離 XSS 漏洞、惡意追蹤、惡意 frames 和很多其他攻擊。 CSP 通過配置資源白名單來避免這些問題。 你可以給任何一種類型的頁面資源(腳本、樣式文件、字體、frames、媒體文件等)做這個配置。 它支持很多指令,所以網站管理員可以做細緻的控制。 更多詳情請參考 HTML 5 Rocks 和 KeyCDN。 不幸的是,一些舊的瀏覽器不支持 CSP。
|
||||
|
||||
By default, directives are wide open, so it’s important to set the defaultSrc directive as a fallback. Helmet supports both defaultSrc and default-src naming styles. The fallback applies for most of the unspecified directives.
|
||||
默認的指令很容易受到攻擊, 所以設置 defaultSrc 指令作爲降級方案很重要。 Helmet 同時支持 defaultSrc 和 default-src 命名規範。 降級方案可以應用在大部分指令上。
|
||||
|
||||
# --instructions--
|
||||
|
||||
In this exercise, use `helmet.contentSecurityPolicy()`, and configure it setting the `defaultSrc directive` to `["self"]` (the list of allowed sources must be in an array), in order to trust only your website address by default. Set also the `scriptSrc` directive so that you will allow scripts to be downloaded from your website, and from the domain 'trusted-cdn.com'.
|
||||
在這個練習中,使用 `helmet.contentSecurityPolicy()`。 通過添加一個 `directives` 對象來配置它。 在該對象中,將 `defaultSrc` 設置爲 `["'self'"]`(允許的來源列表必須是一個數組),以便默認只信任你的網站地址。 同時設置 `scriptSrc` 指令,以便你只允許從你的網站(`'self'`)和域名 `'trusted-cdn.com'` 下載腳本。
|
||||
|
||||
Hint: in the `self` keyword, the single quotes are part of the keyword itself, so it needs to be enclosed in double quotes to be working.
|
||||
提示:在 `'self'` 關鍵詞中,單引號也是關鍵詞的一部分,所以你應該用雙引號來包起它才能正常工作。
|
||||
|
||||
# --hints--
|
||||
|
||||
helmet.csp() middleware should be mounted correctly
|
||||
應正確安裝 helmet.contentSecurityPolicy() 中間件。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
@ -36,7 +36,7 @@ helmet.csp() middleware should be mounted correctly
|
||||
);
|
||||
```
|
||||
|
||||
Your csp config is not correct. defaultSrc should be ["'self'"] and scriptSrc should be ["'self'", 'trusted-cdn.com']
|
||||
你的 csp 配置不正確。 defaultSrc 應爲 ["'self'"],並且 scriptSrc 應爲 ["'self'", 'trusted-cdn.com']
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 58a25bcef9fc0f352b528e7c
|
||||
title: Understand BCrypt Hashes
|
||||
title: 瞭解 BCrypt 的哈希加密
|
||||
challengeType: 2
|
||||
forumTopicId: 301586
|
||||
dashedName: understand-bcrypt-hashes
|
||||
@ -8,23 +8,23 @@ dashedName: understand-bcrypt-hashes
|
||||
|
||||
# --description--
|
||||
|
||||
For the following challenges, you will be working with a new starter project that is different from the previous one. You can find the new starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-bcrypt), or clone it from [GitHub](https://github.com/freeCodeCamp/boilerplate-bcrypt/).
|
||||
在下面的挑戰中,你將啓動一個新的項目,這個項目與之前的項目不同。 你可以在 [Replit](https://replit.com/github/freeCodeCamp/boilerplate-bcrypt)上找到新的啓動項目,或者從 [GitHub](https://github.com/freeCodeCamp/boilerplate-bcrypt/) 上克隆它。
|
||||
|
||||
BCrypt hashes are very secure. A hash is basically a fingerprint of the original data- always unique. This is accomplished by feeding the original data into an algorithm and returning a fixed length result. To further complicate this process and make it more secure, you can also *salt* your hash. Salting your hash involves adding random data to the original data before the hashing process which makes it even harder to crack the hash.
|
||||
BCrypt 哈希值是非常安全的。 哈希值基本上是原始數據的指紋,總是唯一的。 這是通過將原始數據輸入一個算法並返回一個固定長度的結果來實現的。 爲了使這一過程更加複雜和安全,你還可以向你的哈希值 *加鹽*。 對你的散列加鹽處理包含了在散列過程之前向原始數據添加隨機數據,這使得破解散列更加困難。
|
||||
|
||||
BCrypt hashes will always looks like `$2a$13$ZyprE5MRw2Q3WpNOGZWGbeG7ADUre1Q8QO.uUUtcbqloU0yvzavOm` which does have a structure. The first small bit of data `$2a` is defining what kind of hash algorithm was used. The next portion `$13` defines the *cost*. Cost is about how much power it takes to compute the hash. It is on a logarithmic scale of 2^cost and determines how many times the data is put through the hashing algorithm. For example, at a cost of 10 you are able to hash 10 passwords a second on an average computer, however at a cost of 15 it takes 3 seconds per hash... and to take it further, at a cost of 31 it would takes multiple days to complete a hash. A cost of 12 is considered very secure at this time. The last portion of your hash `$ZyprE5MRw2Q3WpNOGZWGbeG7ADUre1Q8QO.uUUtcbqloU0yvzavOm`, looks like one large string of numbers, periods, and letters but it is actually two separate pieces of information. The first 22 characters is the salt in plain text, and the rest is the hashed password!
|
||||
BCrypt 哈希值總是看起來有像`$2a$13$ZyprE5MRw2Q3WpNOGZWGbeG7ADUre1Q8QO.uUUtcbqloU0yvzavOm` 的結構。 它遵循固定的結構,第一小節 `$2a` 說明了該哈希採用什麼算法。 接下來的部分 `$13` 定義了 *成本*。 成本是指計算哈希值需要多少能量。 它在 2^cost 的對數尺度上,決定了數據要通過散列算法計算多少次。 例如,當 cost 爲 10 時,你能夠在普通計算機上每秒散列 10 個密碼,然而當 cost 爲 15 時,每次散列需要 3 秒...... 進一步說,當 cost 爲 31 時,完成一次散列需要好幾天。 通常 cost 爲 12 的哈希運算就已經足夠安全。 哈希結果的最後一部分 `$ZyprE5MRw2Q3WpNOGZWGbeG7ADUre1Q8QO.uUUtcbqloU0yvzavOm` 看起來像是由隨機數字、點和字母組成的字符串,但實際上它有兩部分內容。 前面 22 個字符是加入的鹽,剩下的就是加密過的密碼!
|
||||
|
||||
# --instructions--
|
||||
|
||||
To begin using BCrypt, add it as a dependency in your project and require it as 'bcrypt' in your server.
|
||||
要開始使用 BCrypt,只需將它添加到你的依賴列表,然後在你的服務器引入 “bcrypt”。
|
||||
|
||||
Add all your code for these lessons in the `server.js` file between the code we have started you off with. Do not change or delete the code we have added for you.
|
||||
在 `server.js` 文件中加入這些課程的所有代碼,放在我們提供的代碼之間。 不要改變或刪除我們爲你添加的代碼。
|
||||
|
||||
Submit your page when you think you've got it right.
|
||||
請在完成挑戰後提交你的頁面。
|
||||
|
||||
# --hints--
|
||||
|
||||
BCrypt should be a dependency.
|
||||
BCrypt 應該是一個依賴項。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
@ -43,7 +43,7 @@ BCrypt should be a dependency.
|
||||
);
|
||||
```
|
||||
|
||||
BCrypt should be properly required.
|
||||
應正確引入 BCrypt。
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea9997bbec2e9bc47e94db0
|
||||
title: Creating a TCP Client
|
||||
title: 創建一個 TCP 客戶端
|
||||
challengeType: 11
|
||||
videoId: ugYfJNTawks
|
||||
dashedName: creating-a-tcp-client
|
||||
@ -10,7 +10,7 @@ dashedName: creating-a-tcp-client
|
||||
|
||||
## --text--
|
||||
|
||||
Which socket object method lets you set the maximum amount of data your client accepts at once?
|
||||
哪種套接字對象方法讓你設置客戶端一次接受的最大數據量?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea9997bbec2e9bc47e94db3
|
||||
title: Developing a Banner Grabber
|
||||
title: 開發橫幅抓取器
|
||||
challengeType: 11
|
||||
videoId: CeGW761BIsA
|
||||
dashedName: developing-a-banner-grabber
|
||||
@ -10,7 +10,7 @@ dashedName: developing-a-banner-grabber
|
||||
|
||||
## --text--
|
||||
|
||||
Fill in the blanks to complete the `banner` function below:
|
||||
填寫空格以完成下面的 `banner` 函數:
|
||||
|
||||
```py
|
||||
def banner(ip, port):
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea9997bbec2e9bc47e94db4
|
||||
title: Developing a Port Scanner
|
||||
title: 開發一個端口掃描器
|
||||
challengeType: 11
|
||||
videoId: z_qkqZS7KZ4
|
||||
dashedName: developing-a-port-scanner
|
||||
@ -10,19 +10,19 @@ dashedName: developing-a-port-scanner
|
||||
|
||||
## --text--
|
||||
|
||||
What is the main difference between the `.connect()` and `.connect_ex()` methods?
|
||||
`.connect()` 和 `.connect_ex()` 方法的主要區別是什麼?
|
||||
|
||||
## --answers--
|
||||
|
||||
There is no difference between the two methods.
|
||||
這兩種方法之間沒有區別。
|
||||
|
||||
---
|
||||
|
||||
If there is an error or if no host is found, `.connect()` returns an error code while `.connect_ex()` raises an exception.
|
||||
如果有錯誤或沒有找到主機,`.connect()` 返回一個錯誤代碼,而 `.connect_ex()` 則引發一個異常。
|
||||
|
||||
---
|
||||
|
||||
If there is an error or if no host is found, `.connect()` raises an exception while `.connect_ex()` returns an error code.
|
||||
如果有錯誤或沒有找到主機,`.connect()` 會引發一個異常,而 `.connect_ex()` 會返回一個錯誤代碼。
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea9997bbec2e9bc47e94db1
|
||||
title: Developing an Nmap Scanner part 1
|
||||
title: 開發 Nmap 掃描器 第一部分
|
||||
challengeType: 11
|
||||
videoId: jYk9XaGoAnk
|
||||
dashedName: developing-an-nmap-scanner-part-1
|
||||
@ -10,7 +10,7 @@ dashedName: developing-an-nmap-scanner-part-1
|
||||
|
||||
## --text--
|
||||
|
||||
What is the correct command to install the Python 3 version of the `python-nmap` library?
|
||||
安裝 Python 3 版本的 `python-nmap` 庫的正確命令是什麼?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea9997bbec2e9bc47e94db2
|
||||
title: Developing an Nmap Scanner part 2
|
||||
title: 開發 Nmap 掃描器 第二部分
|
||||
challengeType: 11
|
||||
videoId: a98PscnUsTg
|
||||
dashedName: developing-an-nmap-scanner-part-2
|
||||
@ -10,7 +10,7 @@ dashedName: developing-an-nmap-scanner-part-2
|
||||
|
||||
## --text--
|
||||
|
||||
Which of the following allows you to scan for UDP ports between 21 to 443?
|
||||
以下哪項允許你掃描 21 至 443 之間的 UDP 端口?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea9997bbec2e9bc47e94dae
|
||||
title: Introduction and Setup
|
||||
title: 介紹和安裝
|
||||
challengeType: 11
|
||||
videoId: XeQ7ZKtb998
|
||||
dashedName: introduction-and-setup
|
||||
@ -10,19 +10,19 @@ dashedName: introduction-and-setup
|
||||
|
||||
## --text--
|
||||
|
||||
What code editor and extension does the instructor recommend for developing penetration testing tools in Python?
|
||||
講師推薦什麼代碼編輯器和擴展來開發 Python 的滲透測試工具?
|
||||
|
||||
## --answers--
|
||||
|
||||
Atom and the atom-python-run extension.
|
||||
Atom和atom-python-run 擴展
|
||||
|
||||
---
|
||||
|
||||
VSCode and Microsoft's Python extension.
|
||||
VSCode 和微軟的 Python 擴展
|
||||
|
||||
---
|
||||
|
||||
Sublime Text and the Anaconda package.
|
||||
Sublime Text 和 Anaconda 軟件包
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
@ -20,6 +20,8 @@ Let's create the basic functionality of a hash table. We've created a naive hash
|
||||
|
||||
Be sure to write your code to account for collisions!
|
||||
|
||||
**Note:** The `remove` method tests won't pass until the `add` and `lookup` methods are correctly implemented.
|
||||
|
||||
# --hints--
|
||||
|
||||
The HashTable data structure should exist.
|
||||
@ -50,20 +52,6 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The HashTable should have a remove method.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
if (typeof HashTable !== 'undefined') {
|
||||
test = new HashTable();
|
||||
}
|
||||
return typeof test.remove === 'function';
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
The HashTable should have a lookup method.
|
||||
|
||||
```js
|
||||
@ -78,6 +66,20 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The HashTable should have a remove method.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
if (typeof HashTable !== 'undefined') {
|
||||
test = new HashTable();
|
||||
}
|
||||
return typeof test.remove === 'function';
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
The add method should add key value pairs and the lookup method should return the values associated with a given key.
|
||||
|
||||
```js
|
||||
@ -103,14 +105,40 @@ assert(
|
||||
if (typeof HashTable !== 'undefined') {
|
||||
test = new HashTable();
|
||||
}
|
||||
test.add = addMethodSolution;
|
||||
test.add('key', 'value');
|
||||
|
||||
test.remove('key');
|
||||
return !test.collection.hasOwnProperty(hashValue);
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
The remove method should only remove the correct key value pair.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
var hashValue = hash('key');
|
||||
if (typeof HashTable !== 'undefined') {
|
||||
test = new HashTable();
|
||||
}
|
||||
test.add('key', 'value');
|
||||
test.add('yek', 'value');
|
||||
test.add('altKey', 'value');
|
||||
|
||||
test.remove('yek');
|
||||
if (test.lookup('yek') || !test.lookup('key') || !test.lookup('altKey')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
test.remove('key');
|
||||
|
||||
return !test.collection.hasOwnProperty(hashValue) && test.lookup('altKey');
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
Items should be added using the hash function.
|
||||
|
||||
```js
|
||||
@ -165,14 +193,6 @@ var hash = string => {
|
||||
}
|
||||
return hash;
|
||||
};
|
||||
|
||||
var addMethodSolution = function(key, val) {
|
||||
var theHash = hash(key);
|
||||
if (!this.collection.hasOwnProperty(theHash)) {
|
||||
this.collection[theHash] = {};
|
||||
}
|
||||
this.collection[theHash][key] = val;
|
||||
}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
@ -12,11 +12,15 @@ In this challenge you will be creating a Priority Queue. A Priority Queue is a s
|
||||
|
||||
For instance, let’s imagine we have a priority queue with three items:
|
||||
|
||||
`[['kitten', 2], ['dog', 2], ['rabbit', 2]]`
|
||||
```js
|
||||
[['kitten', 2], ['dog', 2], ['rabbit', 2]]
|
||||
```
|
||||
|
||||
Here the second value (an integer) represents item priority. If we enqueue `['human', 1]` with a priority of `1` (assuming lower priorities are given precedence) it would then be the first item to be dequeued. The collection would look like this:
|
||||
|
||||
`[['human', 1], ['kitten', 2], ['dog', 2], ['rabbit', 2]]`.
|
||||
```js
|
||||
[['human', 1], ['kitten', 2], ['dog', 2], ['rabbit', 2]]
|
||||
```
|
||||
|
||||
We’ve started writing a `PriorityQueue` in the code editor. You will need to add an `enqueue` method for adding items with a priority, a `dequeue` method for removing and returning items, a `size` method to return the number of items in the queue, a `front` method to return the element at the front of the queue, and finally an `isEmpty` method that will return `true` if the queue is empty or `false` if it is not.
|
||||
|
||||
|
@ -77,8 +77,9 @@ The `peek` method should return the top element of the stack
|
||||
assert(
|
||||
(function () {
|
||||
var test = new Stack();
|
||||
test.push('CS61');
|
||||
test.push('CS50');
|
||||
return test.peek() === 'CS50';
|
||||
return test.peek() === 'CS50' && test.peek() === 'CS50';
|
||||
})()
|
||||
);
|
||||
```
|
||||
@ -89,8 +90,9 @@ The `pop` method should remove and return the top element of the stack
|
||||
assert(
|
||||
(function () {
|
||||
var test = new Stack();
|
||||
test.push('CS61');
|
||||
test.push('CS50');
|
||||
return test.pop() === 'CS50';
|
||||
return test.pop() === 'CS50' && test.pop() === 'CS61';
|
||||
})()
|
||||
);
|
||||
```
|
||||
@ -112,6 +114,7 @@ The `clear` method should remove all element from the stack
|
||||
assert(
|
||||
(function () {
|
||||
var test = new Stack();
|
||||
test.push('CS61');
|
||||
test.push('CS50');
|
||||
test.clear();
|
||||
return test.isEmpty();
|
||||
|
@ -31,7 +31,9 @@ assert(myMap.get('freeCodeCamp') === 'Awesome!');
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,15 +12,21 @@ Now that you have worked through ES5, you are going to perform something similar
|
||||
|
||||
To create a new empty set:
|
||||
|
||||
`var set = new Set();`
|
||||
```js
|
||||
var set = new Set();
|
||||
```
|
||||
|
||||
You can create a set with a value:
|
||||
|
||||
`var set = new Set(1);`
|
||||
```js
|
||||
var set = new Set(1);
|
||||
```
|
||||
|
||||
You can create a set with an array:
|
||||
|
||||
`var set = new Set([1, 2, 3]);`
|
||||
```js
|
||||
var set = new Set([1, 2, 3]);
|
||||
```
|
||||
|
||||
Once you have created a set, you can add the values you wish using the `add` method:
|
||||
|
||||
|
@ -14,13 +14,17 @@ While binary heaps may be implemented as tree structures with nodes that contain
|
||||
|
||||
For instance, consider this array representation of a binary min heap:
|
||||
|
||||
`[ 6, 22, 30, 37, 63, 48, 42, 76 ]`
|
||||
```js
|
||||
[ 6, 22, 30, 37, 63, 48, 42, 76 ]
|
||||
```
|
||||
|
||||
The root node is the first element, `6`. Its children are `22` and `30`. If we look at the relationship between the array indices of these values, for index `i` the children are `2 * i + 1` and `2 * i + 2`. Similarly, the element at index `0` is the parent of these two children at indices `1` and `2`. More generally, we can find the parent of a node at any index with the following: `Math.floor((i - 1) / 2)`. These patterns will hold true as the binary tree grows to any size. Finally, we can make a slight adjustment to make this arithmetic even easier by skipping the first element in the array. Doing this creates the following relationship for any element at a given index `i`:
|
||||
|
||||
Example array representation:
|
||||
|
||||
`[ null, 6, 22, 30, 37, 63, 48, 42, 76 ]`
|
||||
```js
|
||||
[ null, 6, 22, 30, 37, 63, 48, 42, 76 ]
|
||||
```
|
||||
|
||||
An element's left child: `i * 2`
|
||||
|
||||
|
@ -12,7 +12,9 @@ Let's practice removing items from an ES6 Set using the `delete` method.
|
||||
|
||||
First, create an ES6 Set:
|
||||
|
||||
`var set = new Set([1,2,3]);`
|
||||
```js
|
||||
var set = new Set([1,2,3]);
|
||||
```
|
||||
|
||||
Now remove an item from your Set with the `delete` method.
|
||||
|
||||
@ -46,8 +48,11 @@ assert(
|
||||
|
||||
```js
|
||||
function checkSet(){
|
||||
var set = null;
|
||||
return set;
|
||||
// Only change code below this line
|
||||
var set = null;
|
||||
|
||||
// Only change code above this line
|
||||
return set;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -10,7 +10,9 @@ dashedName: typed-arrays
|
||||
|
||||
Arrays are JavaScript objects that can hold a lot of different elements.
|
||||
|
||||
`var complexArr = [1, 5, "2", "Word", {"name": "James"}];`
|
||||
```js
|
||||
var complexArr = [1, 5, "2", "Word", {"name": "James"}];
|
||||
```
|
||||
|
||||
Basically what happens in the background is that your browser will automatically give the right amount of memory space for that array. It will also change as needed if you add or remove data.
|
||||
|
||||
|
@ -12,15 +12,21 @@ Let's look at the .has and .size methods available on the ES6 Set object.
|
||||
|
||||
First, create an ES6 Set
|
||||
|
||||
`var set = new Set([1,2,3]);`
|
||||
```js
|
||||
var set = new Set([1,2,3]);
|
||||
```
|
||||
|
||||
The .has method will check if the value is contained within the set.
|
||||
|
||||
`var hasTwo = set.has(2);`
|
||||
```js
|
||||
var hasTwo = set.has(2);
|
||||
```
|
||||
|
||||
The .size method will return an integer representing the size of the Set
|
||||
|
||||
`var howBig = set.size;`
|
||||
```js
|
||||
var howBig = set.size;
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,24 +8,50 @@ dashedName: problem-100-arranged-probability
|
||||
|
||||
# --description--
|
||||
|
||||
If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, P(BB) = (15/21)×(14/20) = 1/2.
|
||||
If a box contains twenty-one colored discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs.
|
||||
|
||||
The next such arrangement, for which there is exactly 50% chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.
|
||||
$${P(BB)} = \frac{15}{21}×\frac{14}{20} = \frac{1}{2}$$
|
||||
|
||||
By finding the first arrangement to contain over 10<sup>12</sup> = 1,000,000,000,000 discs in total, determine the number of blue discs that the box would contain.
|
||||
The next such arrangement, for which there is exactly a 50% chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.
|
||||
|
||||
By finding the first arrangement to contain over `limit` discs in total, determine the number of blue discs that the box would contain.
|
||||
|
||||
# --hints--
|
||||
|
||||
`arrangedProbability()` should return a number.
|
||||
`arrangedProbability(20)` should return a number.
|
||||
|
||||
```js
|
||||
assert(typeof arrangedProbability() === 'number');
|
||||
assert(typeof arrangedProbability(10) === 'number');
|
||||
```
|
||||
|
||||
`arrangedProbability()` should return 756872327473.
|
||||
`arrangedProbability(20)` should return `15`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(arrangedProbability(), 756872327473);
|
||||
assert.strictEqual(arrangedProbability(20), 15);
|
||||
```
|
||||
|
||||
`arrangedProbability(100)` should return `85`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(arrangedProbability(100), 85);
|
||||
```
|
||||
|
||||
`arrangedProbability(100000)` should return `97513`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(arrangedProbability(100000), 97513);
|
||||
```
|
||||
|
||||
`arrangedProbability(1000000000)` should return `3822685023`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(arrangedProbability(1000000000), 3822685023);
|
||||
```
|
||||
|
||||
`arrangedProbability(1000000000000)` should return `756872327473`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(arrangedProbability(1000000000000), 756872327473);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,16 +59,29 @@ assert.strictEqual(arrangedProbability(), 756872327473);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function arrangedProbability() {
|
||||
function arrangedProbability(limit) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
arrangedProbability();
|
||||
arrangedProbability(20);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function arrangedProbability(limit) {
|
||||
// Based on https://www.mathblog.dk/project-euler-100-blue-discs-two-blue/
|
||||
let blue = 15;
|
||||
let discs = 21;
|
||||
|
||||
while (discs < limit) {
|
||||
const nextBlue = 3 * blue + 2 * discs - 2;
|
||||
const nextDiscs = 4 * blue + 3 * discs - 3;
|
||||
|
||||
blue = nextBlue;
|
||||
discs = nextDiscs;
|
||||
}
|
||||
return blue;
|
||||
}
|
||||
```
|
||||
|
@ -10,26 +10,30 @@ dashedName: problem-101-optimum-polynomial
|
||||
|
||||
If we are presented with the first k terms of a sequence it is impossible to say with certainty the value of the next term, as there are infinitely many polynomial functions that can model the sequence.
|
||||
|
||||
As an example, let us consider the sequence of cube numbers. This is defined by the generating function, un = n3: 1, 8, 27, 64, 125, 216, ...
|
||||
As an example, let us consider the sequence of cube numbers. This is defined by the generating function, $u_n = n^3: 1, 8, 27, 64, 125, 216, \ldots$
|
||||
|
||||
Suppose we were only given the first two terms of this sequence. Working on the principle that "simple is best" we should assume a linear relationship and predict the next term to be 15 (common difference 7). Even if we were presented with the first three terms, by the same principle of simplicity, a quadratic relationship should be assumed.
|
||||
|
||||
We shall define OP(k, n) to be the nth term of the optimum polynomial generating function for the first k terms of a sequence. It should be clear that OP(k, n) will accurately generate the terms of the sequence for n ≤ k, and potentially the first incorrect term (FIT) will be OP(k, k+1); in which case we shall call it a bad OP (BOP).
|
||||
We shall define $OP(k, n)$ to be the $n^{th}$ term of the optimum polynomial generating function for the first k terms of a sequence. It should be clear that $OP(k, n)$ will accurately generate the terms of the sequence for $n ≤ k$, and potentially the first incorrect term (FIT) will be $OP(k, k+1)$; in which case we shall call it a bad OP (BOP).
|
||||
|
||||
As a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for n ≥ 2, OP(1, n) = u1.
|
||||
As a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for $n ≥ 2, OP(1, n) = u_1$.
|
||||
|
||||
Hence we obtain the following OPs for the cubic sequence:
|
||||
|
||||
OP(1, n) = 1 1, 1, 1, 1, ... OP(2, n) = 7n−6 1, 8, 15, ... OP(3, n) = 6n2−11n+6 1, 8, 27, 58, ... OP(4, n) = n3 1, 8, 27, 64, 125, ...
|
||||
$$\begin{array}{ll} OP(1, n) = 1 & 1, {\color{red}1}, 1, 1, \ldots \\\\ OP(2, n) = 7n−6 & 1, 8, {\color{red}{15}}, \ldots \\\\ OP(3, n) = 6n^2−11n+6 & 1, 8, 27, {\color{red}{58}}, \ldots \\\\ OP(4, n) = n^3 & 1, 8, 27, 64, 125, \ldots \end{array}$$
|
||||
|
||||
Clearly no BOPs exist for k ≥ 4. By considering the sum of FITs generated by the BOPs (indicated in red above), we obtain 1 + 15 + 58 = 74. Consider the following tenth degree polynomial generating function: un = 1 − n + n2 − n3 + n4 − n5 + n6 − n7 + n8 − n9 + n10 Find the sum of FITs for the BOPs.
|
||||
Clearly no BOPs exist for k ≥ 4. By considering the sum of FITs generated by the BOPs (indicated in $\color{red}{red}$ above), we obtain 1 + 15 + 58 = 74. Consider the following tenth degree polynomial generating function:
|
||||
|
||||
$$u_n = 1 − n + n^2 − n^3 + n^4 − n^5 + n^6 − n^7 + n^8 − n^9 + n^{10}$$
|
||||
|
||||
Find the sum of FITs for the BOPs.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler101()` should return 37076114526.
|
||||
`optimumPolynomial()` should return `37076114526`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler101(), 37076114526);
|
||||
assert.strictEqual(optimumPolynomial(), 37076114526);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -37,12 +41,12 @@ assert.strictEqual(euler101(), 37076114526);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler101() {
|
||||
function optimumPolynomial() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler101();
|
||||
optimumPolynomial();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
File diff suppressed because one or more lines are too long
@ -8,30 +8,29 @@ dashedName: problem-103-special-subset-sums-optimum
|
||||
|
||||
# --description--
|
||||
|
||||
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
|
||||
Let $S(A)$ represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
|
||||
|
||||
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
|
||||
1. $S(B) ≠ S(C)$; that is, sums of subsets cannot be equal.
|
||||
2. If B contains more elements than C then $S(B) > S(C)$.
|
||||
|
||||
If B contains more elements than C then S(B) > S(C).
|
||||
If $S(A)$ is minimised for a given n, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.
|
||||
|
||||
If S(A) is minimised for a given n, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.
|
||||
$$\begin{align} & n = 1: \\{1\\} \\\\ & n = 2: \\{1, 2\\} \\\\ & n = 3: \\{2, 3, 4\\} \\\\ & n = 4: \\{3, 5, 6, 7\\} \\\\ & n = 5: \\{6, 9, 11, 12, 13\\} \\\\ \end{align}$$
|
||||
|
||||
n = 1: {1}n = 2: {1, 2}n = 3: {2, 3, 4}n = 4: {3, 5, 6, 7}n = 5: {6, 9, 11, 12, 13}
|
||||
It seems that for a given optimum set, $A = \\{a_1, a_2, \ldots, a_n\\}$, the next optimum set is of the form $B = \\{b, a_1 + b, a_2 + b, \ldots, a_n + b\\}$, where b is the "middle" element on the previous row.
|
||||
|
||||
It seems that for a given optimum set, A = {a1, a2, ... , an}, the next optimum set is of the form B = {b, a1+b, a2+b, ... ,an+b}, where b is the "middle" element on the previous row.
|
||||
By applying this "rule" we would expect the optimum set for $n = 6$ to be $A = \\{11, 17, 20, 22, 23, 24\\}$, with $S(A) = 117$. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for $n = 6$ is $A = \\{11, 18, 19, 20, 22, 25\\}$, with $S(A) = 115$ and corresponding set string: `111819202225`.
|
||||
|
||||
By applying this "rule" we would expect the optimum set for n = 6 to be A = {11, 17, 20, 22, 23, 24}, with S(A) = 117. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for n = 6 is A = {11, 18, 19, 20, 22, 25}, with S(A) = 115 and corresponding set string: 111819202225.
|
||||
Given that A is an optimum special sum set for $n = 7$, find its set string.
|
||||
|
||||
Given that A is an optimum special sum set for n = 7, find its set string.
|
||||
|
||||
NOTE: This problem is related to Problem 105 and Problem 106.
|
||||
**Note:** This problem is related to Problem 105 and Problem 106.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler103()` should return 20313839404245.
|
||||
`optimumSpecialSumSet()` should return the string `20313839404245`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler103(), 20313839404245);
|
||||
assert.strictEqual(optimumSpecialSumSet(), '20313839404245');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -39,12 +38,12 @@ assert.strictEqual(euler103(), 20313839404245);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler103() {
|
||||
function optimumSpecialSumSet() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler103();
|
||||
optimumSpecialSumSet();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,18 +10,18 @@ dashedName: problem-104-pandigital-fibonacci-ends
|
||||
|
||||
The Fibonacci sequence is defined by the recurrence relation:
|
||||
|
||||
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
|
||||
$F_n = F_{n − 1} + F_{n − 2}$, where $F_1 = 1$ and $F_2 = 1$
|
||||
|
||||
It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.
|
||||
It turns out that $F_{541}$, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1 - 9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And $F_{2749}$, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1 - 9 pandigital.
|
||||
|
||||
Given that Fk is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.
|
||||
Given that $F_k$ is the first Fibonacci number for which the first nine digits AND the last nine digits are 1 - 9 pandigital, find `k`.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler104()` should return 329468.
|
||||
`pandigitalFibonacciEnds()` should return `329468`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler104(), 329468);
|
||||
assert.strictEqual(pandigitalFibonacciEnds(), 329468);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +29,12 @@ assert.strictEqual(euler104(), 329468);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler104() {
|
||||
function pandigitalFibonacciEnds() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler104();
|
||||
pandigitalFibonacciEnds();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,37 +8,48 @@ dashedName: problem-105-special-subset-sums-testing
|
||||
|
||||
# --description--
|
||||
|
||||
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
|
||||
Let $S(A)$ represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
|
||||
|
||||
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
|
||||
1. $S(B) ≠ S(C)$; that is, sums of subsets cannot be equal.
|
||||
2. If B contains more elements than C then $S(B) > S(C)$.
|
||||
|
||||
If B contains more elements than C then S(B) > S(C).
|
||||
For example, {81, 88, 75, 42, 87, 84, 86, 65} is not a special sum set because 65 + 87 + 88 = 75 + 81 + 84, whereas {157, 150, 164, 119, 79, 159, 161, 139, 158} satisfies both rules for all possible subset pair combinations and $S(A) = 1286$.
|
||||
|
||||
For example, {81, 88, 75, 42, 87, 84, 86, 65} is not a special sum set because 65 + 87 + 88 = 75 + 81 + 84, whereas {157, 150, 164, 119, 79, 159, 161, 139, 158} satisfies both rules for all possible subset pair combinations and S(A) = 1286.
|
||||
Using `sets`, an array with one-hundred sets, containing seven to twelve elements (the two examples given above are the first two sets), identify all the special sum sets, $A_1, A_2, \ldots, A_k$, and find the value of $(A_1) + S(A_2) + \cdots + S(A_k)$.
|
||||
|
||||
Using sets.txt (right click and "Save Link/Target As..."), a 4K text file with one-hundred sets containing seven to twelve elements (the two examples given above are the first two sets in the file), identify all the special sum sets, A1, A2, ..., Ak, and find the value of S(A1) + S(A2) + ... + S(Ak).
|
||||
|
||||
NOTE: This problem is related to Problem 103 and Problem 106.
|
||||
**Note:** This problem is related to Problem 103 and Problem 106.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler105()` should return 73702.
|
||||
`testingSpecialSubsetSums(testSets)` should return `73702`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler105(), 73702);
|
||||
assert.strictEqual(testingSpecialSubsetSums(_testSets), 73702);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const _testSets = [
|
||||
[81,88,75,42,87,84,86,65],[157,150,164,119,79,159,161,139,158],[673,465,569,603,629,592,584,300,601,599,600],[90,85,83,84,65,87,76,46],[165,168,169,190,162,85,176,167,127],[224,275,278,249,277,279,289,295,139],[354,370,362,384,359,324,360,180,350,270],[599,595,557,298,448,596,577,667,597,588,602],[175,199,137,88,187,173,168,171,174],[93,187,196,144,185,178,186,202,182],[157,155,81,158,119,176,152,167,159],[184,165,159,166,163,167,174,124,83],[1211,1212,1287,605,1208,1189,1060,1216,1243,1200,908,1210],[339,299,153,305,282,304,313,306,302,228],[94,104,63,112,80,84,93,96],[41,88,82,85,61,74,83,81],[90,67,84,83,82,97,86,41],[299,303,151,301,291,302,307,377,333,280],[55,40,48,44,25,42,41],[1038,1188,1255,1184,594,890,1173,1151,1186,1203,1187,1195],[76,132,133,144,135,99,128,154],[77,46,108,81,85,84,93,83],[624,596,391,605,529,610,607,568,604,603,453],[83,167,166,189,163,174,160,165,133],[308,281,389,292,346,303,302,304,300,173],[593,1151,1187,1184,890,1040,1173,1186,1195,1255,1188,1203],[68,46,64,33,60,58,65],[65,43,88,87,86,99,93,90],[83,78,107,48,84,87,96,85],[1188,1173,1256,1038,1187,1151,890,1186,1184,1203,594,1195],[302,324,280,296,294,160,367,298,264,299],[521,760,682,687,646,664,342,698,692,686,672],[56,95,86,97,96,89,108,120],[344,356,262,343,340,382,337,175,361,330],[47,44,42,27,41,40,37],[139,155,161,158,118,166,154,156,78],[118,157,164,158,161,79,139,150,159],[299,292,371,150,300,301,281,303,306,262],[85,77,86,84,44,88,91,67],[88,85,84,44,65,91,76,86],[138,141,127,96,136,154,135,76],[292,308,302,346,300,324,304,305,238,166],[354,342,341,257,348,343,345,321,170,301],[84,178,168,167,131,170,193,166,162],[686,701,706,673,694,687,652,343,683,606,518],[295,293,301,367,296,279,297,263,323,159],[1038,1184,593,890,1188,1173,1187,1186,1195,1150,1203,1255],[343,364,388,402,191,383,382,385,288,374],[1187,1036,1183,591,1184,1175,888,1197,1182,1219,1115,1167],[151,291,307,303,345,238,299,323,301,302],[140,151,143,138,99,69,131,137],[29,44,42,59,41,36,40],[348,329,343,344,338,315,169,359,375,271],[48,39,34,37,50,40,41],[593,445,595,558,662,602,591,297,610,580,594],[686,651,681,342,541,687,691,707,604,675,699],[180,99,189,166,194,188,144,187,199],[321,349,335,343,377,176,265,356,344,332],[1151,1255,1195,1173,1184,1186,1188,1187,1203,593,1038,891],[90,88,100,83,62,113,80,89],[308,303,238,300,151,304,324,293,346,302],[59,38,50,41,42,35,40],[352,366,174,355,344,265,343,310,338,331],[91,89,93,90,117,85,60,106],[146,186,166,175,202,92,184,183,189],[82,67,96,44,80,79,88,76],[54,50,58,66,31,61,64],[343,266,344,172,308,336,364,350,359,333],[88,49,87,82,90,98,86,115],[20,47,49,51,54,48,40],[159,79,177,158,157,152,155,167,118],[1219,1183,1182,1115,1035,1186,591,1197,1167,887,1184,1175],[611,518,693,343,704,667,686,682,677,687,725],[607,599,634,305,677,604,603,580,452,605,591],[682,686,635,675,692,730,687,342,517,658,695],[662,296,573,598,592,584,553,593,595,443,591],[180,185,186,199,187,210,93,177,149],[197,136,179,185,156,182,180,178,99],[271,298,218,279,285,282,280,238,140],[1187,1151,890,593,1194,1188,1184,1173,1038,1186,1255,1203],[169,161,177,192,130,165,84,167,168],[50,42,43,41,66,39,36],[590,669,604,579,448,599,560,299,601,597,598],[174,191,206,179,184,142,177,180,90],[298,299,297,306,164,285,374,269,329,295],[181,172,162,138,170,195,86,169,168],[1184,1197,591,1182,1186,889,1167,1219,1183,1033,1115,1175],[644,695,691,679,667,687,340,681,770,686,517],[606,524,592,576,628,593,591,584,296,444,595],[94,127,154,138,135,74,136,141],[179,168,172,178,177,89,198,186,137],[302,299,291,300,298,149,260,305,280,370],[678,517,670,686,682,768,687,648,342,692,702],[302,290,304,376,333,303,306,298,279,153],[95,102,109,54,96,75,85,97],[150,154,146,78,152,151,162,173,119],[150,143,157,152,184,112,154,151,132],[36,41,54,40,25,44,42],[37,48,34,59,39,41,40],[681,603,638,611,584,303,454,607,606,605,596]
|
||||
];
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler105() {
|
||||
function testingSpecialSubsetSums(sets) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler105();
|
||||
const testSets = [
|
||||
[81,88,75,42,87,84,86,65],[157,150,164,119,79,159,161,139,158],[673,465,569,603,629,592,584,300,601,599,600],[90,85,83,84,65,87,76,46],[165,168,169,190,162,85,176,167,127],[224,275,278,249,277,279,289,295,139],[354,370,362,384,359,324,360,180,350,270],[599,595,557,298,448,596,577,667,597,588,602],[175,199,137,88,187,173,168,171,174],[93,187,196,144,185,178,186,202,182],[157,155,81,158,119,176,152,167,159],[184,165,159,166,163,167,174,124,83],[1211,1212,1287,605,1208,1189,1060,1216,1243,1200,908,1210],[339,299,153,305,282,304,313,306,302,228],[94,104,63,112,80,84,93,96],[41,88,82,85,61,74,83,81],[90,67,84,83,82,97,86,41],[299,303,151,301,291,302,307,377,333,280],[55,40,48,44,25,42,41],[1038,1188,1255,1184,594,890,1173,1151,1186,1203,1187,1195],[76,132,133,144,135,99,128,154],[77,46,108,81,85,84,93,83],[624,596,391,605,529,610,607,568,604,603,453],[83,167,166,189,163,174,160,165,133],[308,281,389,292,346,303,302,304,300,173],[593,1151,1187,1184,890,1040,1173,1186,1195,1255,1188,1203],[68,46,64,33,60,58,65],[65,43,88,87,86,99,93,90],[83,78,107,48,84,87,96,85],[1188,1173,1256,1038,1187,1151,890,1186,1184,1203,594,1195],[302,324,280,296,294,160,367,298,264,299],[521,760,682,687,646,664,342,698,692,686,672],[56,95,86,97,96,89,108,120],[344,356,262,343,340,382,337,175,361,330],[47,44,42,27,41,40,37],[139,155,161,158,118,166,154,156,78],[118,157,164,158,161,79,139,150,159],[299,292,371,150,300,301,281,303,306,262],[85,77,86,84,44,88,91,67],[88,85,84,44,65,91,76,86],[138,141,127,96,136,154,135,76],[292,308,302,346,300,324,304,305,238,166],[354,342,341,257,348,343,345,321,170,301],[84,178,168,167,131,170,193,166,162],[686,701,706,673,694,687,652,343,683,606,518],[295,293,301,367,296,279,297,263,323,159],[1038,1184,593,890,1188,1173,1187,1186,1195,1150,1203,1255],[343,364,388,402,191,383,382,385,288,374],[1187,1036,1183,591,1184,1175,888,1197,1182,1219,1115,1167],[151,291,307,303,345,238,299,323,301,302],[140,151,143,138,99,69,131,137],[29,44,42,59,41,36,40],[348,329,343,344,338,315,169,359,375,271],[48,39,34,37,50,40,41],[593,445,595,558,662,602,591,297,610,580,594],[686,651,681,342,541,687,691,707,604,675,699],[180,99,189,166,194,188,144,187,199],[321,349,335,343,377,176,265,356,344,332],[1151,1255,1195,1173,1184,1186,1188,1187,1203,593,1038,891],[90,88,100,83,62,113,80,89],[308,303,238,300,151,304,324,293,346,302],[59,38,50,41,42,35,40],[352,366,174,355,344,265,343,310,338,331],[91,89,93,90,117,85,60,106],[146,186,166,175,202,92,184,183,189],[82,67,96,44,80,79,88,76],[54,50,58,66,31,61,64],[343,266,344,172,308,336,364,350,359,333],[88,49,87,82,90,98,86,115],[20,47,49,51,54,48,40],[159,79,177,158,157,152,155,167,118],[1219,1183,1182,1115,1035,1186,591,1197,1167,887,1184,1175],[611,518,693,343,704,667,686,682,677,687,725],[607,599,634,305,677,604,603,580,452,605,591],[682,686,635,675,692,730,687,342,517,658,695],[662,296,573,598,592,584,553,593,595,443,591],[180,185,186,199,187,210,93,177,149],[197,136,179,185,156,182,180,178,99],[271,298,218,279,285,282,280,238,140],[1187,1151,890,593,1194,1188,1184,1173,1038,1186,1255,1203],[169,161,177,192,130,165,84,167,168],[50,42,43,41,66,39,36],[590,669,604,579,448,599,560,299,601,597,598],[174,191,206,179,184,142,177,180,90],[298,299,297,306,164,285,374,269,329,295],[181,172,162,138,170,195,86,169,168],[1184,1197,591,1182,1186,889,1167,1219,1183,1033,1115,1175],[644,695,691,679,667,687,340,681,770,686,517],[606,524,592,576,628,593,591,584,296,444,595],[94,127,154,138,135,74,136,141],[179,168,172,178,177,89,198,186,137],[302,299,291,300,298,149,260,305,280,370],[678,517,670,686,682,768,687,648,342,692,702],[302,290,304,376,333,303,306,298,279,153],[95,102,109,54,96,75,85,97],[150,154,146,78,152,151,162,173,119],[150,143,157,152,184,112,154,151,132],[36,41,54,40,25,44,42],[37,48,34,59,39,41,40],[681,603,638,611,584,303,454,607,606,605,596]
|
||||
];
|
||||
|
||||
testingSpecialSubsetSums(testSets);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,11 +8,10 @@ dashedName: problem-106-special-subset-sums-meta-testing
|
||||
|
||||
# --description--
|
||||
|
||||
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
|
||||
Let $S(A)$ represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
|
||||
|
||||
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
|
||||
|
||||
If B contains more elements than C then S(B) > S(C).
|
||||
1. $S(B) ≠ S(C)$; that is, sums of subsets cannot be equal.
|
||||
2. If B contains more elements than C then $S(B) > S(C)$.
|
||||
|
||||
For this problem we shall assume that a given set contains n strictly increasing elements and it already satisfies the second rule.
|
||||
|
||||
@ -20,14 +19,14 @@ Surprisingly, out of the 25 possible subset pairs that can be obtained from a se
|
||||
|
||||
For n = 12, how many of the 261625 subset pairs that can be obtained need to be tested for equality?
|
||||
|
||||
NOTE: This problem is related to Problem 103 and Problem 105.
|
||||
**Note:** This problem is related to Problem 103 and Problem 105.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler106()` should return 21384.
|
||||
`subsetSumsMetaTesting()` should return `21384`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler106(), 21384);
|
||||
assert.strictEqual(subsetSumsMetaTesting(), 21384);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,12 +34,12 @@ assert.strictEqual(euler106(), 21384);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler106() {
|
||||
function subsetSumsMetaTesting() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler106();
|
||||
subsetSumsMetaTesting();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
File diff suppressed because one or more lines are too long
@ -10,19 +10,17 @@ dashedName: problem-108-diophantine-reciprocals-i
|
||||
|
||||
In the following equation x, y, and n are positive integers.
|
||||
|
||||
1/`x` + 1/`y` = 1/`n`
|
||||
$$\frac{1}{x} + \frac{1}{y} = \frac{1}{n}$$
|
||||
|
||||
For `n` = 4 there are exactly three distinct solutions:
|
||||
|
||||
1/5 + 1/20 = 1/4
|
||||
1/6 + 1/12 = 1/4
|
||||
1/8 + 1/8 = 1/4
|
||||
$$\begin{align} & \frac{1}{5} + \frac{1}{20} = \frac{1}{4}\\\\ \\\\ & \frac{1}{6} + \frac{1}{12} = \frac{1}{4}\\\\ \\\\ & \frac{1}{8} + \frac{1}{8} = \frac{1}{4} \end{align}$$
|
||||
|
||||
What is the least value of `n` for which the number of distinct solutions exceeds one-thousand?
|
||||
|
||||
# --hints--
|
||||
|
||||
`diophantineOne()` should return 180180.
|
||||
`diophantineOne()` should return `180180`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(diophantineOne(), 180180);
|
||||
|
@ -10,28 +10,26 @@ dashedName: problem-109-darts
|
||||
|
||||
In the game of darts a player throws three darts at a target board which is split into twenty equal sized sections numbered one to twenty.
|
||||
|
||||
The score of a dart is determined by the number of the region that the dart lands in. A dart landing outside the red/green outer ring scores zero. The black and cream regions inside this ring represent single scores. However, the red/green outer ring and middle ring score double and treble scores respectively. At the centre of the board are two concentric circles called the bull region, or bulls-eye. The outer bull is worth 25 points and the inner bull is a double, worth 50 points. There are many variations of rules but in the most popular game the players will begin with a score 301 or 501 and the first player to reduce their running total to zero is a winner. However, it is normal to play a "doubles out" system, which means that the player must land a double (including the double bulls-eye at the centre of the board) on their final dart to win; any other dart that would reduce their running total to one or lower means the score for that set of three darts is "bust". When a player is able to finish on their current score it is called a "checkout" and the highest checkout is 170: T20 T20 D25 (two treble 20s and double bull). There are exactly eleven distinct ways to checkout on a score of 6:
|
||||
<img class="img-responsive center-block" alt="Darts board" src="https://cdn.freecodecamp.org/curriculum/project-euler/darts.png" style="background-color: white; padding: 10px;" />
|
||||
|
||||
D3
|
||||
The score of a dart is determined by the number of the region that the dart lands in. A dart landing outside the red/green outer ring scores zero. The black and cream regions inside this ring represent single scores. However, the red/green outer ring and middle ring score double and treble scores respectively.
|
||||
|
||||
D1 D2
|
||||
At the center of the board are two concentric circles called the bull region, or bulls-eye. The outer bull is worth 25 points and the inner bull is a double, worth 50 points.
|
||||
|
||||
S2 D2
|
||||
There are many variations of rules but in the most popular game the players will begin with a score of 301 or 501 and the first player to reduce their running total to zero is a winner. However, it is normal to play a "doubles out" system, which means that the player must land a double (including the double bulls-eye at the center of the board) on their final dart to win; any other dart that would reduce their running total to one or lower means the score for that set of three darts is "bust".
|
||||
|
||||
D2 D1
|
||||
When a player is able to finish on their current score it is called a "checkout" and the highest checkout is 170: T20 T20 D25 (two treble 20s and double bull). There are exactly eleven distinct ways to checkout on a score of 6:
|
||||
|
||||
S4 D1
|
||||
$$\begin{array} \text{D3} & & \\\\ D1 & D2 & \\\\ S2 & D2 & \\\\ D2 & D1 & \\\\ S4 & D1 & \\\\ S1 & S1 & D2 \\\\ S1 & T1 & D1 \\\\ S1 & S3 & D1 \\\\ D1 & D1 & D1 \\\\ D1 & S2 & D1 \\\\ S2 & S2 & D1 \end{array}$$
|
||||
|
||||
S1 S1 D2 S1 T1 D1 S1 S3 D1 D1 D1 D1 D1 S2 D1 S2 S2 D1
|
||||
|
||||
Note that D1 D2 is considered different to D2 D1 as they finish on different doubles. However, the combination S1 T1 D1 is considered the same as T1 S1 D1. In addition we shall not include misses in considering combinations; for example, D3 is the same as 0 D3 and 0 0 D3. Incredibly there are 42336 distinct ways of checking out in total. How many distinct ways can a player checkout with a score less than 100?
|
||||
Note that D1 D2 is considered different from D2 D1 as they finish on different doubles. However, the combination S1 T1 D1 is considered the same as T1 S1 D1. In addition, we shall not include misses in considering combinations; for example, D3 is the same as 0 D3 and 0 0 D3. Incredibly there are 42336 distinct ways of checking out in total. How many distinct ways can a player checkout with a score less than 100?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler109()` should return 38182.
|
||||
`darts()` should return `38182`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler109(), 38182);
|
||||
assert.strictEqual(darts(), 38182);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -39,12 +37,12 @@ assert.strictEqual(euler109(), 38182);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler109() {
|
||||
function darts() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler109();
|
||||
darts();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,15 +10,17 @@ dashedName: problem-110-diophantine-reciprocals-ii
|
||||
|
||||
In the following equation x, y, and n are positive integers.
|
||||
|
||||
1/`x` + 1/`y` = 1/`n`
|
||||
$$\frac{1}{x} + \frac{1}{y} = \frac{1}{n}$$
|
||||
|
||||
It can be verified that when `n` = 1260 there are 113 distinct solutions and this is the least value of `n` for which the total number of distinct solutions exceeds one hundred.
|
||||
|
||||
What is the least value of `n` for which the number of distinct solutions exceeds four million?
|
||||
|
||||
**Note:** This problem is a much more difficult version of Problem 108 and as it is well beyond the limitations of a brute force approach it requires a clever implementation.
|
||||
|
||||
# --hints--
|
||||
|
||||
`diophantineTwo()` should return 9350130049860600.
|
||||
`diophantineTwo()` should return `9350130049860600`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(diophantineTwo(), 9350130049860600);
|
||||
|
@ -10,24 +10,35 @@ dashedName: problem-111-primes-with-runs
|
||||
|
||||
Considering 4-digit primes containing repeated digits it is clear that they cannot all be the same: 1111 is divisible by 11, 2222 is divisible by 22, and so on. But there are nine 4-digit primes containing three ones:
|
||||
|
||||
1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111
|
||||
$$1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111$$
|
||||
|
||||
We shall say that M(n, d) represents the maximum number of repeated digits for an n-digit prime where d is the repeated digit, N(n, d) represents the number of such primes, and S(n, d) represents the sum of these primes.
|
||||
We shall say that $M(n, d)$ represents the maximum number of repeated digits for an n-digit prime where d is the repeated digit, $N(n, d)$ represents the number of such primes, and $S(n, d)$ represents the sum of these primes.
|
||||
|
||||
So M(4, 1) = 3 is the maximum number of repeated digits for a 4-digit prime where one is the repeated digit, there are N(4, 1) = 9 such primes, and the sum of these primes is S(4, 1) = 22275. It turns out that for d = 0, it is only possible to have M(4, 0) = 2 repeated digits, but there are N(4, 0) = 13 such cases.
|
||||
So $M(4, 1) = 3$ is the maximum number of repeated digits for a 4-digit prime where one is the repeated digit, there are $N(4, 1) = 9$ such primes, and the sum of these primes is $S(4, 1) = 22275$. It turns out that for d = 0, it is only possible to have $M(4, 0) = 2$ repeated digits, but there are $N(4, 0) = 13$ such cases.
|
||||
|
||||
In the same way we obtain the following results for 4-digit primes.
|
||||
|
||||
Digit, d M(4, d) N(4, d) S(4, d) 0 2 13 67061 1 3 9 22275 2 3 1 2221 3 3 12 46214 4 3 2 8888 5 3 1 5557 6 3 1 6661 7 3 9 57863 8 3 1 8887 9 3 7 48073
|
||||
| Digit, d | $M(4, d)$ | $N(4, d)$ | $S(4, d)$ |
|
||||
| -------- | --------- | --------- | --------- |
|
||||
| 0 | 2 | 13 | 67061 |
|
||||
| 1 | 3 | 9 | 22275 |
|
||||
| 2 | 3 | 1 | 2221 |
|
||||
| 3 | 3 | 12 | 46214 |
|
||||
| 4 | 3 | 2 | 8888 |
|
||||
| 5 | 3 | 1 | 5557 |
|
||||
| 6 | 3 | 1 | 6661 |
|
||||
| 7 | 3 | 9 | 57863 |
|
||||
| 8 | 3 | 1 | 8887 |
|
||||
| 9 | 3 | 7 | 48073 |
|
||||
|
||||
For d = 0 to 9, the sum of all S(4, d) is 273700. Find the sum of all S(10, d).
|
||||
For d = 0 to 9, the sum of all $S(4, d)$ is 273700. Find the sum of all $S(10, d)$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler111()` should return 612407567715.
|
||||
`primesWithRuns()` should return `612407567715`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler111(), 612407567715);
|
||||
assert.strictEqual(primesWithRuns(), 612407567715);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,12 +46,12 @@ assert.strictEqual(euler111(), 612407567715);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler111() {
|
||||
function primesWithRuns() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler111();
|
||||
primesWithRuns();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -22,10 +22,10 @@ Find the least number for which the proportion of bouncy numbers is exactly 99%.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler112()` should return 1587000.
|
||||
`bouncyNumbers()` should return `1587000`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler112(), 1587000);
|
||||
assert.strictEqual(bouncyNumbers(), 1587000);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +33,12 @@ assert.strictEqual(euler112(), 1587000);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler112() {
|
||||
function bouncyNumbers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler112();
|
||||
bouncyNumbers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -14,16 +14,16 @@ Similarly if no digit is exceeded by the digit to its right it is called a decre
|
||||
|
||||
We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number; for example, 155349.
|
||||
|
||||
As n increases, the proportion of bouncy numbers below n increases such that there are only 12951 numbers below one-million that are not bouncy and only 277032 non-bouncy numbers below 1010.
|
||||
As n increases, the proportion of bouncy numbers below n increases such that there are only 12951 numbers below one-million that are not bouncy and only 277032 non-bouncy numbers below ${10}^{10}$.
|
||||
|
||||
How many numbers below a googol (10100) are not bouncy?
|
||||
How many numbers below a googol (${10}^{100}$) are not bouncy?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler113()` should return 51161058134250.
|
||||
`nonBouncyNumbers()` should return `51161058134250`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler113(), 51161058134250);
|
||||
assert.strictEqual(nonBouncyNumbers(), 51161058134250);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +31,12 @@ assert.strictEqual(euler113(), 51161058134250);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler113() {
|
||||
function nonBouncyNumbers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler113();
|
||||
nonBouncyNumbers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,14 +10,18 @@ dashedName: problem-114-counting-block-combinations-i
|
||||
|
||||
A row measuring seven units in length has red blocks with a minimum length of three units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square. There are exactly seventeen ways of doing this.
|
||||
|
||||
How many ways can a row measuring fifty units in length be filled? NOTE: Although the example above does not lend itself to the possibility, in general it is permitted to mix block sizes. For example, on a row measuring eight units in length you could use red (3), black (1), and red (4).
|
||||
<img class="img-responsive center-block" alt="Possible ways of placing block with a minimum length of three units, on a row with length of seven units" src="https://cdn.freecodecamp.org/curriculum/project-euler/counting-block-combinations-i.png" style="background-color: white; padding: 10px;" />
|
||||
|
||||
How many ways can a row measuring fifty units in length be filled?
|
||||
|
||||
**Note:** Although the example above does not lend itself to the possibility, in general it is permitted to mix block sizes. For example, on a row measuring eight units in length you could use red (3), black (1), and red (4).
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler114()` should return 16475640049.
|
||||
`countingBlockOne()` should return `16475640049`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler114(), 16475640049);
|
||||
assert.strictEqual(countingBlockOne(), 16475640049);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -25,12 +29,12 @@ assert.strictEqual(euler114(), 16475640049);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler114() {
|
||||
function countingBlockOne() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler114();
|
||||
countingBlockOne();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,26 +8,26 @@ dashedName: problem-115-counting-block-combinations-ii
|
||||
|
||||
# --description--
|
||||
|
||||
NOTE: This is a more difficult version of Problem 114.
|
||||
A row measuring `n` units in length has red blocks with a minimum length of `m` units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.
|
||||
|
||||
A row measuring n units in length has red blocks with a minimum length of m units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.
|
||||
Let the fill-count function, $F(m, n)$, represent the number of ways that a row can be filled.
|
||||
|
||||
Let the fill-count function, F(m, n), represent the number of ways that a row can be filled.
|
||||
|
||||
For example, F(3, 29) = 673135 and F(3, 30) = 1089155.
|
||||
For example, $F(3, 29) = 673135$ and $F(3, 30) = 1089155$.
|
||||
|
||||
That is, for m = 3, it can be seen that n = 30 is the smallest value for which the fill-count function first exceeds one million.
|
||||
|
||||
In the same way, for m = 10, it can be verified that F(10, 56) = 880711 and F(10, 57) = 1148904, so n = 57 is the least value for which the fill-count function first exceeds one million.
|
||||
In the same way, for m = 10, it can be verified that $F(10, 56) = 880711$ and $F(10, 57) = 1148904$, so n = 57 is the least value for which the fill-count function first exceeds one million.
|
||||
|
||||
For m = 50, find the least value of n for which the fill-count function first exceeds one million.
|
||||
For m = 50, find the least value of `n` for which the fill-count function first exceeds one million.
|
||||
|
||||
**Note:** This is a more difficult version of Problem 114.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler115()` should return 168.
|
||||
`countingBlockTwo()` should return `168`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler115(), 168);
|
||||
assert.strictEqual(countingBlockTwo(), 168);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,12 +35,12 @@ assert.strictEqual(euler115(), 168);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler115() {
|
||||
function countingBlockTwo() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler115();
|
||||
countingBlockTwo();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,18 +12,26 @@ A row of five black square tiles is to have a number of its tiles replaced with
|
||||
|
||||
If red tiles are chosen there are exactly seven ways this can be done.
|
||||
|
||||
<img class="img-responsive center-block" alt="Possible ways to placing red oblong on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-or-blue-tiles-1.png" style="background-color: white; padding: 10px;" />
|
||||
|
||||
If green tiles are chosen there are three ways.
|
||||
|
||||
<img class="img-responsive center-block" alt="Possible ways of placing green oblong on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-or-blue-tiles-2.png" style="background-color: white; padding: 10px;" />
|
||||
|
||||
And if blue tiles are chosen there are two ways.
|
||||
|
||||
Assuming that colours cannot be mixed there are 7 + 3 + 2 = 12 ways of replacing the black tiles in a row measuring five units in length. How many different ways can the black tiles in a row measuring fifty units in length be replaced if colours cannot be mixed and at least one coloured tile must be used? NOTE: This is related to Problem 117.
|
||||
<img class="img-responsive center-block" alt="Possible ways of placing blue oblong on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-or-blue-tiles-3.png" style="background-color: white; padding: 10px;" />
|
||||
|
||||
Assuming that colors cannot be mixed there are 7 + 3 + 2 = 12 ways of replacing the black tiles in a row measuring five units in length. How many different ways can the black tiles in a row measuring fifty units in length be replaced if colors cannot be mixed and at least one colored tile must be used?
|
||||
|
||||
**Note:** This is related to Problem 117.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler116()` should return 20492570929.
|
||||
`redGreenBlueOne()` should return `20492570929`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler116(), 20492570929);
|
||||
assert.strictEqual(redGreenBlueOne(), 20492570929);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +39,12 @@ assert.strictEqual(euler116(), 20492570929);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler116() {
|
||||
function redGreenBlueOne() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler116();
|
||||
redGreenBlueOne();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,14 +10,18 @@ dashedName: problem-117-red-green-and-blue-tiles
|
||||
|
||||
Using a combination of black square tiles and oblong tiles chosen from: red tiles measuring two units, green tiles measuring three units, and blue tiles measuring four units, it is possible to tile a row measuring five units in length in exactly fifteen different ways.
|
||||
|
||||
How many ways can a row measuring fifty units in length be tiled? NOTE: This is related to Problem 116.
|
||||
<img class="img-responsive center-block" alt="Possible ways of placing red, green and blue oblongs on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-and-blue-tiles.png" style="background-color: white; padding: 10px;" />
|
||||
|
||||
How many ways can a row measuring fifty units in length be tiled?
|
||||
|
||||
**Note**: This is related to Problem 116.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler117()` should return 100808458960497.
|
||||
`redGreenBlueTilesTwo()` should return `100808458960497`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler117(), 100808458960497);
|
||||
assert.strictEqual(redGreenBlueTilesTwo(), 100808458960497);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -25,12 +29,12 @@ assert.strictEqual(euler117(), 100808458960497);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler117() {
|
||||
function redGreenBlueTilesTwo() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler117();
|
||||
redGreenBlueTilesTwo();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,16 +8,16 @@ dashedName: problem-118-pandigital-prime-sets
|
||||
|
||||
# --description--
|
||||
|
||||
Using all of the digits 1 through 9 and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set {2,5,47,89,631}, all of the elements belonging to it are prime.
|
||||
Using all of the digits 1 through 9 and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set $\\{2, 5, 47, 89, 631\\}$, all of the elements belonging to it are prime.
|
||||
|
||||
How many distinct sets containing each of the digits one through nine exactly once contain only prime elements?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler118()` should return 44680.
|
||||
`pandigitalPrimeSets()` should return `44680`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler118(), 44680);
|
||||
assert.strictEqual(pandigitalPrimeSets(), 44680);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -25,12 +25,12 @@ assert.strictEqual(euler118(), 44680);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler118() {
|
||||
function pandigitalPrimeSets() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler118();
|
||||
pandigitalPrimeSets();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,20 @@ dashedName: problem-119-digit-power-sum
|
||||
|
||||
# --description--
|
||||
|
||||
The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
|
||||
The number 512 is interesting because it is equal to the sum of its digits raised to some power: $5 + 1 + 2 = 8$, and $8^3 = 512$. Another example of a number with this property is $614656 = 28^4$.
|
||||
|
||||
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
|
||||
We shall define an to be the $n-th$ term of this sequence and insist that a number must contain at least two digits to have a sum.
|
||||
|
||||
You are given that a2 = 512 and a10 = 614656.
|
||||
You are given that $a_2 = 512$ and $a_{10} = 614656$.
|
||||
|
||||
Find a30.
|
||||
Find $a_{30}$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler119()` should return 248155780267521.
|
||||
`digitPowerSum()` should return `248155780267521`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler119(), 248155780267521);
|
||||
assert.strictEqual(digitPowerSum(), 248155780267521);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +29,12 @@ assert.strictEqual(euler119(), 248155780267521);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler119() {
|
||||
function digitPowerSum() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler119();
|
||||
digitPowerSum();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-120-square-remainders
|
||||
|
||||
# --description--
|
||||
|
||||
Let r be the remainder when (a−1)n + (a+1)n is divided by a2.
|
||||
Let `r` be the remainder when ${(a − 1)}^n + {(a + 1)}^n$ is divided by $a^2$.
|
||||
|
||||
For example, if a = 7 and n = 3, then r = 42: 63 + 83 = 728 ≡ 42 mod 49. And as n varies, so too will r, but for a = 7 it turns out that rmax = 42.
|
||||
For example, if $a = 7$ and $n = 3$, then $r = 42: 6^3 + 8^3 = 728 ≡ 42 \\ \text{mod}\\ 49$. And as `n` varies, so too will `r`, but for $a = 7$ it turns out that $r_{max} = 42$.
|
||||
|
||||
For 3 ≤ a ≤ 1000, find ∑ rmax.
|
||||
For $3 ≤ a ≤ 1000$, find $\sum{r}_{max}$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler120()` should return 333082500.
|
||||
`squareRemainders()` should return `333082500`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler120(), 333082500);
|
||||
assert.strictEqual(squareRemainders(), 333082500);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler120(), 333082500);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler120() {
|
||||
function squareRemainders() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler120();
|
||||
squareRemainders();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,16 +10,48 @@ dashedName: problem-182-rsa-encryption
|
||||
|
||||
The RSA encryption is based on the following procedure:
|
||||
|
||||
Generate two distinct primes p and q.Compute n=pq and φ=(p-1)(q-1).
|
||||
Generate two distinct primes `p` and `q`. Compute `n=p*q` and `φ=(p-1)(q-1)`. Find an integer `e`, `1 < e < φ`, such that `gcd(e,φ) = 1`
|
||||
|
||||
Find an integer e, 1<e<φ, such='' that='' gcd(e,φ)='1.' a='' message='' in='' this='' system='' is='' number='' the='' interval='' \[0,n-1].='' text='' to='' be='' encrypted='' then='' somehow='' converted='' messages='' (numbers='' \[0,n-1]).='' encrypt='' text,='' for='' each='' message,='' m,='' c='me' mod='' n='' calculated.='' decrypt='' following='' procedure='' needed:='' calculate='' d='' ed='1' φ,='' c,='' m='cd' n.='' there='' exist='' values='' of='' e='' and='' me='' call='' which='' unconcealed='' messages.='' an='' issue='' when='' choosing='' should='' not='' too='' many='' instance,='' let='' p='19' q='37.' φ='18\*36=648.' if='' we='' choose='' then,='' although='' gcd(181,648)='1' it='' turns='' out='' all='' possible='' messagesm='' (0≤m≤n-1)='' are='' calculating='' any='' valid='' choice='' some='' it's='' important='' at='' minimum.='' find='' sum='' e,='' 1<e<φ(1009,3643)='' so='' value='' <='' section=''></e<φ,>
|
||||
A message in this system is a number in the interval `[0,n-1]`. A text to be encrypted is then somehow converted to messages (numbers in the interval `[0,n-1]`). To encrypt the text, for each message, `m`, c=m<sup>e</sup> mod n is calculated.
|
||||
|
||||
To decrypt the text, the following procedure is needed: calculate `d` such that `ed=1 mod φ`, then for each encrypted message, `c`, calculate m=c<sup>d</sup> mod n.
|
||||
|
||||
There exist values of `e` and `m` such that m<sup>e</sup> mod n = m. We call messages `m` for which m<sup>e</sup> mod n=m unconcealed messages.
|
||||
|
||||
An issue when choosing `e` is that there should not be too many unconcealed messages. For instance, let `p=19` and `q=37`. Then `n=19*37=703` and `φ=18*36=648`. If we choose `e=181`, then, although `gcd(181,648)=1` it turns out that all possible messages m `(0≤m≤n-1)` are unconcealed when calculating m<sup>e</sup> mod n. For any valid choice of `e` there exist some unconcealed messages. It's important that the number of unconcealed messages is at a minimum.
|
||||
|
||||
For any given `p` and `q`, find the sum of all values of `e`, `1 < e < φ(p,q)` and `gcd(e,φ)=1`, so that the number of unconcealed messages for this value of `e` is at a minimum.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler182()` should return 399788195976.
|
||||
`RSAEncryption` should be a function.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler182(), 399788195976);
|
||||
assert(typeof RSAEncryption === 'function')
|
||||
```
|
||||
|
||||
`RSAEncryption` should return a number.
|
||||
|
||||
```js
|
||||
assert.strictEqual(typeof RSAEncryption(19, 37), 'number');
|
||||
```
|
||||
|
||||
`RSAEncryption(19, 37)` should return `17766`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(RSAEncryption(19, 37), 17766);
|
||||
```
|
||||
|
||||
`RSAEncryption(283, 409)` should return `466196580`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(RSAEncryption(283, 409), 466196580);
|
||||
```
|
||||
|
||||
`RSAEncryption(1009, 3643)` should return `399788195976`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(RSAEncryption(19, 37), 17766);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,16 +59,44 @@ assert.strictEqual(euler182(), 399788195976);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler182() {
|
||||
function RSAEncryption(p, q) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler182();
|
||||
RSAEncryption(19, 37);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function gcd(a, b) {
|
||||
if (b)
|
||||
return gcd(b, a % b);
|
||||
else
|
||||
return a;
|
||||
}
|
||||
|
||||
function RSAEncryption(p, q) {
|
||||
let phi = (p - 1) * (q - 1);
|
||||
|
||||
let best = Number.MAX_SAFE_INTEGER;
|
||||
let sum = 0;
|
||||
|
||||
for (let e = 0; e < phi; ++e) {
|
||||
if (!(gcd(e, phi) == 1))
|
||||
continue;
|
||||
|
||||
let msg = (gcd(p - 1, e - 1) + 1) * (gcd(q - 1, e - 1) + 1);
|
||||
|
||||
if (best == msg) {
|
||||
sum += e;
|
||||
} else if (best > msg) {
|
||||
best = msg;
|
||||
sum = e;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
```
|
||||
|
@ -12,22 +12,46 @@ We shall say that an `n`-digit number is pandigital if it makes use of all the d
|
||||
|
||||
The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.
|
||||
|
||||
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
||||
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through `n` pandigital.
|
||||
|
||||
**Hint:** Some products can be obtained in more than one way so be sure to only include it once in your sum.
|
||||
|
||||
# --hints--
|
||||
|
||||
`pandigitalProducts()` should return a number.
|
||||
`pandigitalProducts(4)` should return a number.
|
||||
|
||||
```js
|
||||
assert(typeof pandigitalProducts() === 'number');
|
||||
assert(typeof pandigitalProducts(4) === 'number');
|
||||
```
|
||||
|
||||
`pandigitalProducts()` should return 45228.
|
||||
`pandigitalProducts(4)` should return `12`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalProducts(), 45228);
|
||||
assert.strictEqual(pandigitalProducts(4), 12);
|
||||
```
|
||||
|
||||
`pandigitalProducts(6)` should return `162`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalProducts(6), 162);
|
||||
```
|
||||
|
||||
`pandigitalProducts(7)` should return `0`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalProducts(7), 0);
|
||||
```
|
||||
|
||||
`pandigitalProducts(8)` should return `13458`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalProducts(8), 13458);
|
||||
```
|
||||
|
||||
`pandigitalProducts(9)` should return `45228`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalProducts(9), 45228);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,22 +59,21 @@ assert.strictEqual(pandigitalProducts(), 45228);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function pandigitalProducts() {
|
||||
function pandigitalProducts(n) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
pandigitalProducts();
|
||||
pandigitalProducts(4);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function pandigitalProducts() {
|
||||
function is1to9Pandigital(...numbers) {
|
||||
const digitStr = concatenateNums(...numbers);
|
||||
// check if length is 9
|
||||
if (digitStr.length !== 9) {
|
||||
function pandigitalProducts(n) {
|
||||
function is1toNPandigital(n, digitStr) {
|
||||
// check if length is n
|
||||
if (digitStr.length !== n) {
|
||||
return false;
|
||||
}
|
||||
// check if pandigital
|
||||
@ -70,15 +93,24 @@ function pandigitalProducts() {
|
||||
}
|
||||
|
||||
const pandigitalNums = [];
|
||||
const limit = 10 ** Math.floor(n / 2) - 1;
|
||||
let sum = 0;
|
||||
for (let mult1 = 2; mult1 < 9876; mult1++) {
|
||||
let mult2 = 123;
|
||||
while (concatenateNums(mult1, mult2, mult1 * mult2).length < 10) {
|
||||
if (is1to9Pandigital(mult1, mult2, mult1 * mult2) && !pandigitalNums.includes(mult1 * mult2)) {
|
||||
pandigitalNums.push(mult1 * mult2);
|
||||
sum += mult1 * mult2;
|
||||
for (let mult1 = 2; mult1 < limit; mult1++) {
|
||||
for (let mult2 = 2; mult2 < limit; mult2++) {
|
||||
const product = mult1 * mult2;
|
||||
const concatenated = concatenateNums(mult1, mult2, product);
|
||||
if (concatenated.length > n) {
|
||||
break;
|
||||
} else if (concatenated.length < n) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
is1toNPandigital(n, concatenated) &&
|
||||
!pandigitalNums.includes(product)
|
||||
) {
|
||||
pandigitalNums.push(product);
|
||||
sum += product;
|
||||
}
|
||||
mult2++;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
|
@ -16,7 +16,7 @@ The ant is always oriented in one of the cardinal directions (left, right, up or
|
||||
|
||||
\- if it is on a white square, it flips the color of the square to black, rotates 90 degrees clockwise and moves forward one square.
|
||||
|
||||
Starting with a grid that is entirely white, how many squares are black after 1018 moves of the ant?
|
||||
Starting with a grid that is entirely white, how many squares are black after 10<sup>18</sup> moves of the ant?
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -10,30 +10,32 @@ dashedName: problem-38-pandigital-multiples
|
||||
|
||||
Take the number 192 and multiply it by each of 1, 2, and 3:
|
||||
|
||||
<div style='margin-left: 4em;'>
|
||||
192 × 1 = 192<br>
|
||||
192 × 2 = 384<br>
|
||||
192 × 3 = 576<br>
|
||||
</div>
|
||||
$$\begin{align} 192 × 1 = 192\\\\ 192 × 2 = 384\\\\ 192 × 3 = 576\\\\ \end{align}$$
|
||||
|
||||
By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1, 2, 3).
|
||||
|
||||
The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1, 2, 3, 4, 5).
|
||||
|
||||
What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1, 2, ... , `n`) where `n` > 1?
|
||||
What is the largest 1 to `k` pandigital `k`-digit number that can be formed as the concatenated product of an integer with (1, 2, ..., `n`) where `n` > 1?
|
||||
|
||||
# --hints--
|
||||
|
||||
`pandigitalMultiples()` should return a number.
|
||||
`pandigitalMultiples(8)` should return a number.
|
||||
|
||||
```js
|
||||
assert(typeof pandigitalMultiples() === 'number');
|
||||
assert(typeof pandigitalMultiples(8) === 'number');
|
||||
```
|
||||
|
||||
`pandigitalMultiples()` should return 932718654.
|
||||
`pandigitalMultiples(8)` should return `78156234`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalMultiples(), 932718654);
|
||||
assert.strictEqual(pandigitalMultiples(8), 78156234);
|
||||
```
|
||||
|
||||
`pandigitalMultiples(9)` should return `932718654`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(pandigitalMultiples(9), 932718654);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -41,38 +43,37 @@ assert.strictEqual(pandigitalMultiples(), 932718654);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function pandigitalMultiples() {
|
||||
function pandigitalMultiples(k) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
pandigitalMultiples();
|
||||
pandigitalMultiples(8);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function pandigitalMultiples() {
|
||||
|
||||
function get9DigitConcatenatedProduct(num) {
|
||||
// returns false if concatenated product is not 9 digits
|
||||
function pandigitalMultiples(k) {
|
||||
function getKDigitConcatenatedProduct(num, k) {
|
||||
// returns false if concatenated product is not k digits
|
||||
let concatenatedProduct = num.toString();
|
||||
for (let i = 2; concatenatedProduct.length < 9; i++) {
|
||||
for (let i = 2; concatenatedProduct.length < k; i++) {
|
||||
concatenatedProduct += num * i;
|
||||
}
|
||||
return concatenatedProduct.length === 9 ? concatenatedProduct : false;
|
||||
return concatenatedProduct.length === k ? concatenatedProduct : false;
|
||||
}
|
||||
|
||||
function is1to9Pandigital(num) {
|
||||
function is1toKPandigital(num, k) {
|
||||
const numStr = num.toString();
|
||||
|
||||
// check if length is not 9
|
||||
if (numStr.length !== 9) {
|
||||
// check if length is not k
|
||||
if (numStr.length !== k) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if pandigital
|
||||
for (let i = 9; i > 0; i--) {
|
||||
for (let i = k; i > 0; i--) {
|
||||
if (numStr.indexOf(i.toString()) === -1) {
|
||||
return false;
|
||||
}
|
||||
@ -81,11 +82,13 @@ function pandigitalMultiples() {
|
||||
}
|
||||
|
||||
let largestNum = 0;
|
||||
for (let i = 9999; i >= 9000; i--) {
|
||||
const concatenatedProduct = get9DigitConcatenatedProduct(i);
|
||||
if (is1to9Pandigital(concatenatedProduct) && concatenatedProduct > largestNum) {
|
||||
largestNum = parseInt(concatenatedProduct);
|
||||
break;
|
||||
for (let i = 10 ** Math.floor(k / 2) + 1; i >= 1; i--) {
|
||||
const concatenatedProduct = getKDigitConcatenatedProduct(i, k);
|
||||
if (is1toKPandigital(concatenatedProduct, k)) {
|
||||
const number = parseInt(concatenatedProduct, 10);
|
||||
if (number > largestNum) {
|
||||
largestNum = number;
|
||||
}
|
||||
}
|
||||
}
|
||||
return largestNum;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user