r/dailyprogrammer • u/nint22 1 2 • Feb 06 '13
[02/06/13] Challenge #120 [Intermediate] Base Conversion Words
(Intermediate): Base Conversion Words
Given as input an arbitrary string and base (integer), your goal is to convert the base-encoded string to all bases from 2 to 64 and try to detect all English-language words.
Author: aredna
Formal Inputs & Outputs
Input Description
On the console, you will be first given an arbitrary string followed by an integer "Base". This given string is base-encoded, so as an example if the string is "FF" and base is "16", then we know that the string is hex-encoded, where "FF" means 255 in decimal.
Output Description
Given this string, you goal is to re-convert it to all bases, between 2 (binary) to 64. Based on these results, if any English-language words are found within the resulting encodings, print the encoded string, the encoding base, and on the same line have a comma-separated list of all words you found in it.
It is ** extremely** important to note this challenge's encoding scheme: unlike the "Base-64" encoding scheme, we will associate the value 0 (zero) as the character '0', up to value '9' (nine), the value 10 as the character 'a' up to 35 as the character 'z', the value 26 as 'A', then the value 61 as 'Z', and finally 62 as '+' (plus) and 63 as '/' (division). Essentially it is as follows:
Values 0 to 9 maps to '0' through '9'
Values 10 to 35 maps to 'a' through 'z'
Values 36 to 61 maps to 'A' through 'Z'
Value 62 maps to '+'
Value 63 maps to '/'Sample Inputs & Outputs
Sample Input
E1F1 22Sample Output
Coming soon!Challenge Input
None given
Challenge Input Solution
None given
Note
None
19
u/djnattyp Feb 06 '13
This part of the challenge is a little too vague... especially since there's no example output of this part.
Care to point me to a dictionary to use, or are we just assuming any non-numeric strings are "English-language words"?
14
u/Sonnenhut Feb 06 '13
Apparently I think this is wrong. the input should be "ff 16" and not "FF 16" because our encoding goes: 0-9a-f with the base 16
10
u/Sonnenhut Feb 06 '13 edited Feb 06 '13
for everyone who is lazy. here is the encoding (format it to your language if you need it) - Java:
4
u/[deleted] Feb 06 '13
In the output description, I think you meant to put:
but instead it says:
3
u/skeeto -9 8 Feb 06 '13
JavaScript,
Usage:
Emacs Lisp / Common Lisp,
3
u/lawlrng 0 1 Feb 06 '13 edited Feb 06 '13
Just kind of ignoring the check for words since I don't have handy access to a dictionary.
2
u/[deleted] Feb 06 '13
A dictionary would be needed to find if it's actually an English word, right?
Anyways, my unreasonably long solution in Python. Any tips would be appreciated
2
u/minno Feb 06 '13
If the capital letters map to 36 through 61, then E1F1, the sample input, is not a valid base-22 number.
2
u/TheSpongeGod Feb 08 '13 edited Feb 10 '13
Haskell, modified to use a real dictionary. I changed the test data, because e1f1 doesn't actually encode to any real words:
2
u/DannyP72 Feb 08 '13
Ruby
Output - using e1f1 with base 25 to produce a dictionary hit
2
u/Sonnenhut Feb 06 '13
Soloution in Java. Prints out all encoded words for every number system (2-62)
Output for( "e1f1 22"):
1
u/Rup-Inc Feb 06 '13 edited Feb 06 '13
Solution in c++.
edit: Input "e1f1" (what I think the submitter is meaning) gives an output of 149887
1
u/jeff303 0 2 Feb 06 '13
Here is my solution given my interpretation of the problem, in Python.
Sample input:
Sample output:
For the word list, I basically just used /usr/dict/words from an arbitrary Linux server I had access to (can paste it later if anyone wants to see it). I also didn't attempt to validate input (you could provide an invalid string for the specified encoding, as pointed out by minno's comment and this code wouldn't complain).
1
u/w0lfey Feb 06 '13
another solution in java using something todo with cryptography especially caesar chiffre and vigenere key gathering to identify words (infinite monkey theorem may also apply). missing the part to identify single words e.g. using the phi on different substrings. the method works a lot better on longer phrases than on the small text
1
u/jpverkamp Feb 06 '13
Here's what I have in Racket. This is most of the code, but in the interest of space, I left a few of the details in a post on my blog (numbers as words in arbitrary bases).
We'll start at the end with a function to convert any number into all bases 2-64:
For that to work, we need to be able to turn any arbitrary decimal number into a list of digits. So for exable 101 in decimal is 65 in hexadecimal, so this function would return (6 5).
Finally, a function to convert a list of digits to a string. So (6 5) would become "65"
Then I'll actually combine that with a dictionary library that I wrote previously. I'm using the wordsEn.txt word list from SIL International. Now we can filter the results from
->all-basesto get->all-base-words. As an arbitrary example:The nice thing is that it's easy enough to use this to generate all such words:
Here's a random slice of that:
This doesn't actually convert from an arbitrary base, but there's more than enough code in my blog post to do that.
1
u/SmartViking Feb 16 '13
Python, combining 2 dictionaries, with only words length greater than 3:
Example usage:
1
u/codemac Mar 05 '13 edited Mar 06 '13
scheme (guile):
Remembering the whole
for bases really simplified everything down.
1
u/AbigailBuccaneer Mar 26 '13
C++11 with heavy usage of the STL. I suspect this could be optimised quite a bit; it runs disappointingly slowly. I submit this for full code review.
Output:
1
u/Schmenge470 Mar 27 '13
Java (assuming the input is e1f1 22, and using a standard linux words file): import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.HashMap;
1
u/DaveAZME Apr 13 '13
Python:
Output for input of "face 16"