Skip to content

Commit

Permalink
some more files too
Browse files Browse the repository at this point in the history
  • Loading branch information
hearues-zueke-github committed May 21, 2018
1 parent 6e6225f commit c5264ab
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
58 changes: 9 additions & 49 deletions binary_games/matrix_binary_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,27 @@

from PIL import Image

def get_valid_binary_row(n):
def get_valid_binary_row(n, max_same_numbers):
row = np.zeros((n, )).astype(np.int)

idx = 0
color = np.random.randint(0, 2)
length = np.random.randint(1, 3)
length = np.random.randint(1, max_same_numbers+1)
while idx < n:
row[idx:idx+length] = color
idx += length

color = (color+1)%2
length = np.random.randint(1, 3)
length = np.random.randint(1, max_same_numbers+1)

return row

if __name__ == "__main__":
n = 15
# arr = np.random.randint(0, 2, (n, n))

# arr_dy = (arr[1:]==arr[:-1])+0
# arr_dx = (arr[:, 1:]==arr[:, :-1])+0

# print("arr:\n{}".format(arr))

# print("arr_dy:\n{}".format(arr_dy))
# print("arr_dx:\n{}".format(arr_dx))

# arr_sum_dy_2 = arr_dy[:-1]+arr_dy[1:]
# arr_sum_dx_2 = arr_dx[:, :-1]+arr_dx[:, 1:]

# print("arr_sum_dy_2:\n{}".format(arr_sum_dy_2))
# print("arr_sum_dx_2:\n{}".format(arr_sum_dx_2))


# m = 20
# resize_factor = 10
# arr = np.zeros((m, n)).astype(np.int)
# for i in xrange(0, m):
# arr[i] = get_valid_binary_row(n)

# new_arr = np.zeros((resize_factor**2, m*n)).astype(np.uint8)
# new_arr[:] = arr.reshape((-1, ))
# new_arr = new_arr.T.reshape((m, n*resize_factor, resize_factor)) \
# .transpose(0, 2, 1) \
# .reshape((m*resize_factor, n*resize_factor))

# # print("new_arr:\n{}".format(new_arr.tolist()))

# # img = Image.fromarray(arr.astype(np.uint8)*255)
# img = Image.fromarray(new_arr.astype(np.uint8)*255)
# # img = img.resize((n*3, n*3), Image.ANTIALIAS)
# img.show()

# sys.exit(0)

n = 20

def set_rows(arr, n, amount):
for i in xrange(0, amount):
arr[i] = get_valid_binary_row(n)
arr[i] = get_valid_binary_row(n, amount)

def get_amount_same_numbers(arr):
sum_rows = 0
Expand All @@ -75,26 +37,24 @@ def get_amount_same_numbers(arr):
for i in xrange(1, rows):
sum_rows += row_0==arr[i]

print("sum_rows:\n{}".format(sum_rows))
# print("sum_rows:\n{}".format(sum_rows))

return sum_rows

arr = np.zeros((n, n)).astype(np.int)
same_numbers = 2
# arr[0] = get_valid_binary_row(n)
# arr[1] = get_valid_binary_row(n)
set_rows(arr, n, same_numbers)

i = same_numbers
worked_idx = [2]
tries = 0
while i < n:
if i < 2:
arr[i] = get_valid_binary_row(n)
if i < same_numbers:
arr[i] = get_valid_binary_row(n, same_numbers)
i += 1
print("i: {}".format(i))
worked_idx.append(i)
arr[i] = get_valid_binary_row(n)
arr[i] = get_valid_binary_row(n, same_numbers)
# print("i: {}, arr[{}]: {}".format(i, i, arr[i]))
if np.where(get_amount_same_numbers(arr[i-same_numbers:i+1])>=same_numbers)[0].shape[0] > 0:
# if np.where((0+(arr[i-2]==arr[i-1])+(arr[i-2]==arr[i]))>=same_numbers)[0].shape[0] > 0:
Expand Down
6 changes: 6 additions & 0 deletions bytes_io/numpy_bytes_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@

print("{}read_data:{}".format(clrs.lyb, clrs.rst))
pretty_block_printer(read_data, 8, read_data.shape[0])

# with open("/dev/sdf", "rb") as fin:
# data = np.fromfile(fin, dtype=np.uint8, count=512)

# print("{}data:{}".format(clrs.lyb, clrs.rst))
# pretty_block_printer(data, 8, data.shape[0])
37 changes: 37 additions & 0 deletions math_functions/plot_recursive_input_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /usr/bin/python2.7

import sys

import matplotlib.pyplot as plt
import numpy as np

from PIL import Image

def f_1(x, i=1):
return i + 1.0 / x

if __name__ == "__main__":
x = np.arange(-5., 5., 0.01)

vf1 = np.vectorize(f_1)

def get_next_y(vf, x, y_min, y_max, i=1):
y = vf(x)
# print("y: {}".format(y))
check_range = (y >= y_min) & (y <= y_max)
# print("check_range: {}".format(check_range))
return y[check_range]

xs = [x.copy()]
for i in xrange(0, 5):
x = get_next_y(vf1, x, -5., 5., i=(i+1))
xs.append(x.copy())

phi = (1+5.**0.5) / 2.
plt.figure()
for i, x in enumerate(xs):
plt.plot(x, np.zeros(x.shape)+i, "b.")
plt.plot([phi, phi], [0, len(xs)], "k-")
plt.xlabel("x")
plt.ylabel("iteration")
plt.show()
1 change: 0 additions & 1 deletion test_programs/create_random_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os


import sys
sys.path.append('..')
# sys.path.append('../encryption')
Expand Down

0 comments on commit c5264ab

Please sign in to comment.