#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
ENG=1
RUS=0
ASCII=255
alphabet = [u"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",
u"ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
def getcode(letter,language):
if language == ASCII:
return ord(code)
i = 0
for search in alphabet[language]:
if letter == search:
return i
i = i+1
def getletter(code,language):
if language == ASCII:
return chr(code)
if (code == None) or (code > len(alphabet[language])-1):
print code
return " "
return alphabet[language][code]
LEFT = 0
RIGHT = 1
BIG = 1
LITTLE = -1
msg=[
1,0,0,1,
1,0,1,0,
0,0,0,0,
1,0,1,1,
1,0,0,1,
0,1,0,0,
0,1,1,0,
1,0,1,1,
1,0,0,1,
1,1,0,1,
1,1,0,0,
1,0,0,1,
1,1,1,0,
0,0,0,1,
1,1,0,1,
0,1,1,0,
1,0,0,1,
0,0,0,0,
1,0]
def array_to_value(array,endian):
size = len(array)
value = 0
i = 0
for element in apply(xrange,(0,size) if (endian > 0) else (size-1, -1, endian)):
value = value + (2**i)*array[element]
i = i + 1
return value
def array_to_subs(array,sub_size,endian):
size = len(array)
elems = int(size/sub_size)
if (size%sub_size != 0):
elems = elems+1
subs = [None for i in xrange(0, elems)]
for i in xrange(0,elems):
subs[i] = array[i*sub_size:i*sub_size+sub_size] if (endian>0) else array[-i*sub_size-sub_size:-i*sub_size]
return subs
def bitsize(val):
return int(math.floor(math.log(val,2))+1)
# print array_to_subs(msg, 4, LITTLE)
# print bitsize(len(alphabet[RUS]))
# print bitsize(len(alphabet[ENG]))
# for abc in [ENG, RUS]:
# for top_endian in [BIG,LITTLE]:
# for bottom_endian in [BIG,LITTLE]:
# string = ""
# for letter in array_to_subs(msg,bitsize(len(alphabet[abc])),top_endian):
# string = string + getletter(int(array_to_value(letter, bottom_endian)) % len(alphabet[abc]), abc)
# print string
# for subs in [8]:
# for top_endian in [BIG,LITTLE]:
# for bottom_endian in [BIG,LITTLE]:
# for offset in xrange(0,127):
# string = ""
# for letter in array_to_subs(msg,subs,top_endian):
# string = string + chr(((array_to_value(letter, bottom_endian) + offset)+ ord(" ")) % 128 )
# print string
# for sub_size in xrange(1,9):
# max_l = -1
# min_l = 99999999
# for letter in array_to_subs(msg,sub_size,BIG):
# max_l = max(max_l, array_to_value(letter, BIG))
# min_l = min(min_l, array_to_value(letter, BIG))
# print str(sub_size) + ": " + str(max_l - min_l) + " " + str(min_l) + "-" + str(max_l)
one = 0
zero = 0
for item in msg:
if item == 0:
zero = zero + 1
if item == 1:
one = one + 1
print "0: " + str(zero) + " 1: " + str(one)
# group = 26
# for offset in xrange(0,26):
# result = ""
# for letter in array_to_subs(msg,4,BIG):
# result = result + getletter(int(array_to_value(letter, BIG) + offset) % 26, ENG)
# print result
value = array_to_value(msg,LITTLE)
print value