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.
 
Reactions: purbeast0

daveybrat

Elite Member
Super Moderator
Jan 31, 2000
5,736
949
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??
 
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,079
661
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,255
3,853
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.

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,045
432
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....
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |