Skip to content

Instantly share code, notes, and snippets.

@ElenaMalysheva
Created October 28, 2022 10:52
Show Gist options
  • Save ElenaMalysheva/851b2b7f468be1e7d5672ab8d837de90 to your computer and use it in GitHub Desktop.
Save ElenaMalysheva/851b2b7f468be1e7d5672ab8d837de90 to your computer and use it in GitHub Desktop.
# Создайте программу для игры с конфетами человек против человека.
#
# Условие задачи: На столе лежит 2021 конфета. Играют два игрока делая ход друг после друга.
# Первый ход определяется жеребьёвкой. За один ход можно забрать не более чем 28 конфет.
# Все конфеты оппонента достаются сделавшему последний ход.
# Сколько конфет нужно взять первому игроку, чтобы забрать все конфеты у своего конкурента?
#
# a) Добавьте игру против бота
#
# b) Подумайте как наделить бота ""интеллектом""
import random
#
# def create_random():
# return random.randint(1, 28)
#
# def ganer_choose():
# gamer = int(input("Напишите количество конфет от 1 до 28: "))
# return gamer
#
#
#
# def round():
# ostatok = 2021
# gamer = ganer_choose()
# comp = create_random()
# i = 1
# while ostatok >0:
# if i%2 == 0:
# ostatok = count_ostatok(ostatok, ganer_choose())
# i = i+1
# else:
# ostatok = count_ostatok(ostatok, create_random())
# i = i+1
# if ostatok>0:
# print(f'Раунд {i-1}, Остаток = {ostatok} ')
# else:
# if i%2 == 0:
# print("Человек победил")
# else:print("Компьютер победил")
#
#
#
# def count_ostatok(ost, a):
# if ost > 0:
# return (ost - a)
#
#
# round()
# ---------------------------------------------------------------------------------
# Создайте программу для игры в ""Крестики-нолики"".
#
# def create_random_x(a):
# return random.randint(0, a)
#
# def gamer_choose_x():
# gamer = int(input("Выберите 0 или 1: "))
# return gamer
#
# def gamer_choose_place_x():
# row = int(input("Выберите ряд от 0 до 2: "))
# column = int(input("Выберите колонку от 0 до 2: "))
# list_p = [row,column]
# return list_p
#
# def print_list(list_xx):
# for i in range(len(list_xx)):
# for j in range(len(list_xx[i])):
# print(list_xx[i][j], end=' ')
# print()
#
# def check_gorizont(list_xx):
# j = 0
# for i in range(len(list_xx)):
# a = list_xx[i][0]
# if (list_xx[i][j] == a and list_xx[i][j+1] == a and list_xx[i][j+2] == a) and a != 2:
# # print("yes")
# return True
#
# def check_vertical(list_xx):
# # a = 0
# i = 0
# j = 0
# # for i in range(len(list_xx)):
# for j in range(len(list_xx[i])):
# a = list_xx[i][j]
# if (list_xx[i][j] == a and list_xx[i+1][j] == a and list_xx[i+2][j] == a) and a != 2:
# print("yes")
# return True
#
# def change_simbol(list_xxx, list_place,simbol):
# # print(type( list_xxx[list_place[0],list_place[1]]))
# i = list_place[0]
# j = list_place[1]
# print(list_xxx[0][0])
# # list_xxx[list_place[0]][list_place[1]] = simbol
#
# if list_xxx[i][j] == 2:
# list_xxx[list_place[0]][list_place[1]] = simbol
# return list_xxx
#
# def round_x ():
# list_x = [[0, 2, 2], [2, 2, 2], [2, 2, 2]] #задаем массив
# next_step = 1 # определяем очередь
# for next_step in range(1, 8):
# if next_step%2 != 0:
# simbol = gamer_choose_x() # присваиваем символ от игрока
# place_simbol = gamer_choose_place_x() # место символа
# change_simbol(list_x, place_simbol,simbol) #вставляем символ в список списков
# print_list(list_x) # печатаем массив
# if check_vertical(list_x) == True: #проверяем выигрыш по вертикали
# print("Вы выиграли!")
# break
# elif check_gorizont(list_x): #проверяем выигрыш по горизонтали
# print("Вы выиграли!")
# break
#
# else:
# simbol = create_random_x(1)
# place_simbol = [create_random_x(2),create_random_x(2)]
# change_simbol(list_x, place_simbol, simbol)
# print_list(list_x)
# if check_vertical(list_x) == True:
# print("Компьютер выиграл!")
# break
# elif check_gorizont(list_x):
# print("Компьютер выиграл!")
# break
#
# round_x()
# ---------------------------------------------------------------------------------
# Реализуйте RLE алгоритм: реализуйте модуль сжатия и восстановления данных.
def read_file():
with open('rle.txt') as f:
for line in f:
line1 = line
line1 = line1.strip()
print(line1)
return line1
def write_file(rle_string):
file = open('rle_result.txt', 'w') # записываем в файл
file.write(f'{rle_string}')
file.close()
def rle(m_string):
count = 1
result = ''
m_string.strip()
for i in range(1,len(m_string)-2):
if m_string[i] == m_string[i+1]:
count = count+1
else:
result = result + (f'{m_string[i]}{count}')
count = 1
result = result + (f'{m_string[-2]}{count}')
print(result)
write_file(result)
my_string = 'aaaarrtttttyy'
rle(read_file())
# read_file()
# write_file(my_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment