{"id":288182,"date":"2018-08-17T19:30:12","date_gmt":"2018-08-17T15:30:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288182"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288182","title":{"rendered":"\u041c\u043e\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u044f\u0437\u044b\u043a\u0435 Kotlin"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420299\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 Kotlin \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Kotlin.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1f2\/8bd\/347\/1f28bd3472067f00fb324fb500176cb0.png\" alt=\"\u041c\u043e\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u044f\u0437\u044b\u043a\u0435 Kotlin\"><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h3 id=\"rabota-s-kollekciyami\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438<\/h3>\n<p>  <\/p>\n<p>Kotlin \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438. \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043b\u0443\u0447\u0448\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u044b \u0441\u0442\u0438\u043f\u0435\u043d\u0434\u0438\u0438. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c <code>Student<\/code>:<\/p>\n<p>  <\/p>\n<pre><code>class Student(     val name: String,     val surname: String,     val passing: Boolean,     val averageGrade: Double )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u0435\u0441\u044f\u0442\u0438 \u043b\u0443\u0447\u0448\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u0441\u0435\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c:<\/p>\n<p>  <\/p>\n<pre><code>students.filter { it.passing &amp;&amp; it.averageGrade &gt; 4.0 } \/\/ 1     .sortedBy { it.averageGrade } \/\/ 2     .take(10) \/\/ 3     .sortedWith(compareBy({ it.surname }, { it.name })) \/\/ 4 <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0430\u0432\u0448\u0438\u0445 \u044d\u043a\u0437\u0430\u043c\u0435\u043d \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432, \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0431\u0430\u043b\u043b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u043e\u043b\u0435\u0435 4.0.<\/li>\n<li>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u043f\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u043c\u0443 \u0431\u0430\u043b\u043b\u0443.<\/li>\n<li>\u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0435\u0441\u044f\u0442\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432.<\/li>\n<li>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443. \u041a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0444\u0430\u043c\u0438\u043b\u0438\u0438, \u0438 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0440\u0430\u0432\u043d\u044b, \u0442\u043e \u043e\u043d \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0427\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432? \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u044b:<\/p>\n<p>  <\/p>\n<pre><code>students.filter { it.passing &amp;&amp; it.averageGrade &gt; 4.0 }     .withIndex() \/\/ 1     .sortedBy { (i, s) -&gt; s.averageGrade } \/\/ 2     .take(10)     .sortedBy { (i, s) -&gt; i } \/\/ 3     .map { (i, s) -&gt; s } \/\/ 4<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443.<\/li>\n<li>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u043c\u0443 \u0431\u0430\u043b\u043b\u0443 \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0435\u0441\u044f\u0442\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432.<\/li>\n<li>\u0421\u043d\u043e\u0432\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443.<\/li>\n<li>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u0430 \u0438 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 Kotlin.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/288\/6f3\/3a6\/2886f33a698851f73a1e3003367e5f56.jpg\" alt=\"\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 Kotlin\"><\/p>\n<p>  <\/p>\n<h3 id=\"supermnozhestvo-buleanhttpsruwikipediaorgwikid091d183d0bbd0b5d0b0d0bd\"><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%91%D1%83%D0%BB%D0%B5%D0%B0%D0%BD\">\u0421\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e (\u0431\u0443\u043b\u0435\u0430\u043d)<\/a><\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0437\u0443\u0447\u0430\u043b\u0438 \u0430\u043b\u0433\u0435\u0431\u0440\u0443 \u0432 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0435, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0414\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0435\u0433\u043e \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0430\u043c\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u043f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440:<\/p>\n<p>  <\/p>\n<p>{1,2,3}<\/p>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0433\u043e \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e:<\/p>\n<p>  <\/p>\n<p>{{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}<\/p>\n<p>  <\/p>\n<p>\u0412 \u0430\u043b\u0433\u0435\u0431\u0440\u0435 \u0442\u0430\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430. \u041a\u0430\u043a \u043d\u0430\u043c \u0435\u0451 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u0432\u044b\u0437\u043e\u0432, \u0442\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435\u0441\u044c \u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u043d\u0430\u0448 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 1), \u0442\u043e \u0432 \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0441 \u044d\u0442\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c ({1}, {1,2}, {1,3}, {1,2,3}) \u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e ({}, {2}, {3}, {2,3}).<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u2013 \u044d\u0442\u043e \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e ({2,3}), \u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u2013 \u044d\u0442\u043e \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e ({2,3}) \u0441 \u043d\u0430\u0448\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c (1) \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432\u0437\u044f\u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0432 \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0438 \u0432\u0435\u0440\u043d\u0443\u0432 \u0441\u0443\u043c\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443:<\/p>\n<p>  <\/p>\n<pre><code>fun &lt;T&gt; powerset(set: Set&lt;T&gt;): Set&lt;Set&lt;T&gt;&gt; {    val first = set.first()    val powersetOfRest = powerset(set.drop(1))    return powersetOfRest.map { it + first } + powersetOfRest }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0443\u0441\u0442\u043e\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435: <code>first<\/code> \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0443\u0441\u0442\u043e\u0435. \u0417\u0434\u0435\u0441\u044c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u2014 \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e: powerset({}) = {{}}. \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c:<\/p>\n<p>  <\/p>\n<pre><code>fun &lt;T&gt; powerset(set: Set&lt;T&gt;): Set&lt;Set&lt;T&gt;&gt; =     if (set.isEmpty()) setOf(emptySet())     else {        val powersetOfRest = powerset(set.drop(1))        powersetOfRest + powersetOfRest.map { it + set.first() }     }<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/aea\/150\/ee3\/aea150ee316f7800b56220e8dbd10b5f.png\" alt=\"\u041c\u0435\u043c \u043f\u0440\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e\"><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c powerset({1,2,3}). \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p>powerset({1,2,3}) = powerset({2,3}) + powerset({2,3}).map { it + 1 }<\/p>\n<p>  <\/p>\n<p>powerset({2,3}) = powerset({3}) + powerset({3}).map { it + 2}<\/p>\n<p>  <\/p>\n<p>powerset({3}) = powerset({}) + powerset({}).map { it + 3}<\/p>\n<p>  <\/p>\n<p>powerset({}) = {{}}<\/p>\n<p>  <\/p>\n<p>powerset({3}) = {{}, {3}}<\/p>\n<p>  <\/p>\n<p>powerset({2,3}) = {{}, {3}} + {{2}, {2, 3}} = {{}, {2}, {3}, {2, 3}}<\/p>\n<p>  <\/p>\n<p>powerset({1,2,3}) = {{}, {2}, {3}, {2, 3}} + {{1}, {1, 2}, {1, 3}, {1, 2, 3}} = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e let, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u043e\u0447\u0435 \u0438 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code>fun &lt;T&gt; powerset(set: Set&lt;T&gt;): Set&lt;Set&lt;T&gt;&gt; =     if (set.isEmpty()) setOf(emptySet())     else powerset(set.drop(1))            .let { it+ it.map { it + set.first() }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f <code>Collection<\/code>, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0430\u043a, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u0431\u044b\u043b \u043c\u0435\u0442\u043e\u0434 <code>Set<\/code> (<code>setOf(1,2,3).powerset()<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>powerset(setOf(1,2,3))<\/code>):<\/p>\n<p>  <\/p>\n<pre><code>fun &lt;T&gt; Collection&lt;T&gt;.powerset(): Set&lt;Set&lt;T&gt;&gt; =     if (isEmpty()) setOf(emptySet())     else drop(1)            .powerset()            .let { it+ it.map { it + first() }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0449\u0451 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u043e\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0443\u043f\u0435\u0440\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0441\u0442\u0435\u0442 \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439 (\u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>tailrec<\/code>. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <code>tailrec<\/code> \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code>fun &lt;T&gt; Collection&lt;T&gt;.powerset(): Set&lt;Set&lt;T&gt;&gt; =      powerset(this, setOf(emptySet()))  private tailrec fun &lt;T&gt; powerset(left: Collection&lt;T&gt;, acc: Set&lt;Set&lt;T&gt;&gt;): Set&lt;Set&lt;T&gt;&gt; =     if (left.isEmpty()) acc     else powerset(left.drop(1), acc + acc.map { it + left.first() })<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/MarcinMoskala\/KotlinDiscreteMathToolkit\">KotlinDiscreteMathToolkit<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"bystraya-sortirovka-quicksorthttpsruwikipediaorgwikid091d18bd181d182d180d0b0d18f_d181d0bed180d182d0b8d180d0bed0b2d0bad0b0\"><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%91%D1%8B%D1%81%D1%82%D1%80%D0%B0%D1%8F_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0\">\u0411\u044b\u0441\u0442\u0440\u0430\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 (quicksort)<\/a><\/h3>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u043a\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0438\u043b\u044f \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0441\u0442: \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (pivot (\u0440\u0443\u0441. <em>\u0441\u0442\u0435\u0440\u0436\u0435\u043d\u044c<\/em>)) \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0434\u0432\u0430 \u0441\u043f\u0438\u0441\u043a\u0430: \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0441\u0442\u0435\u0440\u0436\u0435\u043d\u044c, \u0438 \u043c\u0435\u043d\u044c\u0448\u0435. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u043f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432\u044b. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u043d\u044c\u0448\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u0442\u0435\u0440\u0436\u0435\u043d\u044c \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u0435\u0440\u0436\u043d\u044f. \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code>fun &lt;T : Comparable&lt;T&gt;&gt; List&lt;T&gt;.quickSort(): List&lt;T&gt; =      if(size &lt; 2) this     else {         val pivot = first()         val (smaller, greater) = drop(1).partition { it &lt;= pivot}         smaller.quickSort() + pivot + greater.quickSort()     } \/\/ Usage listOf(2,5,1).quickSort() \/\/ [1,2,5]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0448\u0438\u043a\u0430\u0440\u043d\u043e, \u043f\u0440\u0430\u0432\u0434\u0430? \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/272\/390\/e2b\/272390e2bd0960c5c5c9bf1dd42fa5e9.jpg\" alt=\"\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041e\u043d\u0430 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f. \u0417\u0430\u0442\u043e \u043e\u043d\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0438 \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u0430\u044f.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Java. \u041e\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430\u0442\u0438\u0432\u043d\u043e. \u042d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c. \u041d\u043e \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d\u043d\u043e? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u044d\u0442\u0438 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code>val r = Random() listOf(100_000, 1_000_000, 10_000_000)     .asSequence()     .map { (1..it).map { r.nextInt(1000000000) } }     .forEach { list: List&lt;Int&gt; -&gt;         println(\"Java stdlib sorting of ${list.size} elements took ${measureTimeMillis { list.sorted() }}\")         println(\"quickSort sorting of ${list.size} elements took ${measureTimeMillis { list.quickSort() }}\")     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438:<\/p>\n<p>  <\/p>\n<p>Java stdlib sorting of 100000 elements took 83<br \/>  quickSort sorting of 100000 elements took 163<br \/>  Java stdlib sorting of 1000000 elements took 558<br \/>  quickSort sorting of 1000000 elements took 859<br \/>  Java stdlib sorting of 10000000 elements took 6182<br \/>  quickSort sorting of 10000000 elements took 12133<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>quickSort<\/code> \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 2 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u0414\u0430\u0436\u0435 \u0434\u043b\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432. \u0412 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0442 0,1\u043c\u0441 \u0434\u043e 0,2\u043c\u0441. \u042d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u043d\u043e \u0437\u0430\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u0430 \u0438 \u043f\u0440\u043e\u0441\u0442\u0430.<\/p>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/420299\/\"> https:\/\/habr.com\/post\/420299\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420299\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 Kotlin \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Kotlin.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1f2\/8bd\/347\/1f28bd3472067f00fb324fb500176cb0.png\" alt=\"\u041c\u043e\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u044f\u0437\u044b\u043a\u0435 Kotlin\"><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-288182","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288182"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288182\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}