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 / emigration.cpp
Created February 7, 2020 10:31
@jinxonik / UniLecs #207
#include <iostream>
#include <vector>
#include <stack>
using std::cout;
using std::vector;
using std::stack;
vector<int> emigration(const vector<int>& average)
{
@jin-x
jin-x / str_to_int.cpp
Created January 27, 2020 11:46
@jinxonik / UniLecs #205
#include <iostream>
#include <string>
#include <algorithm>
#include <climits>
// Преобразование строки в число до первого неверного символа
int str_to_int(const std::string& str)
{
auto end = str.end();
// Пропускаем пробелы
@jin-x
jin-x / shift_array.cpp
Created December 27, 2019 10:56
@jinxonik / UniLecs #202
#include <iostream>
#include <vector>
#include <algorithm>
using std::cout;
using std::vector;
template <typename T>
void shift_array(vector<T>& array, size_t value)
{
@jin-x
jin-x / fact_radix.cpp
Last active December 24, 2019 21:30
Factorial radix
#include <string>
#include <vector>
// Factorial radix
namespace fact_radix
{
// factorial digit type
using fact_digits = std::vector<int8_t>;
@jin-x
jin-x / spec_sum.cpp
Created December 20, 2019 21:10
@jinxonik / UniLecs #201
#include <iostream>
using namespace std;
// Returns -1 for illegal source number (n)
int spec_sum(int n)
{
if (n < 100 || n > 999) return -1;
int a = n/100, b = n/10%10, c = n%10;
if (b+c == 0) return n*2;
@jin-x
jin-x / puzzle_52_ext.py
Last active June 6, 2021 09:50
@jinxonik / UniLecs puzzle #52
# Find numbers of specified length that are complete squares with ascending sorted non-repeating digits in specified radix
# Returns list of found values of None on invalid radix or length parameters
def find_perfect_squares(radix, length):
if not 2 <= radix <= 36 or not 1 <= length < radix:
return None
from math import ceil, floor
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@jin-x
jin-x / magic_square.cpp
Last active June 6, 2021 09:50
Magic Square Finder
#include <iostream>
#include <iomanip>
#include <array>
#include <algorithm>
#include <numeric>
#define SQUARE_SIZE 4
//#define PRINT_SQUARES
#define DEBUG
@jin-x
jin-x / word_count.cpp
Created December 4, 2019 20:42
Word Counting
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <chrono>
using std::cout;
using std::cerr;
using std::cin;
@jin-x
jin-x / hospital_queue.cpp
Last active June 6, 2021 09:52
@jinxonik / UniLecs #191
#include <iostream>
#include <string>
#include <vector>
#include <list>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::list;
@jin-x
jin-x / brackets.cpp
Created September 30, 2019 17:35
@jinxonik / UniLecs #189
#include <iostream>
#include <functional>
// Bracket balance search function, returns number of found balances
// count - number of brackets pairs
// callback - function called for found bracket balance (parameters: uint64_t - bracket balance bit mask, int - number of bracket pairs)
// bit balance: lower bit (number 0) - first bracket, higher bit (number count-1) - last bracket: 0 - opened, 1 - closed
// list - bracket balance bit mask (used in recursion, leave zero on root call)
// opened, closed - number of opened/closed brackets in list (used in recursion, leave zero on root call)
uint64_t brackets(int count, std::function<void(uint64_t, int)> callback, uint64_t list = 0, int opened = 0, int closed = 0)