From c1628d6538d846f26d6dfd88e495205235c31110 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Mon, 10 Oct 2016 22:03:50 +0700 Subject: /r/dailyprogrammer Challenge #285: Add Python 3 solutions --- daily/285easy/1dec.py | 7 +++++++ daily/285easy/1enc.py | 10 ++++++++++ daily/285easy/2dec.py | 13 +++++++++++++ daily/285easy/2enc.inp | 5 ----- daily/285easy/2enc.out | 5 ----- daily/285easy/2enc.py | 7 +++++++ 6 files changed, 37 insertions(+), 10 deletions(-) create mode 100755 daily/285easy/1dec.py create mode 100755 daily/285easy/1enc.py create mode 100755 daily/285easy/2dec.py delete mode 100644 daily/285easy/2enc.inp delete mode 100644 daily/285easy/2enc.out create mode 100755 daily/285easy/2enc.py (limited to 'daily') diff --git a/daily/285easy/1dec.py b/daily/285easy/1dec.py new file mode 100755 index 0000000..2a05ec4 --- /dev/null +++ b/daily/285easy/1dec.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +from binascii import a2b_uu + +with open('1dec.inp') as fi, open('1dec.out', 'w') as fo: + for line in fi: + fo.write(a2b_uu(bytes(line, 'ascii')).decode()) diff --git a/daily/285easy/1enc.py b/daily/285easy/1enc.py new file mode 100755 index 0000000..8ce1a95 --- /dev/null +++ b/daily/285easy/1enc.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 + +from binascii import b2a_uu + +with open('1enc.inp') as f: + s = f.read() + +with open('1enc.out', 'w') as f: + for i in range(0, n, 45): + f.write(b2a_uu(bytes(s[i : i+45], 'utf-8')).decode()) diff --git a/daily/285easy/2dec.py b/daily/285easy/2dec.py new file mode 100755 index 0000000..a0b6bb2 --- /dev/null +++ b/daily/285easy/2dec.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +tmp = 0 + +with open('2dec.inp') as fi, open('2dec.out', 'w') as fo: + for line in fi: + l = [] + for n in line.split(): + tmp += int(n) + if n != '255': + l.append(str(tmp)) + tmp = 0 + fo.write(' '.join(l) + '\n') diff --git a/daily/285easy/2enc.inp b/daily/285easy/2enc.inp deleted file mode 100644 index 6e366a5..0000000 --- a/daily/285easy/2enc.inp +++ /dev/null @@ -1,5 +0,0 @@ -12 -255 -256 -510 -512 44 1024 \ No newline at end of file diff --git a/daily/285easy/2enc.out b/daily/285easy/2enc.out deleted file mode 100644 index cb04923..0000000 --- a/daily/285easy/2enc.out +++ /dev/null @@ -1,5 +0,0 @@ -12 -255 0 -255 1 -255 255 0 -255 255 2 44 255 255 255 255 4 diff --git a/daily/285easy/2enc.py b/daily/285easy/2enc.py new file mode 100755 index 0000000..1aeb15f --- /dev/null +++ b/daily/285easy/2enc.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +enc = lambda n: ' '.join([str(i) for i in n // 255 * [255] + [n % 255]]) + +with open('2enc.inp') as fi, open('2enc.out', 'w') as fo: + for line in fi: + fo.write(' '.join([enc(int(n)) for n in line.split()]) + '\n') -- cgit 1.4.1