From d6a7018c1ebc4b297aaeab215e4ab774a189359f Mon Sep 17 00:00:00 2001 From: Alexey Shobanov Date: Thu, 11 Jun 2020 15:17:08 +0000 Subject: [PATCH] add exercises 3_5-3_8 --- resources/lang/en/exercises/3_5.php | 60 ++++++++++++++++++ resources/lang/en/exercises/3_6.php | 23 +++++++ resources/lang/en/exercises/3_7.php | 34 +++++++++++ resources/lang/en/exercises/3_8.php | 23 +++++++ resources/lang/ru/exercises/3_5.php | 61 +++++++++++++++++++ resources/lang/ru/exercises/3_6.php | 23 +++++++ resources/lang/ru/exercises/3_7.php | 36 +++++++++++ resources/lang/ru/exercises/3_8.php | 22 +++++++ .../views/exercise/listing/3_5.blade.php | 53 ++++++++++++++++ .../views/exercise/listing/3_6.blade.php | 15 +++++ .../views/exercise/listing/3_7.blade.php | 32 ++++++++++ .../views/exercise/listing/3_8.blade.php | 15 +++++ 12 files changed, 397 insertions(+) create mode 100644 resources/lang/en/exercises/3_5.php create mode 100644 resources/lang/en/exercises/3_6.php create mode 100644 resources/lang/en/exercises/3_7.php create mode 100644 resources/lang/en/exercises/3_8.php create mode 100644 resources/lang/ru/exercises/3_5.php create mode 100644 resources/lang/ru/exercises/3_6.php create mode 100644 resources/lang/ru/exercises/3_7.php create mode 100644 resources/lang/ru/exercises/3_8.php create mode 100644 resources/views/exercise/listing/3_5.blade.php create mode 100644 resources/views/exercise/listing/3_6.blade.php create mode 100644 resources/views/exercise/listing/3_7.blade.php create mode 100644 resources/views/exercise/listing/3_8.blade.php diff --git a/resources/lang/en/exercises/3_5.php b/resources/lang/en/exercises/3_5.php new file mode 100644 index 000000000..a08c91abb --- /dev/null +++ b/resources/lang/en/exercises/3_5.php @@ -0,0 +1,60 @@ + 'Monte Carlo integration', + 'description1' => + 'Monte Carlo integration is a method of estimating definite integrals by means of Monte Carlo simulation. ' . + 'Consider computing the area of a region of space described by a predicate ', + 'description2' => + ' that is true for points ', + 'description3' => + ' in the region and false for points not in the region. For example, ' . + 'the region contained within a circle of radius ', + 'description4' => + ' centered at ', + 'description5' => + ' is described by the predicate that tests whether ', + 'description6' => + '. To estimate the area of the region described by such a predicate, begin by choosing a rectangle that contains the region. ' . + 'For example, a rectangle with diagonally opposite corners at ', + 'description7' => + ' and ', + 'description8' => + ' contains the circle above. ' . + 'The desired integral is the area of that portion of the rectangle that lies in the region. ' . + 'We can estimate the integral by picking, at random, points ', + 'description9' => + ' that lie in the rectangle, and testing ', + 'description10' => + ' for each point to determine whether the point lies in the region. ' . + 'If we try this with many points, then the fraction of points that fall in the region should give an estimate of the proportion of the rectangle that lies in the region. ' . + 'Hence, multiplying this fraction by the area of the entire rectangle should produce an estimate of the integral.', + 'description11' => + 'Implement Monte Carlo integration as a procedure ', + 'description12' => + ' that takes as arguments a predicate ', + 'description13' => + ', upper and lower bounds ', + 'description14' => + ' and ', + 'description15' => + ' for the rectangle, and the number of trials to perform in order to produce the estimate. ' . + 'Your procedure should use the same ', + 'description16' => + ' procedure that was used above to estimate ', + 'description17' => + '. Use your ', + 'description18' => + ' to produce an estimate of ', + 'description19' => + ' by measuring the area of a unit circle.', + 'description20' => + 'You will find it useful to have a procedure that returns a number chosen at random from a given range. ' . + 'The following ', + 'description21' => + 'procedure implements this in terms of the ', + 'description22' => + ' procedure used in section ', + 'description23' => + ', which returns a nonnegative number less than its input.' +]; diff --git a/resources/lang/en/exercises/3_6.php b/resources/lang/en/exercises/3_6.php new file mode 100644 index 000000000..5a9db4cb2 --- /dev/null +++ b/resources/lang/en/exercises/3_6.php @@ -0,0 +1,23 @@ + 'Advanced random number generator', + 'description1' => + 'It is useful to be able to reset a random-number generator to produce a sequence starting from a given value. ' . + 'Design a new ', + 'description2' => + ' procedure that is called with an argument that is either the symbol ', + 'description3' => + ' or the symbol ', + 'description4' => + ' and behaves as follows: ', + 'description5' => + ' produces a new random number; ', + 'description6' => + ' resets the internal state variable to the designated ', + 'description7' => + '. Thus, by resetting the state, one can generate repeatable sequences. ' . + 'These are very handy to have when testing and debugging programs that use random numbers.', + 'description8' => + 'new-value' +]; diff --git a/resources/lang/en/exercises/3_7.php b/resources/lang/en/exercises/3_7.php new file mode 100644 index 000000000..2f96e1199 --- /dev/null +++ b/resources/lang/en/exercises/3_7.php @@ -0,0 +1,34 @@ + 'Joint accounts', + 'description1' => + 'Consider the bank account objects created by ', + 'description2' => + ', with the password modification described in exercise ', + 'description3' => + '. Suppose that our banking system requires the ability to make joint accounts. Define a procedure ', + 'description4' => + ' that accomplishes this. ', + 'description5' => + ' should take three arguments. The first is a password-protected account. ' . + 'The second argument must match the password with which the account was defined in order for the ', + 'description6' => + ' operation to proceed. The third argument is a new password. ', + 'description7' => + ' is to create an additional access to the original account using the new password. For example, if ', + 'description8' => + ' is a bank account with password ', + 'description9' => + ', then', + 'description10' => + 'will allow one to make transactions on ', + 'description11' => + ' using the name ', + 'description12' => + ' and the password ', + 'description13' => + '. You may wish to modify your solution to exercise ', + 'description14' => + ' to accommodate this new feature.' +]; diff --git a/resources/lang/en/exercises/3_8.php b/resources/lang/en/exercises/3_8.php new file mode 100644 index 000000000..ae2b698a0 --- /dev/null +++ b/resources/lang/en/exercises/3_8.php @@ -0,0 +1,23 @@ + 'Order for evaluating subexpressions', + 'description1' => + 'When we defined the evaluation model in section ', + 'description2' => + ', we said that the first step in evaluating an expression is to evaluate its subexpressions. ' . + 'But we never specified the order in which the subexpressions should be evaluated ' . + '(e.g., left to right or right to left). When we introduce assignment, ' . + 'the order in which the arguments to a procedure are evaluated can make a difference to the result. ' . + 'Define a simple procedure ', + 'description3' => + ' such that evaluating ', + 'description4' => + ' will return ', + 'description5' => + ' if the arguments to ', + 'description6' => + ' are evaluated from left to right but will return ', + 'description7' => + ' if the arguments are evaluated from right to left.' +]; diff --git a/resources/lang/ru/exercises/3_5.php b/resources/lang/ru/exercises/3_5.php new file mode 100644 index 000000000..3275c8b00 --- /dev/null +++ b/resources/lang/ru/exercises/3_5.php @@ -0,0 +1,61 @@ + 'Интегрирование методом Монте-Карло', + 'description1' => + 'Интегрирование методом Монте-Карло (Monte Carlo integration) — ' . + 'способ приближенного вычисления определенных интегралов при помощи моделирования методом Монте-Карло. ' . + 'Рассмотрим задачу вычисления площади фигуры, описываемой предикатом ', + 'description2' => + ', который истинен для точек ', + 'description3' => + ', принадлежащих фигуре, и ложен для точек вне фигуры. ' . + 'Например, область, содержащаяся в круге с радиусом ', + 'description4' => + ' и центром в точке ', + 'description5' => + ', описывается предикатом, проверяющим ', + 'description6' => + '. Чтобы оценить площадь фигуры, описываемой таким предикатом, для начала выберем прямоугольник, ' . + 'который содержит нашу фигуру. Например, прямоугольник с углами ', + 'description7' => + ' и ', + 'description8' => + ', расположенными по диагонали, содержит вышеописанный круг. ' . + 'Нужный нам интеграл — площадь той части прямоугольника, которая лежит внутри фигуры. ' . + 'Мы можем оценить интеграл, случайным образом выбирая точки ', + 'description9' => + ', лежащие внутри прямоугольника, и проверяя для каждой точки ', + 'description10' => + ', чтобы определить, лежит ли точка внутри фигуры. ' . + 'Если мы проверим много точек, доля тех, которые окажутся внутри области, даст нам приближенное значение отношения площадей фигуры и прямоугольника. ' . + 'Таким образом, домножив это значение на площадь прямоугольника, мы получим приближенное значение интеграла.', + 'description11' => + 'Реализуйте интегрирование методом Монте-Карло в виде процедуры ', + 'description12' => + ', которая в качестве аргументов принимает предикат ', + 'description13' => + ', верхнюю и нижнюю границы прямоугольника ', + 'description14' => + ' и ', + 'description15' => + ', а также число проверок, которые мы должны осуществить, чтобы оценить отношение площадей. ' . + 'Ваша процедура должна использовать ту же самую процедуру ', + 'description16' => + ', которая выше использовалась для оценки значения ', + 'description17' => + '. Оцените ', + 'description18' => + ' при помощи ', + 'description19' => + ' измерив площадь единичного круга.', + 'description20' => + 'Вам может пригодиться процедура, которая выдает число, случайно выбранное внутри данного отрезка. ' . + 'Нижеприведенная процедура ', + 'description21' => + ' решает эту задачу, используя процедуру ', + 'description22' => + ', введенную в разделе ', + 'description23' => + ', которая возвращает неотрицательное число меньше своего аргумента.' +]; diff --git a/resources/lang/ru/exercises/3_6.php b/resources/lang/ru/exercises/3_6.php new file mode 100644 index 000000000..d3b163697 --- /dev/null +++ b/resources/lang/ru/exercises/3_6.php @@ -0,0 +1,23 @@ + 'Усовершенствованный генератор случайных чисел', + 'description1' => + 'Полезно иметь возможность сбросить генератор случайных чисел, чтобы получить последовательность, которая начинается с некоторого числа. ' . + 'Постройте новую процедуру ', + 'description2' => + ', которая вызывается с аргументом. Этот аргумент должен быть либо символом ', + 'description3' => + ', либо символом ', + 'description4' => + '. Процедура работает так: ', + 'description5' => + ' порождает новое случайное число; ', + 'description6' => + ' сбрасывает внутреннюю переменную состояния в указанное ', + 'description7' => + '. Таким образом, сбрасывая значения, можно получать повторяющиеся последовательности. ' . + 'Эта возможность очень полезна при тестировании и отладке программ, использующих случайные числа.', + 'description8' => + 'новое-значение' +]; diff --git a/resources/lang/ru/exercises/3_7.php b/resources/lang/ru/exercises/3_7.php new file mode 100644 index 000000000..497cdbb79 --- /dev/null +++ b/resources/lang/ru/exercises/3_7.php @@ -0,0 +1,36 @@ + 'Совместные счета', + 'description1' => + 'Рассмотрим объекты-банковские счета, создаваемые процедурой ', + 'description2' => + ', и снабженные паролями, как это описано в упражнении ', + 'description3' => + '. Предположим, что наша банковская система требует от нас умения порождать совместные счета. ' . + 'Напишите процедуру ', + 'description4' => + ', которая это делает. ', + 'description5' => + ' должна принимать три аргумента. Первый из них — защищенный паролем счет. ' . + 'Второй обязан совпадать с паролем, с которым этот счет был создан, иначе', + 'description6' => + 'откажется работать. ' . + ' Третий аргумент — новый пароль. ', + 'description7' => + ' открывает дополнительный доступ к счету, с использованием нового пароля. Например, если банковский счет ', + 'description8' => + ' был создан с паролем ', + 'description9' => + ', то', + 'description10' => + 'позволит нам проводить операции с ', + 'description11' => + ', используя имя ', + 'description12' => + ' и пароль ', + 'description13' => + '. Вам может потребоваться переработать решение упражнения ', + 'description14' => + ', чтобы добавить эту новую возможность.' +]; diff --git a/resources/lang/ru/exercises/3_8.php b/resources/lang/ru/exercises/3_8.php new file mode 100644 index 000000000..97236c7ca --- /dev/null +++ b/resources/lang/ru/exercises/3_8.php @@ -0,0 +1,22 @@ + 'Порядок вычисления подвыражений', + 'description1' => + 'Когда в разделе ', + 'description2' => + ' мы определяли модель вычислений, мы сказали, что первым шагом при вычислении выражения является вычисление его подвыражений. ' . + 'Однако мы нигде не указали порядок, в котором проходит вычисление подвыражений (слева направо или справа налево). ' . + 'Когда мы вводим присваивание, порядок, в котором вычисляются аргументы процедуры, может повлиять на результат. ' . + 'Определите простую процедуру ', + 'description3' => + ', так, чтобы вычисление ', + 'description4' => + ' возвращало ', + 'description5' => + ', если аргументы ', + 'description6' => + ' вычисляются слева направо, и ', + 'description7' => + ', если они вычисляются справа налево.' +]; diff --git a/resources/views/exercise/listing/3_5.blade.php b/resources/views/exercise/listing/3_5.blade.php new file mode 100644 index 000000000..9272abbf1 --- /dev/null +++ b/resources/views/exercise/listing/3_5.blade.php @@ -0,0 +1,53 @@ +

+ {{ __('exercises/3_5.description1') }} + P(x, y) + {{ __('exercises/3_5.description2') }} + (x, y) + {{ __('exercises/3_5.description3') }} + 3 + {{ __('exercises/3_5.description4') }} + (5, 7) + {{ __('exercises/3_5.description5') }} + (x - 5)² + (y - 7)² ≤ 3² + {{ __('exercises/3_5.description6') }} + (2, 4) + {{ __('exercises/3_5.description7') }} + (8, 10) + {{ __('exercises/3_5.description8') }} + (x,y) + {{ __('exercises/3_5.description9') }} + P(x, y) + {{ __('exercises/3_5.description10') }} +

+

+ {{ __('exercises/3_5.description11') }} + estimate-integral + {{ __('exercises/3_5.description12') }} + P + {{ __('exercises/3_5.description13') }} + x1, x2, y1 + {{ __('exercises/3_5.description14') }} + y2 + {{ __('exercises/3_5.description15') }} + monte-carlo + {{ __('exercises/3_5.description16') }} + π + {{ __('exercises/3_5.description17') }} + estimate-integral + {{ __('exercises/3_5.description18') }} + π + {{ __('exercises/3_5.description19') }} +

+

+ {{ __('exercises/3_5.description20') }} + random-in-range + {{ __('exercises/3_5.description21') }} + random + {{ __('exercises/3_5.description22') }} + 1.2.6 + {{ __('exercises/3_5.description23') }} +

+
(define (random-in-range low high)
+    (let ((range (- high low)))
+        (+ low (random range))))
+ \ No newline at end of file diff --git a/resources/views/exercise/listing/3_6.blade.php b/resources/views/exercise/listing/3_6.blade.php new file mode 100644 index 000000000..af824a95f --- /dev/null +++ b/resources/views/exercise/listing/3_6.blade.php @@ -0,0 +1,15 @@ +

+ {{ __('exercises/3_6.description1') }} + rand + {{ __('exercises/3_6.description2') }} + generate + {{ __('exercises/3_6.description3') }} + reset + {{ __('exercises/3_6.description4') }} + (rand 'generate) + {{ __('exercises/3_6.description5') }} + ((rand 'reset) <{{ __('exercises/3_6.description8') }}>) + {{ __('exercises/3_6.description6') }} + <{{ __('exercises/3_6.description8') }}> + {{ __('exercises/3_6.description7') }} +

diff --git a/resources/views/exercise/listing/3_7.blade.php b/resources/views/exercise/listing/3_7.blade.php new file mode 100644 index 000000000..981f396df --- /dev/null +++ b/resources/views/exercise/listing/3_7.blade.php @@ -0,0 +1,32 @@ +

+ {{ __('exercises/3_7.description1') }} + make-account + {{ __('exercises/3_7.description2') }} + 3.3 + {{ __('exercises/3_7.description3') }} + make-joint + {{ __('exercises/3_7.description4') }} + Make-joint + {{ __('exercises/3_7.description5') }} + make-joint + {{ __('exercises/3_7.description6') }} + Make-joint + {{ __('exercises/3_7.description7') }} + peter-acc + {{ __('exercises/3_7.description8') }} + open-sesame + {{ __('exercises/3_7.description9') }} +

+
(define paul-acc
+    (make-joint peter-acc 'open-sesame 'rosebud))
+

+ {{ __('exercises/3_7.description10') }} + peter-acc + {{ __('exercises/3_7.description11') }} + paul-acc + {{ __('exercises/3_7.description12') }} + rosebud + {{ __('exercises/3_7.description13') }} + 3.3 + {{ __('exercises/3_7.description14') }} +

diff --git a/resources/views/exercise/listing/3_8.blade.php b/resources/views/exercise/listing/3_8.blade.php new file mode 100644 index 000000000..de216e06e --- /dev/null +++ b/resources/views/exercise/listing/3_8.blade.php @@ -0,0 +1,15 @@ +

+ {{ __('exercises/3_8.description1') }} + 1.1.3 + {{ __('exercises/3_8.description2') }} + f + {{ __('exercises/3_8.description3') }} + (+ (f 0) (f 1)) + {{ __('exercises/3_8.description4') }} + 0 + {{ __('exercises/3_8.description5') }} + + + {{ __('exercises/3_8.description6') }} + 1 + {{ __('exercises/3_8.description7') }} +