Skip to content

Commit

Permalink
massive push
Browse files Browse the repository at this point in the history
  • Loading branch information
hearues-zueke-github committed May 29, 2020
1 parent 634149b commit 8b8ac5d
Show file tree
Hide file tree
Showing 111 changed files with 8,256 additions and 943 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ math_games/pictures/*
math_games/output_*.txt

cpp_programs/primes/*.out
cpp_programs/primes/*.o
cpp_programs/primes/*.o

git_status.txt
23 changes: 23 additions & 0 deletions bases/base_sequences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/python3

# -*- coding: utf-8 -*-

# Some other needed imports
import datetime
import dill
import gzip
import os
import sys

import numpy as np

import matplotlib.pyplot as plt

from functools import reduce
from dotmap import DotMap

PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))+"/"

if __name__=='__main__':
# base1 = 3, convert num to base2 = 2

54 changes: 54 additions & 0 deletions bases/consecutive_ones_in_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/python3

# -*- coding: utf-8 -*-

# Some other needed imports
import datetime
import dill
import gzip
import os
import sys

import numpy as np

import matplotlib.pyplot as plt

from functools import reduce
from dotmap import DotMap

PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))+"/"

if __name__=='__main__':
# base1 = 3, convert num to base2 = 2
base1 = 5
l_consecutive_ones = []
l_amount_ones = []
for n in range(0, 31):
arr=np.array(list(map(int, bin(base1**n)[2:])))
print("n: {}, arr: {}".format(n, arr))

first_i = 0
last_i = 0
prev_1 = False
max_conecutive_length_ones = 0
for i, v in enumerate(arr, 0):
if prev_1==False and v==1:
prev_1 = True
first_i = i
last_i = i
elif prev_1==True and v==1:
last_i = i
elif v==0:
prev_1 = False
diff_i = last_i-first_i+1
if max_conecutive_length_ones<diff_i:
max_conecutive_length_ones = diff_i

l_consecutive_ones.append(max_conecutive_length_ones)
l_amount_ones.append(np.sum(arr==1))

print("- max_conecutive_length_ones: {}".format(max_conecutive_length_ones))

print()
print("l_consecutive_ones: {}".format(str(l_consecutive_ones).replace(', ', ' ')))
print("l_amount_ones: {}".format(str(l_amount_ones).replace(', ', ' ')))
1 change: 1 addition & 0 deletions c_programs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.o
7 changes: 5 additions & 2 deletions c_programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ all:
gcc -Wall huge_number_test.c -o huge_number_test -lgmp

sequence_generator: sequence_generator.c
$(CC) $(CFLAGS) sequence_generator.c -o sequence_generator
$(CC) $(CFLAGS) sequence_generator.c -o sequence_generator.o

simple: simple_c_example.c
$(CC) $(CFLAGS) simple_c_example.c -o simple_c_example
$(CC) $(CFLAGS) simple_c_example.c -o simple_c_example.o

simple_program: simple_program.c
$(CC) $(CFLAGS) simple_program.c -o simple_program.o
59 changes: 5 additions & 54 deletions combinatorics/different_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,59 +78,7 @@ def get_all_combinations_increment(m, n):


# n ... amount of states
def get_permutation_table(n, same_pos=True):
if n == 1:
return np.array([[0]], dtype=np.uint8)
arr = np.array([[0, 1], [1, 0]], dtype=np.uint8)

p = 2
for i in range(3, n+1):
arr_new = np.zeros((p*i, i), dtype=np.uint8)

for j in range(0, i):
arr_new[p*j:p*(j+1), 0] = (j-1) % i
arr_new[p*j:p*(j+1), 1:] = (arr+j) % i

p *= i
arr = arr_new

# arr = np.sort(arr.reshape((-1, )).view(','.join(['u1']*n))).view('u1').reshape((-1, n))

if not same_pos:
arr = arr[~np.any(arr == np.arange(0, n), axis=1)]

return arr

# n ... amount of states
def get_permutation_table_faster(n, same_pos=True):
if n == 1:
return np.array([[0]], dtype=np.uint8)
arr = np.array([[0, 1], [1, 0]], dtype=np.uint8)

lengths = [fac(i) for i in range(1, n+1)]
arr_finish = np.empty((lengths[-1], n), dtype=np.uint8)

arr_finish[:2, :2] = arr

p = 2
for i in range(2, n):
arr_finish[:p, i] = i
arr_part = arr_finish[:p, :i]
for k in range(1, i+1):
arr_part_2 = arr_finish[p*k:p*(k+1), :i]
arr_part_2[:] = arr_part
arr_part_2[arr_part_2==k-1] = i
arr_finish[p*k:p*(k+1), i] = k-1
p *= i+1

if not same_pos:
arr_finish = arr_finish[~np.any(arr_finish == np.arange(0, n), axis=1)]

return arr_finish


# n ... amount of states
def get_permutation_table_faster_2(n, same_pos=True):
def get_permutation_table(n, is_same_pos=True, is_sorted=False):
if n == 1:
return np.array([[0]], dtype=np.uint8)
arr = np.array([[0, 1], [1, 0]], dtype=np.uint8)
Expand All @@ -150,9 +98,12 @@ def get_permutation_table_faster_2(n, same_pos=True):
arr_part_2[:, k:] = arr_part[:, :i-k]
p *= i

if not same_pos:
if not is_same_pos:
arr_finish = arr_finish[~np.any(arr_finish == np.arange(0, n), axis=1)]

if is_sorted:
arr_finish = np.sort(arr_finish.reshape((-1, )).view(','.join(['u1']*n))).view('u1').reshape((-1, n))

return arr_finish


Expand Down
1 change: 1 addition & 0 deletions cpp_programs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.o
6 changes: 5 additions & 1 deletion cpp_programs/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: utils
CC=g++
CFLAGS=-Wall -std=c++11
CFLAGS=-Wall -std=c++17

utils:
$(CC) $(CFLAGS) utils.cpp -c
Expand All @@ -12,5 +12,9 @@ test_vector_2:
$(CC) $(CFLAGS) test_vector_2.cpp -o test_vector_2.o
test_vector_3: utils
$(CC) $(CFLAGS) test_vector_3.cpp utils.o -o test_vector_3.o
test_vector_sort: utils
$(CC) $(CFLAGS) test_vector_sort.cpp utils.o -o test_vector_sort.o
hex_output: utils
$(CC) $(CFLAGS) hex_output.cpp utils.o -o hex_output.o
all:
$(CC) $(CFLAGS) simple_hashing_algorithm.cpp -o simple_hashing_algorithm.o
1 change: 1 addition & 0 deletions cpp_programs/SequencesGenerator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake-build-debug
62 changes: 62 additions & 0 deletions cpp_programs/SequencesGenerator/Combinations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,65 @@
//

#include "Combinations.h"

Combinations::Combinations(int m, int n) :
_m(m),
_n(n),
_vals(n),
_iter(0) {
}

Combinations::Combinations(const Combinations& obj) :
_m(obj._m),
_n(obj._n),
_vals(obj._vals),
_iter(obj._iter) {
}

Combinations::~Combinations() {
}

size_t Combinations::ownPow(size_t b, size_t e) {
int r = 1;
while (e)
{
if (e & 1)
r *= b;
e /= 2;
b *= b;
}
return r;
}

ostream& operator<<(ostream& os, const Combinations& obj) {
os << "iter: " << obj._iter << ", vals: [";
for (size_t i = 0; i < obj._n; ++i) {
if (i > 0) {
os << ", ";
}
os << obj._vals[i];
}
os << "]";
return os;
}

void Combinations::clearVector() {
_iter = 0;
_vals.resize(_n, 0);
}

// returns true only, if all values are again 0 !
bool Combinations::nextCombo() {
bool is_all_zero = true;

for (size_t i = 0; i < _n; ++i) {
if ((_vals[i] = (_vals[i]+1) % _m) != 0) {
is_all_zero = false;
break;
}
}

_iter++;

return is_all_zero;
}
20 changes: 20 additions & 0 deletions cpp_programs/SequencesGenerator/Combinations.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@
#ifndef SEQUENCESGENERATOR_COMBINATIONS_H
#define SEQUENCESGENERATOR_COMBINATIONS_H

#include <cstdint>
#include <vector>
#include <ostream>

using namespace std;

class Combinations {
private:
size_t _m;
size_t _n;
vector<uint32_t> _vals;
size_t _iter;
// size_t _max_iters;
size_t ownPow(size_t b, size_t e);
public:
Combinations(int m, int n);
Combinations(const Combinations& obj);
virtual ~Combinations();

friend ostream& operator<<(ostream& os, const Combinations& obj);

void clearVector();
bool nextCombo();
};


Expand Down
Loading

0 comments on commit 8b8ac5d

Please sign in to comment.