diff --git a/content/1_General/Lambda_Funcs.mdx b/content/1_General/Lambda_Funcs.mdx index a21e1ad7bd..50d0eb7639 100644 --- a/content/1_General/Lambda_Funcs.mdx +++ b/content/1_General/Lambda_Funcs.mdx @@ -49,14 +49,15 @@ description: 'Defining anonymous function objects.' ## Why Use Lambdas? -Lambdas allow us to write simple and anonymous functions in place. +Lambdas allow us to write simple and anonymous functions inline. This allows us to write smaller functions while keeping code local and organized. In addition, lambdas can capture their surrounding variables, which is often convenient when writing helper functions. -In addition, the C++ standard library has good support for lambdas, with functions +The C++ standard library has good support for lambdas, with functions like `std::sort` and `std::lower_bound` allowing you to pass custom functions -to act as a comparator of objects. +to act as a comparator of objects. This is often more convenient than the +alternative of writing a dedicated function to act as a comparator. ## General Form Lambdas have the following form: @@ -93,6 +94,9 @@ Then, you can call the lambda like a normal function. cout << square(10) << '\n'; // prints out 100 ``` +As mentioned in the [custom comparator module](/silver/sorting-custom?lang=cpp) +module, lambdas can also be used as comparators. + ## Recursive Lambdas Let's say we want to write a recursive GCD function. With a lambda, the most @@ -169,9 +173,9 @@ int main() { } ``` -### With `auto` as a parameter: -The main issue with recursive lambdas is that a lambda typically cannot access -itself. To fix this, we pass the lambda into itself. +### With Generic Lambdas +To remedy the issue of the lambda being unable to access itself, we pass it +into itself. ```cpp int main() { diff --git a/content/4_Gold/Combinatorics.problems.json b/content/4_Gold/Combinatorics.problems.json index 73e2e890cc..67a4eb2bc9 100644 --- a/content/4_Gold/Combinatorics.problems.json +++ b/content/4_Gold/Combinatorics.problems.json @@ -149,10 +149,10 @@ } }, { - "uniqueId": "ac-XorPyramid", + "uniqueId": "cses-2419", "name": "Xor Pyramid", "url": "https://cses.fi/problemset/task/2419", - "source": "AC", + "source": "CSES", "difficulty": "Normal", "isStarred": false, "tags": ["Combinatorics", "Bitwise"], diff --git a/solutions/gold/ac-XorPyramid.mdx b/solutions/gold/cses-2419.mdx similarity index 99% rename from solutions/gold/ac-XorPyramid.mdx rename to solutions/gold/cses-2419.mdx index 52f2d73c72..09a254ba6c 100644 --- a/solutions/gold/ac-XorPyramid.mdx +++ b/solutions/gold/cses-2419.mdx @@ -1,5 +1,5 @@ --- -id: ac-XorPyramid +id: cses-2419 source: AC title: Xor Pyramid author: Mihnea Brebenel