Skip to content

Instantly share code, notes, and snippets.

View IegorT's full-sized avatar

Iegor Timukhin IegorT

  • UK
View GitHub Profile
@IegorT
IegorT / task85.js
Last active April 14, 2018 21:42
UniLecs - Задача 85
/** Для положительных k, за исключением 2, наименьшим числом n,
* является последний член арифметической прогрессии(АП),
* для которой k лежит в диаппазоне
* (предыдущая сумма прогрессии < k <= сумма прогрессии).
* Исходя из условия задачи, что n >= 1 следует, что k >= 1.
* Сложность алгоритма: O(n);
*/
const validateAgrument = (k) => {
if (typeof k !== 'number') throw new Error('agument must be a number');
@IegorT
IegorT / task140.js
Last active November 17, 2018 00:34
UniLecs - Задача 140
const isHorseMove = str => {
if(!/^[A-H][1-8]-[A-H][1-8]$/.test(str)) throw new Error('wrong incoming data');
// (c1, r1) - start coodinate, (c2, r2) - coordinate after move a figure
const [c1, r1, _, c2, r2] = str.split('').map(ch => ch.charCodeAt(0));
return (
(Math.abs(c1 - c2) === 1 && Math.abs(r1 - r2) === 2)
||
@IegorT
IegorT / task143.js
Last active December 2, 2018 19:36
UniLecs - Задача 143
function makePyramid(height) {
if (typeof height !== 'number' && height < 1) throw 'Wrong number';
// Total number in pyramid is qual height^2
const total = Math.pow(height, 2);
// make 2d array filled 0
// each internal array length qual number of block in this pyramid leyer
let output = Array.from(
{ length: height},
(_, i) => Array.from({ length: 2*(i+1) - 1}).fill(0)