Last active
October 18, 2021 08:18
-
-
Save toastal/7ba17bcdc86d221c2705 to your computer and use it in GitHub Desktop.
Challenge 202 - https://www.reddit.com/r/dailyprogrammer/2w84hl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str1 = '0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100'; | |
var str2 = '0111000001101100011001010110000101110011011001010010000001110100011000010110110001101011001000000111010001101111001000000110110101100101'; | |
var str3 = '011011000110100101100110011001010010000001110010011010010110011101101000011101000010000001101110011011110111011100100000011010010111001100100000011011000110111101101110011001010110110001111001'; | |
var binStr2ASCII = (str) => { | |
return str.match(/[01]{8}/g).map(x => String.fromCharCode(parseInt(x, 2))).join(''); | |
}; | |
var testStrs = [str1, str2, str3]; | |
testStrs.forEach(str => console.log(binStr2ASCII(str))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str1 = '0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100' | |
str2 = '0111000001101100011001010110000101110011011001010010000001110100011000010110110001101011001000000111010001101111001000000110110101100101' | |
str3 = '011011000110100101100110011001010010000001110010011010010110011101101000011101000010000001101110011011110111011100100000011010010111001100100000011011000110111101101110011001010110110001111001' | |
binStr2ASCII = (str) -> | |
str.match(/[01]{8}/g).map((x) -> String.fromCharCode(parseInt x, 2)).join '' | |
testStrs = [str1, str2, str3] | |
testStrs.forEach((str) -> console.log (binStr2ASCII str)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
str1 = '0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100' | |
str2 = '0111000001101100011001010110000101110011011001010010000001110100011000010110110001101011001000000111010001101111001000000110110101100101' | |
str3 = '011011000110100101100110011001010010000001110010011010010110011101101000011101000010000001101110011011110111011100100000011010010111001100100000011011000110111101101110011001010110110001111001' | |
def bin_str_2_ASCII(str): | |
return ''.join(chr(int(x, 2)) for x in re.findall('[01]{8}', str1)) | |
def main(): | |
for str in [str1, str2, str3]: | |
print(bin_str_2_ASCII(str)) | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- NOT YET WORKING >< | |
import Bitwise | |
import Char (fromCode) | |
import List (..) | |
import String | |
import Regex | |
import Text (asText) | |
str1 = "0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100" | |
str2 = "0111000001101100011001010110000101110011011001010010000001110100011000010110110001101011001000000111010001101111001000000110110101100101" | |
str3 = "011011000110100101100110011001010010000001110010011010010110011101101000011101000010000001101110011011110111011100100000011010010111001100100000011011000110111101101110011001010110110001111001" | |
binaryPlaceVal : Int | |
binaryPlaceVal = reverse <| map (\x -> x ^ 2) [1..9] | |
ints2String : List Int -> String | |
ints2String ints = | |
String.fromList <| map fromCode ints | |
bools2Int : List Bool -> Int | |
bools2Int bools = | |
foldl (+) 0 <| map2 (\x y -> if y == True then x else 0) binaryPlaceVal bools | |
word2Bools : String -> List Bool | |
word2Bools str = | |
map (\x -> if x == '0' then True else False) <| String.toList str | |
breakWords : String -> List String | |
breakWords str = | |
map (\x -> x.match) <| Regex.find Regex.All (Regex.regex "[01]{8}") str | |
-- binStr2ASCII : String -> String | |
binStr2ASCII str = | |
ints2String <| map bools2Int <| map word2Bools <| breakWords str | |
main = | |
asText <| binStr2ASCII str1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment