chore(i18n,chn): manually downloaded curriculum (#42858)
This commit is contained in:
committed by
GitHub
parent
eef1805fe6
commit
7eb0630f2d
@ -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