about summary refs log tree commit diff
path: root/daily
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-10 22:03:50 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-11 09:16:52 +0700
commitc1628d6538d846f26d6dfd88e495205235c31110 (patch)
tree3fcc67809b8c8fe15ff5c7240f90bda8db6ef385 /daily
parent73b09b6b69abce68a06815e7cd789ff0ae70e2b2 (diff)
downloadcp-c1628d6538d846f26d6dfd88e495205235c31110.tar.gz
/r/dailyprogrammer Challenge #285: Add Python 3 solutions
Diffstat (limited to 'daily')
-rwxr-xr-xdaily/285easy/1dec.py7
-rwxr-xr-xdaily/285easy/1enc.py10
-rwxr-xr-xdaily/285easy/2dec.py13
-rw-r--r--daily/285easy/2enc.inp5
-rw-r--r--daily/285easy/2enc.out5
-rwxr-xr-xdaily/285easy/2enc.py7
6 files changed, 37 insertions, 10 deletions
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')