Skip to content

Instantly share code, notes, and snippets.

View jin-x's full-sized avatar

Eugene Krasnikov / Евгений Красников jin-x

View GitHub Profile
@jin-x
jin-x / phone_decipher.cpp
Last active June 6, 2021 09:48
@jinxonik / UniLecs #268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using std::cout;
using std::endl;
using std::string;
using std::vector;
@jin-x
jin-x / tricky_mul.py
Created April 30, 2021 08:30
@jinxonik / UniLecs #267
from random import randint
# Tricky multiplication
def tricky_mul(arr):
mul = 1
new_arr = []
for a in arr:
new_arr.append(mul)
mul *= a
@jin-x
jin-x / missed_item.cpp
Created April 23, 2021 15:58
@jinxonik / UniLecs #266
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
using std::cout;
using std::endl;
using std::vector;
int get_missed(const vector<int>& arr)
@jin-x
jin-x / inc_num_list.cpp
Created December 19, 2020 14:42
@jinxonik / UniLecs #252
#include <iostream>
#include <string>
#include <forward_list>
using std::cout;
using std::endl;
using std::string;
using std::forward_list;
void show_list(const string& title, const forward_list<int>& num)
@jin-x
jin-x / version_compare.cpp
Last active June 6, 2021 09:48
@jinxonik / UniLecs #240
#include <iostream>
#include <string>
#include <vector>
void string_to_int_vector(const std::string s, std::vector<int>& vec)
{
for (size_t start = 0, end = 0; end < std::string::npos; start = end + 1) {
end = s.find('.', start);
size_t len = end - start;
vec.push_back(std::stoi(s.substr(start, len)));
@jin-x
jin-x / islands.cxx
Last active June 6, 2021 09:50
@jinxonik / UniLecs #234
// C++17
#include <vector>
#include <random>
#define RAND_SEED -1 // ключ для генерации карты (разные значения дадут разные карты при равных значениях нижеследующих параметров), -1 означает использование random_device
#define ISLAND_SIZE 35 // 30 - малые, 35 - средние, 40 - большие, 45 - огромные острова
#define ISLAND_COUNT_COEF 50 // коэффициент кол-ва островов: рекомендую - 100 для ISLAND_SIZE 30; 50 для ISLAND_SIZE 35; 25 для ISLAND_SIZE 40; 10 для ISLAND_SIZE 45
class Islands
@jin-x
jin-x / ArgvToCommandLine.cpp
Last active August 10, 2020 15:30
ArgvToCommandLine
#include <iostream>
#include <string>
#include <vector>
#include <windows.h>
std::string ArgvToCommandLine(int argc, const char** argv)
{
std::string result;
for (int i = 0; i < argc; ++i) {
std::string temp = argv[i];
@jin-x
jin-x / file_mask.cxx
Created May 10, 2020 15:37
@jinxonik / UniLecs #220
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
#include <algorithm>
// CLASS DECLARATION ///////////////////////////////////////////////////////////////////////////////
class FileMask
{
@jin-x
jin-x / flist_merge1.cpp
Created March 7, 2020 09:07
@jinxonik / UniLecs #211
#include <iostream>
#include <forward_list>
using std::cout;
using std::forward_list;
using std::next;
template <typename T>
forward_list<T> forward_list_merge(forward_list<T> list1, const forward_list<T>& list2)
{
@jin-x
jin-x / look-and-say-hugemem_slow.cpp
Last active June 6, 2021 09:50
@jinxonik / UniLecs #209
// Реализация алгоритма "Посмотри-и-скажи" (Look-and-Say).
// Вариант, итерационно формирующий результирующее значение (строку цифр). Цифры хранятся в виде 2-х битов на цифру.
// Самый медленный алгоритм, требующий наиболее значительного кол-ва памяти (119 Гб для N = 100, 8.4 Гб для N = 90).
// Хочу отметить, что дополнительные расчёты, связанные с хранением чисел в формате 2-х битов на цифру
// компенсируются меньшим кол-вом обращений к памяти, в результате чего скорость данного алгоритма почти не
// отличается от алгоритма, использующего 1 байт на цифру, однако он значительно менее требователен к памяти.
// Результат (в отличие от look-and-say.cpp) формируется лишь на последней итерации.
// В реализации используется один массив, работающий по принципу двунаправленного чтения и записи.