|
The program has to be a command line tool which asks the user for the name of the JavaScript file and then compresses only the string
values therein, saving the compressed version as an output file.
The compression algorithm looks for the biggest string pieces which occur in the code more than one time and replaces them with short name
variable concatenations. Then it looks for the next big pieces and so on. If the repeatedly occuring piece is smaller than 13 characters, or if it is so small that
a replacement makes no sense, it has to stay non-replaced. This is because the necassery code for preparing and doing the concatenation must be regarded
(plus symbols, new quotes, semicolons, a replacement variable consisting of two characters).
It is important that the compressed code works as flawless as the uncompressed one. The objective is to keep the string data amount as small as
possible. The code itself must not be compressed.
Example:
Uncompressed Version:
if(val1=="176666424890004920914453345888X00049209144533458881399")
alert("You won - now click on number 890004920914453345888X000492091445334588813");
Compressed Version:
aa="0004920914453345888";
ab="89"+aa+"X"+aa+"13";
if(val1=="176666424"+ab+"99")
alert("You won - now click on number "+ab);
Please consider that in this example a is a replacement inside another replacement, so it adds even more code characters and this only makes
sense if the string to be replaced inside the replacement is bigger than 18 characters. But this minimum is only necessary if the string occurs only twice. If it
occurs three times or more, a lower minimum would be possible. To find always the proper minimum has to be part of the algorithm.
The command line tool must be runnable on Windows XP, Windows Vista and Windows 7.
وجب أن يكون البرنامج أداة يمكن استخدامها عبر سطور الأوامر، وأن تطالب المستخدم ببيان اسم ملف الجافاسكريبت المعين فيضغط القيم ذات سلاسل الحروف فقط، حافظا الصيغة المضغوطة ملف مخرجات.
تبحث الخوارزمية عن أكبر أجزاء سلاسل الحروف التي تتكرر في الكود مرتين أو أكثر فتبدلها بمتغيرات. ثم تبحث عن الأجزاء الكبيرة الأخرى وهلم جرا. إن كان الجزء المتكرر أصغر من 13 حرفا أو كان أصغر من أن يكون إبداله ذا
فائدة وجب أن يظل غير مبدل. ذلك أن حجم الكود المحتاج إليه لإعداد الإبدال وتنفيذه وجب أن يراعى أيضا (علامة الجمع، علامتا الاقتباس، الفصلة المنقوطة، اسم متغير ذو حرفين)
من المهم أن يشتغل الكود المضغوط سليما سلامة الكود غير المضغوط. الهدف جعل حجم سلاسل الحروف أصغر ما أمكن. أما الكود نفسه فوجب ألا يضغط بحال.
انظر إلى المثال أعلاه، وليكن في بالك أنه يُظهر إبدالا داخل إبدال، وبذلك يزيد الكود حروفا، وهذا لا يكون له فائدة إلا أن تكون السلسلة المبدلة داخل الإبدال أكبر من 18 حرفا. غير أن هذا الحد الأدنى غير لازم إن وردت
السلسلة أكثر من مرتين. إن وردت ثلاث مرات أو أكثر أمكن حد هو أدنى من هذا. وإثبات الحد الأدنى المناسب جزء من واجبات الخوارزمية.
من المطلوب أن يمكن استخدام البرنامج على ويندوز إكس بي وفيستا و ويندوس 7.
|