Please elp

q250

Junior Member
Nov 12, 2023
2
1
36
Hello everybody. I have problem: I need to write program but iam not programmer. Full algorithm of actions:

Program read any file and check if it not has .cmprs extension, if it not has it check it size, if it equal to 8192 bit then read it in binary and check if it not consist of only zeroes or ones. If all checks is true then do subroutines 1, else check if it has .cmprs extension and it size is smaller than 8192 bit, if true then do subroutines 2, else print “error” and HALT.

Subroutines 1: open file as binary text string, ie all 1 and 0 now become text character. Delete from that string from left all zeroes and one one, that one included, if we get empty string use exemption rule. Declare variable N that equal to number of bits of resulting string. Declare variable D10 that equal to that string value in base10, ignoring all zeroes from left, example string 0101 has integer value 5, string 101 also has integer value 5. Declare variable A that equal to N + D10. Now add 1 to A, ie A:=A+1. Now declare variable B that equal to Floor from log(A) base 2. Now declare variable R that equal to R:=A – 2^B. Now construct binary text string that equal to R in binary and add as much 0 from left as much it needed to make it overall size equal B, example B=3 R=2: firstly get string from R = 10, then add so much zeroes, in our case only one, and final answer 010. Now save that string with name of original file, add low dash and old extension letters, and .cmprs extension and HALT. Exemption rule: just write 0 in new string, save that string with name of original file, add low dash and old extension letters, and .cmprs extension and HALT.

Subroutines 2: : open file as binary text string. Declare variable N that equal to number of bits of resulting string. Declare variable D10 that equal to that string value in base10, ignoring all zeroes from left, example string 0101 has integer value 5, string 101 also has integer value 5. Declare variable A that equal to N + D10. Now subtract 1 from A, ie A:=A-1. If A turn out to be 1 then use exemption rule. Now declare variable B that equal to Floor from log(A) base 2. Now declare variable R that equal to R:=A – 2^B. Now construct binary text string that equal to R in binary and add as much 0 from left as much it needed to make it overall size equal B. Now add to that string one one from left, and add even further to left as much zeroes it needed to make overall string size equal to 8192. Now save that string as binary file under old file name, removing .cmprs extension from it and replace low dash with dot, ie if for example old name was music_mp3.cmprs now it become music.mp3 and HALT. Exemption rule: just write 1 in new string and as much 0 needed to make overall size equal to 8192, now save that string as binary file under old file name, removing .cmprs extension from it and replace low dash with dot and HALT.

If you interested in context and want to know what this program does let me know.
 
  • Haha
Reactions: purbeast0

daveybrat

Elite Member
Super Moderator
Jan 31, 2000
5,772
989
126
I suggest you fork out the money to pay an actual programmer. If you don't know anything about programming, how are you possibly going to create a program??
 
  • Like
Reactions: Ken g6

q250

Junior Member
Nov 12, 2023
2
1
36
I suggest you fork out the money to pay an actual programmer. If you don't know anything about programming, how are you possibly going to create a program??
like i have some spare money to pay programmer. I was hoping that somebody with some spare time willing to write that programm. its not huge request, just load binary string, do some calculation and give out another binary string. this is more like when your neighbor came to you and ask "hey man, can you help me to take out trash?"
 

quikah

Diamond Member
Apr 7, 2003
4,130
696
126
like i have some spare money to pay programmer. I was hoping that somebody with some spare time willing to write that programm. its not huge request, just load binary string, do some calculation and give out another binary string. this is more like when your neighbor came to you and ask "hey man, can you help me to take out trash?"
OK, here is the program using the amount of effort it would take to help take out the trash (I asked ChatGPT). ChatGPT didn't want to do it all at once, so it had to split out the subroutine code, you will have to figure out how to combine them (not hard). No clue if it works. I only did this because I was curious how well ChatGPT works.

Code:
import os
import math

def read_file(filename):
    with open(filename, 'rb') as file:
        content = file.read()
    return content

def is_valid_binary_string(binary_string):
    # Check if the binary string contains only 0s and 1s
    return all(bit in '01' for bit in binary_string)

def process_file(filename):
    # Check if the file has a .cmprs extension
    if not filename.endswith('.cmprs'):
        # Check file size
        file_size = os.path.getsize(filename) * 8  # Convert size to bits
        if file_size == 8192:
            content = read_file(filename)
            binary_string = ''.join(format(byte, '08b') for byte in content)
           
            if is_valid_binary_string(binary_string):
                # Subroutine 1
                # Perform operations described in subroutine 1
                # ...

            else:
                # Handle exemption rule for Subroutine 1
                # ...

        else:
            # Check if file has .cmprs extension and size smaller than 8192 bits
            # Perform operations described in Subroutine 2
            # ...

    else:
        # Print error and halt
        print("Error")
        return
---- Subroutine 1----
import os
import math

def read_file(filename):
    with open(filename, 'rb') as file:
        content = file.read()
    return content

def is_valid_binary_string(binary_string):
    return all(bit in '01' for bit in binary_string)

def subroutine_1(filename, binary_string):
    # Delete leading zeros and ones
    binary_string = binary_string.lstrip('01')

    if not binary_string:
        # Handle exemption rule
        result_string = '0'
    else:
        # Perform operations described in Subroutine 1
        n = len(binary_string)
        d10 = int(binary_string, 2)
        a = n + d10 + 1
        b = math.floor(math.log2(a))
        r = a - 2**b
        result_string = format(int(r), '0' + str(b) + 'b')

    # Save result string with a new filename
    new_filename = f"{os.path.splitext(filename)[0]}_{result_string}.cmprs"
    with open(new_filename, 'w') as new_file:
        new_file.write(result_string)

    print(f"Subroutine 1 completed. Result saved as {new_filename}")
---- Subroutine2 ---
import os
import math

def read_file(filename):
    with open(filename, 'rb') as file:
        content = file.read()
    return content

def is_valid_binary_string(binary_string):
    return all(bit in '01' for bit in binary_string)

def subroutine_2(filename, binary_string):
    n = len(binary_string)
    d10 = int(binary_string, 2)
    a = n + d10 - 1

    if a == 1:
        # Handle exemption rule for Subroutine 2
        result_string = '1' + '0' * 8191
    else:
        b = math.floor(math.log2(a))
        r = a - 2**b
        result_string = format(int(r), '0' + str(b) + 'b')
        result_string = '0' * (8192 - len(result_string)) + result_string

        # Add one '1' to the left
        result_string = '1' + result_string

    # Save result string as binary file
    new_filename = f"{os.path.splitext(filename)[0].replace('_', '.')}_{result_string}.cmprs"
    with open(new_filename, 'wb') as new_file:
        new_file.write(bytes(int(result_string[i:i+8], 2) for i in range(0, 8192, 8))

    print(f"Subroutine 2 completed. Result saved as {new_filename}")
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,438
4,270
75
like i have some spare money to pay programmer. I was hoping that somebody with some spare time willing to write that programm. its not huge request, just load binary string, do some calculation and give out another binary string. this is more like when your neighbor came to you and ask "hey man, can you help me to take out trash?"
This feels more like asking your neighbor to repair your garbage disposal. Even if it's unplugged, it looks like it's going to be a grind. :p

8kbit numbers mean you likely need a bignum library. Kind of like you were using your garbage disposal to grind up a small tree.

But, being neighborly, I can help you research wood chippers, metaphorically speaking. (I'm suggesting the Python, not the C derived from it.)

Looks like another neighbor had their dog drag the tree into the yard and chew on some of the sticks. It doesn't look like it did the job, but it's not entirely unhelpful. Especially since ChatGPT seems to have picked Python as well.
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,116
479
126
I'm just trying to figure out the point of the check for binary file since all files stored on a disk are always binary, and only made of 1's and 0's, and it is then how you interpret the 1's and 0's as to if that contains different meaning/data....