diff options
Diffstat (limited to 'daily')
-rw-r--r-- | daily/285easy/1dec.pas | 9 | ||||
-rwxr-xr-x | daily/285easy/1enc | bin | 0 -> 149572 bytes | |||
-rw-r--r-- | daily/285easy/1enc.inp | 1 | ||||
-rw-r--r-- | daily/285easy/1enc.o | bin | 0 -> 6372 bytes | |||
-rw-r--r-- | daily/285easy/1enc.out | 8 | ||||
-rw-r--r-- | daily/285easy/1enc.pas | 79 | ||||
-rw-r--r-- | daily/285easy/part1.out | 8 | ||||
-rw-r--r-- | daily/285easy/part2.inp | 5 | ||||
-rw-r--r-- | daily/285easy/part2.out | 5 | ||||
-rw-r--r-- | daily/285easy/part2.pas | 22 | ||||
-rw-r--r-- | daily/285easy/problem.html | 94 | ||||
-rw-r--r-- | daily/285easy/problem.md | 121 | ||||
-rw-r--r-- | daily/285easy/problem1.html | 61 | ||||
-rw-r--r-- | daily/285easy/problem1.md | 107 | ||||
-rwxr-xr-x | daily/286easy/lairotcaf | bin | 0 -> 148836 bytes | |||
-rw-r--r-- | daily/286easy/lairotcaf.inp | 6 | ||||
-rw-r--r-- | daily/286easy/lairotcaf.o | bin | 0 -> 4976 bytes | |||
-rw-r--r-- | daily/286easy/lairotcaf.out | 6 | ||||
-rw-r--r-- | daily/286easy/lairotcaf.pas | 31 | ||||
-rw-r--r-- | daily/286easy/problem.html | 25 | ||||
-rw-r--r-- | daily/286easy/problem.md | 41 |
21 files changed, 629 insertions, 0 deletions
diff --git a/daily/285easy/1dec.pas b/daily/285easy/1dec.pas new file mode 100644 index 0000000..734bd0f --- /dev/null +++ b/daily/285easy/1dec.pas @@ -0,0 +1,9 @@ +(* uudecoding *) + +var + fi, fo: text; + + +begin + repeat + read(f diff --git a/daily/285easy/1enc b/daily/285easy/1enc new file mode 100755 index 0000000..eecdec1 --- /dev/null +++ b/daily/285easy/1enc Binary files differdiff --git a/daily/285easy/1enc.inp b/daily/285easy/1enc.inp new file mode 100644 index 0000000..997b0c5 --- /dev/null +++ b/daily/285easy/1enc.inp @@ -0,0 +1 @@ +I feel very strongly about you doing duty. Would you give me a little more documentation about your reading in French? I am glad you are happy — but I never believe much in happiness. I never believe in misery either. Those are things you see on the stage or the screen or the printed pages, they never really happen to you in life. diff --git a/daily/285easy/1enc.o b/daily/285easy/1enc.o new file mode 100644 index 0000000..636d662 --- /dev/null +++ b/daily/285easy/1enc.o Binary files differdiff --git a/daily/285easy/1enc.out b/daily/285easy/1enc.out new file mode 100644 index 0000000..f1fd196 --- /dev/null +++ b/daily/285easy/1enc.out @@ -0,0 +1,8 @@ +M22!F965L('9E<GD@<W1R;VYG;'D@86)O=70@>6]U(&1O:6YG(&1U='DN(%=O +M=6QD('EO=2!G:79E(&UE(&$@;&ET=&QE(&UO<F4@9&]C=6UE;G1A=&EO;B!A +M8F]U="!Y;W5R(')E861I;F<@:6X@1G)E;F-H/R!)(&%M(&=L860@>6]U(&%R +M92!H87!P>2#B@)0@8G5T($D@;F5V97(@8F5L:65V92!M=6-H(&EN(&AA<'!I +M;F5S<RX@22!N979E<B!B96QI979E(&EN(&UI<V5R>2!E:71H97(N(%1H;W-E +M(&%R92!T:&EN9W,@>6]U('-E92!O;B!T:&4@<W1A9V4@;W(@=&AE('-C<F5E +M;B!O<B!T:&4@<')I;G1E9"!P86=E<RP@=&AE>2!N979E<B!R96%L;'D@:&%P +4<&5N('1O('EO=2!I;B!L:69E+@ diff --git a/daily/285easy/1enc.pas b/daily/285easy/1enc.pas new file mode 100644 index 0000000..fb7c363 --- /dev/null +++ b/daily/285easy/1enc.pas @@ -0,0 +1,79 @@ +(* uuencoding *) + +var + fi, fo: text; + s: string[3] = 'CnX'; + n: cardinal = 0; + i: cardinal; + j: byte; + + +function enc(s: string): string; + var + c1, c2, c3: byte; + + begin + c1 := ord(s[1]); + if length(s) < 2 then + c2 := 0 + else + c2 := ord(s[2]); + if length(s) < 3 then + c3 := 0 + else + c3 := ord(s[3]); + + enc := chr(c1 div 4 + 32) + + chr(c1 mod 4 * 16 + c2 div 16 + 32) + + chr(c2 mod 16 * 4 + c3 div 64 + 32) + + chr(c3 mod 64 + 32) + end; + + +begin + assign(fi, '1enc.inp'); + assign(fo, '1enc.out'); + + reset(fi); + while not eof(fi) do + begin + read(fi, s[1]); + inc(n) + end; + if n = 0 then + writeln(fo, ' '); + + reset(fi); + rewrite(fo); + for i := 1 to n div 45 do + begin + write(fo, 'M'); + for j := 1 to 15 do + begin + read(fi, s); + write(fo, enc(s)) + end; + writeln(fo); + end; + + n := n mod 45; + if n > 0 then + begin + write(fo, chr(n + 32)); + for i := 1 to n div 3 do + begin + read(fi, s); + write(fo, enc(s)) + end; + if n mod 3 > 0 then + begin + read(fi, s); + writeln(fo, enc(s)) + end + else + writeln(fo) + end; + + close(fi); + close(fo) +end. diff --git a/daily/285easy/part1.out b/daily/285easy/part1.out new file mode 100644 index 0000000..f1fd196 --- /dev/null +++ b/daily/285easy/part1.out @@ -0,0 +1,8 @@ +M22!F965L('9E<GD@<W1R;VYG;'D@86)O=70@>6]U(&1O:6YG(&1U='DN(%=O +M=6QD('EO=2!G:79E(&UE(&$@;&ET=&QE(&UO<F4@9&]C=6UE;G1A=&EO;B!A +M8F]U="!Y;W5R(')E861I;F<@:6X@1G)E;F-H/R!)(&%M(&=L860@>6]U(&%R +M92!H87!P>2#B@)0@8G5T($D@;F5V97(@8F5L:65V92!M=6-H(&EN(&AA<'!I +M;F5S<RX@22!N979E<B!B96QI979E(&EN(&UI<V5R>2!E:71H97(N(%1H;W-E +M(&%R92!T:&EN9W,@>6]U('-E92!O;B!T:&4@<W1A9V4@;W(@=&AE('-C<F5E +M;B!O<B!T:&4@<')I;G1E9"!P86=E<RP@=&AE>2!N979E<B!R96%L;'D@:&%P +4<&5N('1O('EO=2!I;B!L:69E+@ diff --git a/daily/285easy/part2.inp b/daily/285easy/part2.inp new file mode 100644 index 0000000..6e366a5 --- /dev/null +++ b/daily/285easy/part2.inp @@ -0,0 +1,5 @@ +12 +255 +256 +510 +512 44 1024 \ No newline at end of file diff --git a/daily/285easy/part2.out b/daily/285easy/part2.out new file mode 100644 index 0000000..cb04923 --- /dev/null +++ b/daily/285easy/part2.out @@ -0,0 +1,5 @@ +12 +255 0 +255 1 +255 255 0 +255 255 2 44 255 255 255 255 4 diff --git a/daily/285easy/part2.pas b/daily/285easy/part2.pas new file mode 100644 index 0000000..96e58c5 --- /dev/null +++ b/daily/285easy/part2.pas @@ -0,0 +1,22 @@ +var + fi, fo: text; + n, i: cardinal; + + +begin + assign(fi, 'part2.inp'); + assign(fo, 'part2.out'); + reset(fi); + rewrite(fo); + repeat + repeat + read(fi, n); + for i := 1 to n div 255 do + write(fo, 255, ' '); + write(fo, n mod 255, ' ') + until eoln(fi); + writeln(fo) + until eof(fi); + close(fi); + close(fo) +end. diff --git a/daily/285easy/problem.html b/daily/285easy/problem.html new file mode 100644 index 0000000..5cfd9d9 --- /dev/null +++ b/daily/285easy/problem.html @@ -0,0 +1,94 @@ +<p>We will make a binary byte oriented encoding of data that is self describing and extensible, and aims to solve the following problems:</p> +<ul> +<li>portability between 32 and 64 (and any other) bit systems, and languages, and endian-ness.</li> +<li>type system independent of underlying language.<br /> +</li> +<li>Allow heterogeneous arrays (differing types of array elements) where the underlying language has poor support for them.</li> +<li>leverage power of homogeneous arrays in a language.</li> +<li>support records regardless of underlying language (array of records is homogeneous, even though a record is a heterogeneous list of fields)</li> +<li>Allow ragged arrays (a table where each row is a list, but the rows do not have a uniform size (or shape))</li> +<li>Provide basic in memory compression. Allow deferred decoding of partial data.</li> +</ul> +<h1 id="base64-encoding-used-in-later-challenges">1. base64 encoding (used in later challenges)</h1> +<p>To read and write binary data on reddit, we will use <a href="problem1.html">base64 encoding</a>.</p> +<h1 id="extendible-byte-base.">2. Extendible byte base.</h1> +<p>Any size integer can be coded into a variable byte array by using the maximum byte value as a marker to add the next byte value to decode the total.</p> +<p>This is useful for coding numbers that you think can be limited to around 255 or close to it, without being "hard constrained" by that limit. "256 possible op codes (or characters) ought to be enough for everyone forever thinking"</p> +<p><strong>unsigned byte input</strong><br /> +12<br /> +255<br /> +256<br /> +510<br /> +512 44 1024</p> +<p>last input is a list of 3 integers to encode</p> +<p><strong>sample outputs</strong><br /> +12<br /> +255 0<br /> +255 1<br /> +255 255 0<br /> +255 255 2 44 255 255 255 255 4</p> +<p>every element that is not 255 marks the end of "that integer" in a list. You should also write a decoder that transforms output into input.</p> +<h1 id="multibyte-and-variable-byte-encodings">3. multibyte and variable byte encodings</h1> +<p>Instead of a single byte target encoding, 2,4,8 and variable defined byte sizes are also desirable to cover integers with larger ranges. An account balance might have a 40 bit practical limit, but you might not guarantee it forever. 64 bits might not be enough for Zimbabwe currency balances for example.</p> +<p>For compressing a list of numbers, often it is useful to set the whole list to one "byte size". Other choices include,</p> +<ul> +<li>setting an enum/table of possible byte size codings of 1 2 4 8 sizes, and then encoding, the number of elements, the table/enum size and definition, and then 2 lists (enum key, data items)</li> +<li>interleave bytesize, data</li> +</ul> +<p>The latter will often be longer for long lists, but does not encode the table so is simpler to encode/decode.</p> +<p><strong>Encoding format for table definition:</strong></p> +<ol style="list-style-type: decimal"> +<li>4 bytes: first 30 bits - length of list. last 2 bits: key into 1 2 4 8. If first 30 bits are max value, then following 4 bytes are added to count until a non-max value is taken. Similar to challenge #2.<br /> +</li> +<li>list of byte lengths defined by key in 1. If last 2 bits of 1 are 3 (signifies up to 8 distinct integer sizes), then this list has 8 items. If there only 6 distinct integer size codings, then the last 2 items in this list would be ignored and set to 0. Values over 255 are encoded as in challenge 2.</li> +<li>list of ordered data encodings in boolean form, if there are more than 1. 1 bit for 2, 2 bits for 4, 3 bits for 8.</li> +<li>list of data elements.</li> +</ol> +<p><strong>challenges</strong><br /> +encode list of integers from 0 to 1025 using 8 or 16 bit variable encoding. With the shortest encoding that will contain the number. Just print the sum of all the bytes as result for output brevity.</p> +<p><strong>solution</strong></p> +<ol style="list-style-type: decimal"> +<li>first 4 bytes are (1025 * 4) + 1 (leading 0 bytes for smaller than "full size" numbers)</li> +<li>2 byte list: 1 2</li> +<li>0 for first 256 bits, 1 for remaining bits (total 1032 bits long with padding)</li> +<li>256 + (769 * 2) bytes long encoding of the numbers.</li> +</ol> +<h1 id="balanced-signed-numbers">4. balanced signed numbers</h1> +<p>Some numbers are negative. The common computer encoding for signed number ranges is to subtract half the max power of 2 from the value. A signed byte has range -128 to 127, where a 0 value corresponds to -128 (in our encoding).</p> +<p>For numbers outside this range encoded in a single byte, the process is to take the first byte to determine the sign, and then following bytes add or subtract up to 255 per byte until a non 255 value is reached.</p> +<h1 id="unbalanced-signed-numbers">5. unbalanced signed numbers</h1> +<p>Instead of the midpoint marking 0, a byte can encode a value within any defined range. Another important application is to use "negative" numbers as codes of some sort. These include:</p> +<ul> +<li>An expectation that negative numbers are less frequent and smaller relative to 0</li> +<li>coding special values such as null, infinity, undeterminable (0/0)</li> +<li>Using codes to hint at extended byte encodings and sign of the number, or even data type</li> +</ul> +<p><strong>sample 0 index codes</strong> (for 16 reserved codes) (new paragraph for multiline explained codes)<br /> +Null<br /> +Infinity<br /> +Negative Infinity<br /> +Negative 1 byte<br /> +Negative 2 bytes<br /> +Negative 4 bytes<br /> +Negative 8 bytes<br /> +Negative custom byte length (value is encoded into 2 numbers. First is byte length (in 255 terminated bytes, followed by that number of bytes to represent the number)</p> +<p>Positive 1 byte (first number indicates range of 468 to 723). 467 could have been encoded as 255 254 without this special code.</p> +<p>Positive 2 byte<br /> +Positive 4 byte<br /> +Positive 8 byte<br /> +Positive 16 byte<br /> +Positive 64 byte<br /> +Positive custom byte length (3 to 262 excluding other defined lengths) Positive custom 2 byte length (16 bit unsigned number defines byte length of number, followed by encoded number)</p> +<p><strong>sample inputs</strong><br /> +10<br /> +123123<br /> +-55<br /> +Null</p> +<p><strong>sample output</strong><br /> +26<br /> +9 123123<br /> +3 54 (minimum range value is -1)<br /> +0</p> +<p><strong>challenge input</strong></p> +<p>192387198237192837192837192387123817239182737 _44 981237123</p> +<p>array of 3 numbers (_44 is -44) to be encoded</p> diff --git a/daily/285easy/problem.md b/daily/285easy/problem.md new file mode 100644 index 0000000..c02832f --- /dev/null +++ b/daily/285easy/problem.md @@ -0,0 +1,121 @@ +We will make a binary byte oriented encoding of data that is self describing and extensible, and aims to solve the following problems: + +* portability between 32 and 64 (and any other) bit systems, and languages, and endian-ness. +* type system independent of underlying language. +* Allow heterogeneous arrays (differing types of array elements) where the underlying language has poor support for them. +* leverage power of homogeneous arrays in a language. +* support records regardless of underlying language (array of records is homogeneous, even though a record is a heterogeneous list of fields) +* Allow ragged arrays (a table where each row is a list, but the rows do not have a uniform size (or shape)) +* Provide basic in memory compression. Allow deferred decoding of partial data. + +# 1. base64 encoding (used in later challenges) + +To read and write binary data on reddit, we will use [base64 encoding](problem1.html). + +# 2. Extendible byte base. + +Any size integer can be coded into a variable byte array by using the maximum byte value as a marker to add the next byte value to decode the total. + +This is useful for coding numbers that you think can be limited to around 255 or close to it, without being "hard constrained" by that limit. "256 possible op codes (or characters) ought to be enough for everyone forever thinking" + +**unsigned byte input** +12 +255 +256 +510 +512 44 1024 + +last input is a list of 3 integers to encode + +**sample outputs** +12 +255 0 +255 1 +255 255 0 +255 255 2 44 255 255 255 255 4 + +every element that is not 255 marks the end of "that integer" in a list. You should also write a decoder that transforms output into input. + + +# 3. multibyte and variable byte encodings + +Instead of a single byte target encoding, 2,4,8 and variable defined byte sizes are also desirable to cover integers with larger ranges. An account balance might have a 40 bit practical limit, but you might not guarantee it forever. 64 bits might not be enough for Zimbabwe currency balances for example. + +For compressing a list of numbers, often it is useful to set the whole list to one "byte size". Other choices include, + +* setting an enum/table of possible byte size codings of 1 2 4 8 sizes, and then encoding, the number of elements, the table/enum size and definition, and then 2 lists (enum key, data items) +* interleave bytesize, data + +The latter will often be longer for long lists, but does not encode the table so is simpler to encode/decode. + +**Encoding format for table definition:** + +1. 4 bytes: first 30 bits - length of list. last 2 bits: key into 1 2 4 8. If first 30 bits are max value, then following 4 bytes are added to count until a non-max value is taken. Similar to challenge #2. +2. list of byte lengths defined by key in 1. If last 2 bits of 1 are 3 (signifies up to 8 distinct integer sizes), then this list has 8 items. If there only 6 distinct integer size codings, then the last 2 items in this list would be ignored and set to 0. Values over 255 are encoded as in challenge 2. +3. list of ordered data encodings in boolean form, if there are more than 1. 1 bit for 2, 2 bits for 4, 3 bits for 8. +4. list of data elements. + +**challenges** +encode list of integers from 0 to 1025 using 8 or 16 bit variable encoding. With the shortest encoding that will contain the number. Just print the sum of all the bytes as result for output brevity. + +**solution** + +1. first 4 bytes are (1025 * 4) + 1 (leading 0 bytes for smaller than "full size" numbers) +2. 2 byte list: 1 2 +3. 0 for first 256 bits, 1 for remaining bits (total 1032 bits long with padding) +4. 256 + (769 * 2) bytes long encoding of the numbers. + + +# 4. balanced signed numbers + +Some numbers are negative. The common computer encoding for signed number ranges is to subtract half the max power of 2 from the value. A signed byte has range -128 to 127, where a 0 value corresponds to -128 (in our encoding). + +For numbers outside this range encoded in a single byte, the process is to take the first byte to determine the sign, and then following bytes add or subtract up to 255 per byte until a non 255 value is reached. + +# 5. unbalanced signed numbers + +Instead of the midpoint marking 0, a byte can encode a value within any defined range. +Another important application is to use "negative" numbers as codes of some sort. These include: + +* An expectation that negative numbers are less frequent and smaller relative to 0 +* coding special values such as null, infinity, undeterminable (0/0) +* Using codes to hint at extended byte encodings and sign of the number, or even data type + + +**sample 0 index codes** (for 16 reserved codes) (new paragraph for multiline explained codes) +Null +Infinity +Negative Infinity +Negative 1 byte +Negative 2 bytes +Negative 4 bytes +Negative 8 bytes +Negative custom byte length (value is encoded into 2 numbers. First is byte length (in 255 terminated bytes, followed by that number of bytes to represent the number) + +Positive 1 byte (first number indicates range of 468 to 723). 467 could have been encoded as 255 254 without this special code. + +Positive 2 byte +Positive 4 byte +Positive 8 byte +Positive 16 byte +Positive 64 byte +Positive custom byte length (3 to 262 excluding other defined lengths) +Positive custom 2 byte length (16 bit unsigned number defines byte length of number, followed by encoded number) + +**sample inputs** +10 +123123 +-55 +Null + +**sample output** +26 +9 123123 +3 54 (minimum range value is -1) +0 + +**challenge input** + +192387198237192837192837192387123817239182737 _44 981237123 + +array of 3 numbers (_44 is -44) to be encoded diff --git a/daily/285easy/problem1.html b/daily/285easy/problem1.html new file mode 100644 index 0000000..bf843e7 --- /dev/null +++ b/daily/285easy/problem1.html @@ -0,0 +1,61 @@ +<p>You are trapped at uninhabited island only with your laptop. Still you don't want your significant other to worry about you, so you are going to send a message in a bottle with your picture or at least a couple of words from you (sure, you could just write down the words, but that would be less fun). You're going to use uuencoding for that.</p> +<p>Uuencoding is a form of binary-to-text encoding, which uses only symbols from 32-95 diapason, which means all symbols used in the encoding are printable.</p> +<h1 id="description-of-encoding">Description of encoding</h1> +<p>A uuencoded file starts with a header line of the form:</p> +<pre><code>begin <mode> <file><newline></code></pre> +<p><mode> is the file's Unix file permissions as three octal digits (e.g. 644, 744). For Windows 644 is always used.</p> +<p><file> is the file name to be used when recreating the binary data.</p> +<p><newline> signifies a newline character, used to terminate each line.</p> +<p>Each data line uses the format:</p> +<pre><code><length character><formatted characters><newline></code></pre> +<p><length character> is a character indicating the number of data bytes which have been encoded on that line. This is an ASCII character determined by adding 32 to the actual byte count, with the sole exception of a grave accent "`" (ASCII code 96) signifying zero bytes. All data lines except the last (if the data was not divisible by 45), have 45 bytes of encoded data (60 characters after encoding). Therefore, the vast majority of length values is 'M', (32 + 45 = ASCII code 77 or "M").</p> +<p><formatted characters> are encoded characters.</p> +<p>The mechanism of uuencoding repeats the following for every 3 bytes (if there are less than 3 bytes left, trailing 0 are added):</p> +<ol style="list-style-type: decimal"> +<li><p>Start with 3 bytes from the source, 24 bits in total.</p></li> +<li><p>Split into 4 6-bit groupings, each representing a value in the range 0 to 63: bits (00-05), (06-11), (12-17) and (18-23).</p></li> +<li><p>Add 32 to each of the values. With the addition of 32 this means that the possible results can be between 32 (" " space) and 95 ("_" underline). 96 ("`" grave accent) as the "special character" is a logical extension of this range.</p></li> +<li><p>Output the ASCII equivalent of these numbers.</p></li> +</ol> +<p>For example, we want to encode a word "Cat". ASCII values for C,a,t are 67,97,116, or <code>010000110110000101110100</code> in binary. After dividing into four groups, we get 010000 110110 000101 110100, which is 16,54,5,52 in decimal. Adding 32 to this values and encoding back in ASCII, the final result is <code>0V%T</code>.</p> +<p>The file ends with two lines:</p> +<pre><code>`<newline> +end<newline></code></pre> +<h1 id="formal-inputs-outputs">Formal Inputs & Outputs</h1> +<h2 id="input">Input</h2> +<p>a byte array or string.</p> +<h2 id="output">Output</h2> +<p>a string containing uuencoded input.</p> +<h1 id="examples">Examples</h1> +<p>Input: Cat</p> +<p>Output:</p> +<pre><code>begin 644 cat.txt +#0V%T +` +end</code></pre> +<p>Input: I feel very strongly about you doing duty. Would you give me a little more documentation about your reading in French? I am glad you are happy — but I never believe much in happiness. I never believe in misery either. Those are things you see on the stage or the screen or the printed pages, they never really happen to you in life.</p> +<p>Output:</p> +<pre><code>begin 644 file.txt +M22!F965L('9E<GD@<W1R;VYG;'D@86)O=70@>6]U(&1O:6YG(&1U='DN(%=O +M=6QD('EO=2!G:79E(&UE(&$@;&ET=&QE(&UO<F4@9&]C=6UE;G1A=&EO;B!A +M8F]U="!Y;W5R(')E861I;F<@:6X@1G)E;F-H/R!)(&%M(&=L860@>6]U(&%R +M92!H87!P>2#B@)0@8G5T($D@;F5V97(@8F5L:65V92!M=6-H(&EN(&AA<'!I +M;F5S<RX@22!N979E<B!B96QI979E(&EN(&UI<V5R>2!E:71H97(N(%1H;W-E +M(&%R92!T:&EN9W,@>6]U('-E92!O;B!T:&4@<W1A9V4@;W(@=&AE('-C<F5E +M;B!O<B!T:&4@<')I;G1E9"!P86=E<RP@=&AE>2!N979E<B!R96%L;'D@:&%P +3<&5N('1O('EO=2!I;B!L:69E+C P +` +end</code></pre> +<h1 id="bonuses">Bonuses</h1> +<h2 id="bonus-1">Bonus 1</h2> +<p>Write uudecoder, which decodes uuencoded input back to a byte array or string</p> +<h2 id="bonus-2">Bonus 2</h2> +<p>Write encoder for files as well.</p> +<h2 id="bonus-3">Bonus 3</h2> +<p>Make encoding parallel.</p> +<h1 id="further-reading">Further Reading</h1> +<p><a href="https://en.wikipedia.org/wiki/Binary-to-text_encoding">Binary-to-text encoding</a> on Wikipedia.</p> +<h1 id="finally">Finally</h1> +<p>This challenge is posted by /u/EvgeniyZh</p> +<p>Also have a good challenge idea?</p> +<p>Consider submitting it to /r/dailyprogrammer_ideas</p> diff --git a/daily/285easy/problem1.md b/daily/285easy/problem1.md new file mode 100644 index 0000000..2318628 --- /dev/null +++ b/daily/285easy/problem1.md @@ -0,0 +1,107 @@ +You are trapped at uninhabited island only with your laptop. Still you don't want your significant other to worry about you, so you are going to send a message in a bottle with your picture or at least a couple of words from you (sure, you could just write down the words, but that would be less fun). You're going to use uuencoding for that. + +Uuencoding is a form of binary-to-text encoding, which uses only symbols from 32-95 diapason, which means all symbols used in the encoding are printable. + +#Description of encoding + +A uuencoded file starts with a header line of the form: + + begin <mode> <file><newline> + +<mode> is the file's Unix file permissions as three octal digits (e.g. 644, 744). For Windows 644 is always used. + +<file> is the file name to be used when recreating the binary data. + +<newline> signifies a newline character, used to terminate each line. + +Each data line uses the format: + + <length character><formatted characters><newline> + +<length character> is a character indicating the number of data bytes which have been encoded on that line. This is an ASCII character determined by adding 32 to the actual byte count, with the sole exception of a grave accent "`" (ASCII code 96) signifying zero bytes. All data lines except the last (if the data was not divisible by 45), have 45 bytes of encoded data (60 characters after encoding). Therefore, the vast majority of length values is 'M', (32 + 45 = ASCII code 77 or "M"). + + +<formatted characters> are encoded characters. + +The mechanism of uuencoding repeats the following for every 3 bytes (if there are less than 3 bytes left, trailing 0 are added): + +1. Start with 3 bytes from the source, 24 bits in total. + +2. Split into 4 6-bit groupings, each representing a value in the range 0 to 63: bits (00-05), (06-11), (12-17) and (18-23). + +3. Add 32 to each of the values. With the addition of 32 this means that the possible results can be between 32 (" " space) and 95 ("_" underline). 96 ("`" grave accent) as the "special character" is a logical extension of this range. + +4. Output the ASCII equivalent of these numbers. + + +For example, we want to encode a word "Cat". ASCII values for C,a,t are 67,97,116, or `010000110110000101110100` in binary. After dividing into four groups, we get 010000 110110 000101 110100, which is 16,54,5,52 in decimal. Adding 32 to this values and encoding back in ASCII, the final result is `0V%T`. + +The file ends with two lines: + + `<newline> + end<newline> + +#Formal Inputs & Outputs + +##Input + +a byte array or string. + +##Output + +a string containing uuencoded input. + +#Examples + +Input: Cat + +Output: + + begin 644 cat.txt + #0V%T + ` + end + +Input: +I feel very strongly about you doing duty. Would you give me a little more documentation about your reading in French? I am glad you are happy — but I never believe much in happiness. I never believe in misery either. Those are things you see on the stage or the screen or the printed pages, they never really happen to you in life. + + +Output: + + begin 644 file.txt + M22!F965L('9E<GD@<W1R;VYG;'D@86)O=70@>6]U(&1O:6YG(&1U='DN(%=O + M=6QD('EO=2!G:79E(&UE(&$@;&ET=&QE(&UO<F4@9&]C=6UE;G1A=&EO;B!A + M8F]U="!Y;W5R(')E861I;F<@:6X@1G)E;F-H/R!)(&%M(&=L860@>6]U(&%R + M92!H87!P>2#B@)0@8G5T($D@;F5V97(@8F5L:65V92!M=6-H(&EN(&AA<'!I + M;F5S<RX@22!N979E<B!B96QI979E(&EN(&UI<V5R>2!E:71H97(N(%1H;W-E + M(&%R92!T:&EN9W,@>6]U('-E92!O;B!T:&4@<W1A9V4@;W(@=&AE('-C<F5E + M;B!O<B!T:&4@<')I;G1E9"!P86=E<RP@=&AE>2!N979E<B!R96%L;'D@:&%P + 3<&5N('1O('EO=2!I;B!L:69E+C P + ` + end + +#Bonuses + +##Bonus 1 + +Write uudecoder, which decodes uuencoded input back to a byte array or string + +##Bonus 2 + +Write encoder for files as well. + +##Bonus 3 + +Make encoding parallel. + +#Further Reading + +[Binary-to-text encoding](https://en.wikipedia.org/wiki/Binary-to-text_encoding) on Wikipedia. + +#Finally + +This challenge is posted by /u/EvgeniyZh + +Also have a good challenge idea? + +Consider submitting it to /r/dailyprogrammer_ideas diff --git a/daily/286easy/lairotcaf b/daily/286easy/lairotcaf new file mode 100755 index 0000000..68e22b8 --- /dev/null +++ b/daily/286easy/lairotcaf Binary files differdiff --git a/daily/286easy/lairotcaf.inp b/daily/286easy/lairotcaf.inp new file mode 100644 index 0000000..ea4419c --- /dev/null +++ b/daily/286easy/lairotcaf.inp @@ -0,0 +1,6 @@ +3628800 +479001600 +6 +18 +150 +120 diff --git a/daily/286easy/lairotcaf.o b/daily/286easy/lairotcaf.o new file mode 100644 index 0000000..ebc1810 --- /dev/null +++ b/daily/286easy/lairotcaf.o Binary files differdiff --git a/daily/286easy/lairotcaf.out b/daily/286easy/lairotcaf.out new file mode 100644 index 0000000..9916cd0 --- /dev/null +++ b/daily/286easy/lairotcaf.out @@ -0,0 +1,6 @@ +3628800 = 10! +479001600 = 12! +6 = 3! +18 NONE +150 NONE +120 = 5! diff --git a/daily/286easy/lairotcaf.pas b/daily/286easy/lairotcaf.pas new file mode 100644 index 0000000..ef2c910 --- /dev/null +++ b/daily/286easy/lairotcaf.pas @@ -0,0 +1,31 @@ +var + fi, fo: text; + n, i: int64; + +begin + assign(fi, 'lairotcaf.inp'); + assign(fo, 'lairotcaf.out'); + reset(fi); + rewrite(fo); + repeat + readln(fi, n); + write(fo, n); + if n > 0 then + begin + i := 2; + while n mod i = 0 do + begin + n := n div i; + inc(i) + end; + if n = 1 then + begin + writeln(fo, ' = ', i - 1, '!'); + continue + end + end; + writeln(fo, ' NONE') + until eof(fi); + close(fi); + close(fo) +end. diff --git a/daily/286easy/problem.html b/daily/286easy/problem.html new file mode 100644 index 0000000..362cc50 --- /dev/null +++ b/daily/286easy/problem.html @@ -0,0 +1,25 @@ +<h1 id="description">Description</h1> +<p>Nearly everyone is familiar with the factorial operator in math. 5! yields 120 because factorial means "multiply successive terms where each are one less than the previous":</p> +<pre><code>5! -> 5 * 4 * 3 * 2 * 1 -> 120</code></pre> +<p>Simple enough.</p> +<p>Now let's reverse it. Could you write a function that tells us that "120" is "5!"?</p> +<p>Hint: The strategy is pretty straightforward, just divide the term by successively larger terms until you get to "1" as the resultant:</p> +<pre><code>120 -> 120/2 -> 60/3 -> 20/4 -> 5/5 -> 1 => 5!</code></pre> +<h1 id="sample-input">Sample Input</h1> +<p>You'll be given a single integer, one per line. Examples:</p> +<pre><code>120 +150</code></pre> +<h1 id="sample-output">Sample Output</h1> +<p>Your program should report what each number is as a factorial, or "NONE" if it's not legitimately a factorial. Examples:</p> +<pre><code>120 = 5! +150 NONE</code></pre> +<h1 id="challenge-input">Challenge Input</h1> +<pre><code>3628800 +479001600 +6 +18</code></pre> +<h1 id="challenge-output">Challenge Output</h1> +<pre><code>3628800 = 10! +479001600 = 12! +6 = 3! +18 NONE</code></pre> diff --git a/daily/286easy/problem.md b/daily/286easy/problem.md new file mode 100644 index 0000000..8715cbe --- /dev/null +++ b/daily/286easy/problem.md @@ -0,0 +1,41 @@ +# Description + +Nearly everyone is familiar with the factorial operator in math. 5! yields 120 because factorial means "multiply successive terms where each are one less than the previous": + + 5! -> 5 * 4 * 3 * 2 * 1 -> 120 + +Simple enough. + +Now let's reverse it. Could you write a function that tells us that "120" is "5!"? + +Hint: The strategy is pretty straightforward, just divide the term by successively larger terms until you get to "1" as the resultant: + + 120 -> 120/2 -> 60/3 -> 20/4 -> 5/5 -> 1 => 5! + +# Sample Input + +You'll be given a single integer, one per line. Examples: + + 120 + 150 + +# Sample Output + +Your program should report what each number is as a factorial, or "NONE" if it's not legitimately a factorial. Examples: + + 120 = 5! + 150 NONE + +# Challenge Input + + 3628800 + 479001600 + 6 + 18 + +# Challenge Output + + 3628800 = 10! + 479001600 = 12! + 6 = 3! + 18 NONE |