Skip to content

Instantly share code, notes, and snippets.

@skytreader
Created June 3, 2013 07:52
Show Gist options
  • Save skytreader/5696674 to your computer and use it in GitHub Desktop.
Save skytreader/5696674 to your computer and use it in GitHub Desktop.
Terribly inefficient SMS point-to-point packing.
#! /usr/bin/env python3
import math
"""
Proof-of-concept pseudocode for SMS point-to-point
packing.
"""
def pack(char_encodings):
"""
Where char_count is a list of length-7 strings.
"""
alphabet_markers = "abcdefg"
char_count = len(char_encodings)
row_count = math.ceil((char_count * 7) / 8)
grid = [[' 0' for i in range(8)] for i in range(row_count)]
offset = 1
for i in range(char_count):
start = offset
char_display = str(i + 1)
row_translation = math.ceil((i * 7) / 8)
if not i % 7 and i:
row_translation -= 1
while start < 8:
if offset == 0 and start == 7:
break
grid[row_translation][start] = char_encodings[i][start - offset]
start += 1
go_up_start = start - offset
up_row = row_translation - 1
while up_row >= 0 and go_up_start < len(alphabet_markers):
grid[up_row][go_up_start - (start - offset)] = char_encodings[i][go_up_start]
go_up_start += 1
offset = (offset + 1) % 8
return grid
def print_grid(grid):
for row in grid:
print(str(row))
if __name__ == "__main__":
print_grid(pack(("1000001", "1001100", "1010000", "1001000", "1000001", "0000000", "1001110", "1010101", "1001101")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment