Jump to content

jodunno

Members
  • Posts

    259
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by jodunno

  1. That is excellent advice, requinix. Thank you for taking time to help a non-programmer. I always appreciate this forum and its members despite my agression at times. LOL. what i can say, i'm a bit of a weight lifting pesky wasp. I have made a text file with your advice and i will read more about this subject. I always make an effort to better myself so i promise that your advice is well taken. I am going to shutdown my xampp for the day and relax a bit. I am still trying to feel normal after covid and the flu. I started playing Grim Tales games (not spamming here but how else do i describe the games?) I can just sit back and click my way through a game. I hope that everyone has a great day and i cannot stress enough the importance of well being. Take care of yourselves. John
  2. Hi requinix and anyone else reading this post, The code that uses this expression is as follows working directories: C:\xampp C:\xampp\htdocs\qs.php <?php declare (strict_types = 1); //example request: http://localhost/qs.php?legal_copyright function checkGetRequest(string $queryString = '') { if (preg_match("/^[A-Za-z]{3,16}+_[A-Za-z]{3,48}$/", $queryString) === 0) { return false; } (array) $queryString = explode('_', $queryString); (string) $path = dirname(__FILE__) . '/../system/paging/'; if (!file_exists($path) || !file_exists($path . $queryString[0] . '/definition.php')) { return false; } require_once $path . $queryString[0] . '/definition.php'; if (!function_exists('definition')) { return false; } unset($path); if (definition($queryString[1]) !== true) { return false; } return (array) $queryString; } if (!empty($_SERVER['QUERY_STRING']) && is_string($_SERVER['QUERY_STRING']) && function_exists('checkGetRequest')) { (array) $showPage = checkGetRequest(trim(htmlspecialchars($_SERVER['QUERY_STRING']))); if ($showPage !== false && is_array($showPage)) { print_r($showPage); exit; } unset($showPage); } echo 'index page'; exit; ?> C:\xampp\system\paging\ (outside root) C:\xampp\system\paging\legal\definition.php (array of acceptable page requests) <?php declare (strict_types = 1); function definition(string $validity = '') { $pages = (array) ['agb','copyright','datenschutz','impressum','kontakt','uberuns']; if (in_array($validity, $pages, true)) { unset($pages); return true; } unset($pages); return false; } ?> category exists to allow hundreds of possibilities. a switch with more than 10 cases is ridiculous, so i 'switched' to a category and page system. I am aware of everyone's attitude about exit and error handling and cleanup work but i am not open to changing the code. I always clean up after myself in reality and i do the same in my code (unset). I like it that way. I also like to handle foreseen errors (a file doesn't exist or a call to an array loads a string instead. I try to handle known possible erros, which makes me happy. So besides my coding methods, if you spot anything that could be done better, then offer an opinion. Happy Holidays everyone and please stay healthy and warm. We are living in difficult times. John
  3. oh wow! I missed that entirely. I honestly did not realize that i had that flag. I copied a similar expression from my form validation and changed the core of the expression. I'm not trying to make an excuse for overlooking this stupidity but my brain is a little foggy lately. I had covid immediately followed by the flu a few weeks ago. I was not well and i am still trying to feel normal. I cannot believe how many times that i have looked at this code and did not notice the i Honestly, Thank You for cleaning this up for me. Meantime, i will post my experimental code so that you can see how it is used. I need to copy the code from my non-internet connected work laptop, then i will post it. I have tried the restrictions in everyway that i can imagine and the regex is working as expected. So once again, Thank you, requinix. I appreciate and value your expertise.
  4. Hi requinix, I was hoping that you would offer an opinion, since you are an actual regex specialist. I actually learned the basics of regex from your posts at this forum. I don't want to say that i credit you entirely because i am prone to erroneous regex logic at times and you are not responsible for the bad regex solutions of mine. Anyway, the links are a beautiful addition to your reply. Thank you for posting 🙂 well, our viewpoint is obviously different. I only use index.php and accept requests for content that fits my definition of acceptable content requests. Thus, the location/resource/route is the same. Only the content changes. So i don't consider it to be routing traffic, rather fetching different content for display in the same location. Routers typically involve mvc or classes, functions and frameworks. You know, call a class, which calls a class, which loads a function, which loads another function to echo a message instead of using the built-in echo function. LOL. Please let's not start a router definition, i should be using mvc argument. I actually like and respect you, requinix. I hope that you can reciprocate that sentiment 🙂 either way, if you must see my usage, then i don't mind posting my code but it would not be open to discussion 🙂 Happy Holidays and please stay healthy and warm, John
  5. Dear members, I'm building a get request file handler (sometimes erroneously referred to as a router) and i need to restrict the query string to a particular format using regex. goal: restrict a GET query string format to: category_page (id est, http://localhost/file.php?category_page) so Alphabetic letters of length 3 to 16 characters followed by an underscore followed by alphabetic letters of length 3 to 48 characters my current regex is contained within a "checkGetRequest()": if (preg_match("/^[A-Za-z]{3,16}+_[A-Za-z]{3,48}$/i", $queryString === 0) { return false; } is this regex correct? or perhaps someone can stop laughing and correct me? the regex seems to be working but i'm not a regex guru. Happy Holidays, John
  6. okay, i see. you are the big php gorilla in the room and you want to pound your chest when someone is out of place challenging you. i didn't expect this behaviour from you. You are always right. You are omniscient and i should bow down to you. Fine, i kow tow your excellency. You are so much smarter than me. I'm have no iq. I no nothing about programming. Only Barand knows. I will add to my notes: modulus is defined in php with an illogical % symbol (per centum, 100). modulus only exists because of php. So when you see a ≡ b (mod n) it was invented by php developers. gotcha. I will be sure to find my place in stuporville. I know nothing so i should not contribute to this forum. I should only ask questions from the Wizard of Oz but never look behind the curtain. I will stay away from this forum and let you pound your chest.
  7. "The modulo operator was invented for situations like this" it was invented? it was invented to handle division? it was invented to handle division by 5? I'm pretty sure that remainders are as old as division. The term is simply a word to refer to them and the concept is a way to work with them.
  8. hmm. I didn't think about modulus so it is a better example of reducing the code but your definition of it is not correct. Modulus is simply remainder and calculating using remainder (hence, ==0 means no remainder.) I learned that years ago when i encountered modulus in a Microsoft QBasic Gorilla game. I never heard of it before since my Math teachers only used the word remainder. Then again, I never had a proper algebra or calculus education. I had to teach myself (using teach yourself books). Good contribution, Barand.
  9. I have tried scaling before and it failed because browsers seem to keep the space of the original size. Thus multiple scaled items will not adjust to the new size in proportion with the page. I cannot remember exact details but it was horrible. I don't think any changes have been made to the rendering engines, so the problem should still remain.
  10. Hi Lumana, You could reduce the comparison branching to a single comparison with a count . <?php $Count = 5; for ($j = 1; $j < 101; $j++) { if ($j == $Count) { echo $j . ' Boogie Woogies' . '<br>'; $Count += 5; continue; } echo $j . '<br>'; } ?>
  11. yes it is 12. i made an erroneous mental calculation and i saw it after i posted.. i didn't want to log back in to correct it. ixiiv is still nonstandard and i intend to filter it out. I'm working on the code...
  12. update: so i used my decimal to roman numeral code inside of a loop in my roman to decimal code. All of the numbers passed, which means my code is not filtering standard roman numerals. Super! i changed an entry in the loop to a numeral that should be considered non standard and my code stopped the loop and displayed the invalid message. so the code is working. Then i used the decimal to roman code to produce an array of all of the standard roman numerals, then i used the var_export to create a copy of this good numerals array. I made a copy of the array produced in the roman to decimal converter that passed through the filtering process. I made a new php file named compare.php. I pasted both arrays into compare.php, then i created a loop that compares the values. If any value is different, then show the different value via echo. Continue the loop until it is finished. The result is a blank page, which confirms that good numerals are not filtered. Yippee! However, i did notice that a nonstandard numeral still passes through my filter: xxxliiv. Now i permit nonstandard subtraction of numerals up to five, so iiv is okay. xxxl has not been handled. I have no filter for higher numeral subtractions. I think that i could make a rule that two non-standard subtractions should not occur in the same processed number. I am not yet sure if that idea works or not. But i can say that artificial intelligence could help me here. Imagine including my decimal to roman code inside of the same file as the roman to decimal code. I could calculate a good numeral based upon the total of the submitted numeral. Then compare the code and if the submitted code is different, then i will know that you are adding or subtracting to reach the nonstandard form of the decimal. Then i could check, i guess, powers of ten? 54 should have a fifty or L. Otherwise, you did something to reach 50 which is non standard. Thus, ixiiv should fail because the total is 14 which is between 10 and 20, yet the equation does not have a X (10). You did something strange to reach the number. If i can add such code to my current code, then i should have a splendid converter.
  13. interesting. I can't believe that my code is even remotely similar to yours. I am not a very good programmer so it is nice to know that i did something correctly. I suppose that i am a bit too hard on myself. Really though, i am still trying to comprehend how i wrote code that is similar to your code. You are a pro and i am just a programmatic idiot trying to make a website. I guess i am slowly learning how to think programmatically. So progress is good 😀 but i don't let it go to my head. I got lucky this time and did something right. I am going to get some coffee and get to work on my roman to decimal converter.
  14. Hi Barand, I created a script for decimal to roman last week. I am certain that my approach is different than yours but i get the job done. I added a loop so that my code prints numerals 1-3999. Decimal to Roman is easy if we only convert to standard Roman numerals. Converting from unknown possibly nonstandard possibly invalid roman numerals to decimal is a bit more difficult. I suppose that one could make a 3999 roman numeral valued array and call it a day but i like to try to solve the problems programmatically. If failure happens and i can't find a way to filter correctly then the 3999 value array is my only hope. Here is my Decimal to Roman converter using basic arithmetic of places. Everyone, take your places! 😃 <?php //John's PHP Decimal number to Roman Numeral converter v1 $Ones = array('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'); $Tens = array('X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'); $Hundreds = array('C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'); $Thousands = array('M', 'MM', 'MMM'); for ($j = 1; $j < 4000; $j++) { $PlaceCount = strval(strlen($j)); $Places = str_split($j); $RomanNumeral = null; switch ($PlaceCount) { case '1': $RomanNumeral = $Ones[$j - 1]; break; case '2': $RomanNumeral .= $Tens[$Places[0] - 1]; if (!empty($Places[1])) { $RomanNumeral .= $Ones[$Places[1] - 1]; } break; case '3': $RomanNumeral .= $Hundreds[$Places[0] - 1]; if (!empty($Places[1])) { $RomanNumeral .= $Tens[$Places[1] - 1]; } if (!empty($Places[2])) { $RomanNumeral .= $Ones[$Places[2] - 1]; } break; case '4': $RomanNumeral .= $Thousands[$Places[0] - 1]; if (!empty($Places[1])) { $RomanNumeral .= $Hundreds[$Places[1] - 1]; } if (!empty($Places[2])) { $RomanNumeral .= $Tens[$Places[2] - 1]; } if (!empty($Places[3])) { $RomanNumeral .= $Ones[$Places[3] - 1]; } break; } echo $RomanNumeral . '<br>'; } ?>
  15. Hi Barand, Thank you for the lovely gift 🙂 I will finish testing today. I have a physical therapy session in the afternoon. Hopefully, i can put it all together after my appointment. I think that the program is working as expected but time will tell. Best wishes, John
  16. Hi gw1500se, i don't know how to define the scholarly subtraction but it certainly isn't invalid. Some mathematicians (which noone has ever heard of) suddenly hold themselves higher than, say Carl von Linne, and deem MDVC as an invalid numeral. However, some of the world's smartest people have published books with these 'invalid' numerals. I want to convert these numerals that you may see in old books and not show a message that it is invalid. I have only seen numbers I-5 used in irregular subtraction dates: mdvc, mdic etc. I've not seen MDVIIC or MDVIXC. I want to limit irregular subtractions to five while ignoring any other subtractions until later in the code. I like the limit and i want the limit. I have the limit. Filter number 2 handles these lower numbers used in irregular subtractions: //2. subtraction less than 5 should be valid in this converter $validSubtraction = array('IV', 'III', 'II', 'I', 'V'); foreach ($validSubtraction as $m) { foreach ($FollowedBy as $n) { $pos = stripos($RomanNumeralInput, $m . $n); if ($pos !== false) { // if ($m === $n) { $invalid = 1; $invalidRule = 20; break(2); } if ($pos > 0 && $RomanNumeralInput[$pos-1] === 'I') { $invalid = 1; $invalidRule = 21; break(2); } if ($pos > 0 && $RomanDecimal[$RomanNumeralInput[$pos-1]] < $RomanDecimal[$n]) { $invalid = 1; $invalidRule = 22; break(2); } $subtraction = 1; $subtractionCount = strlen($m . $n); $subtractionIsolated = $m . $n; $calculateSubtraction = $RomanDecimal[$n] - $RomanDecimal[$m]; if ($pos + $subtractionCount < strlen($RomanNumeralInput)) { if ($calculateSubtraction > $RomanDecimal[$RomanNumeralInput[$pos + $subtractionCount]]) { $invalid = 1; $invalidRule = 23; break(2); } } $RomanNumeralInput = str_replace($m.$n, '', $RomanNumeralInput); break(2); } } } if ($invalid) { echo ' is a nonstandard Roman Numeral (Rule number: ' . $invalidRule . ')'; exit; } This code works. Later, i handle all other subtractions like everyone else. loop through the array holding the submitted numeral. Then simply use an if statement. If current numeral less than next numeral, then subtractive. I have tried my code on numbers 1-100, 200, 300, 400, 500, 1000, 3999, MDVC etc. I have no problems yet. MDCM is handled normally in my code. I will finish the code tomorrow, then loop through 1-3999 and see how it goes. Then i will try various irregular combinations and see how the code holds up. I'll post reults. Maybe someone can help clean up and tighten my code. Best wishes, John
  17. ixx really shouldn't be calculated and my code skips it. I prefer it be skipped. Furthermore, i notice other numerals that should be ignored according to research and comparison with printed material: vv,vvv,vvvv, ll,lll,llll, dd,ddd,dddd. 2021 really should not be processed as dddixxii. I also noticed that old books use the letter j for a final i in a series of this numeral: ij, iij, vij, viij. I've added this snippet of code to my program to permit the usage of the letter j: $RomanNumeralInput = str_replace('J', 'I', $RomanNumeralInput); I added the following code at the end of my script (after Isolation so that subtractive numbers are not factored) to block repeated characters above four times (three is the standard but i've seen iiii and cccc in published material): //3. check for numerals repeated greater than four times and exclude L,D foreach (count_chars($RomanNumeralInput, 1) as $i => $val( { if ($val > 4) { $invalid = 1; $invalidRule = 30; break; } if ($val > 1 && $val <= 4 && chr($i) === 'L' || chr($i) === 'D') { $invalid = 1; $invalidRule = 31; break; } } // show error message and rule violation which helps during development process. if ($invalid) { echo $RomanNumeralInput . ' is a nonstandard Roman Numeral. (Rule number: ') . $invalidRule . ')'; exit; } I really just wanted a date converter that accepts subtractions up to V (MDVC) and permits repeated numerals up to four times (IIII, CCCC). I also wanted to block irregular and nonstandard numerals. One can argue that VC is non standard but it is published in old books. Thus, i aim to create a converter that will help users convert the numerals that they may see in old books. I am getting closer to completing my code. Adding J is also something that i want to support. I am going to add the conversion soon, then see how it handles conversions from 1-to-3999 along with subtractions. Your code is clean and efficient for sure. I need to learn how to be a better coder. I am just adamant about sticking to my design. I don't want to process ixx, viiiviii, vvvv, ixi, etc. Best wishes, John
  18. Hi Barand, I got my program to do all of the tings that i want it to do. I just have to finish the code by producing a decimal/arabic number and verify that all of the numbers are correct. I have learned something about Roman numerals today that i find interesting. I do not rmember hearing about this problem before. I have given this problem a name: "The Nine Hole". Your code also falls into the "Nine Hole". What am i talking about? how do you know that ixx is 19 and not 1? ixx is 10-9 or 20-1, depending on how you see it. My code jumps over the Nine Hole with a code block on the ix as an invalid subtraction followed by ten. Your code calculates 19. I never thought about this problem before. I didn't realize that such a problem exists. Do you see it? ix, iix, iiix, ivx, vx, vix, viix, viiix, ixx (also 20-1). I have decided to keep my "jumping over the Nine Hole code", which i will also explain on my website. Meantime, i am satisfied with my code for now. I will try to wrap it up later or tomorrow. Then i will test it with numbers 1-3999. Then i will test it with odd and irregular numerals. If everything works as expected , then i am finished wih this nightmare of a project. And i will have a converter which accepts subtractive numbers up to five. Best wishes, John
  19. Hi Barand, I am not making a calculator. I will try to better explain my project. I am simply trying to create my own date converter (roman numerals to arabic/decimal numbers) allowing common date subtractive numerals but restricting subtractives to five. Again, I forgot how roman numerals work except for basic numers. I had to look up D (500) for example. I often have to calculate the dates in books for my literary references of biographical notices. An example citation for Ulisse Aldrovandi (Ulysses Aldrovandi): Bonucci, Anicio . Plauso Letterario per la Restaurazione della Sala Urbana ed Inaugurazione dell'aula Piana nel Palazzo Apostolico di Bologna . Artikel: Elogio di Ulisse Aldrovandi . Seiten 68-73 . Bologna (Italien) 1852 (M DCCC LII) I often have to mentally convert the dates because they are only published in Roman numerals. I started using online converters to spare me from having to calculate. But none of the online converters that i found allow subtractive numbers. I found an old book from 1595 and the published date was in Roman Numerals as MDVC. I couldn't find an online converter that accepts this format. Again, i've seen subtractive numbers in books but they seem to stop at 5. I've not seen viic, so it appears to me that old scholars accepted subtractive dates with a limit of five. I want to permit these subtractions but stick to conventional numerals for all other dates. Thus viiiviii is not conventional and i'd like to ignore it. I further tweaked my code and it is now blocking the following numerals: xicx, ixcx, iiilxv, viiiviii. So my code seems like it is working now. My code accepts MDVC but not MDVIIC. I am happy. It is actually working. Meantime, i hope that i can list links here. I am certainly not spamming, endorsing or advertising. If the following links are deemed inappropriate then have a mod delete them and i am sorry. So these are the sites that i was using for quick date conversions (none of the sites accept mdvc, which is annoying): www.romannumerals.org/converter www.calculatorsoup.com/calculators/conversions/roman-numeral-converter.php www.rapidtables.com/convert/number/roman-numerals-converter.html I thought that it will be nice to make my own converter for my website but tweak it to accept common subtractive numerals in dates. Like mdvc. By the way, i cant visit the rapidtables site anymore unless i use kmeleon browser. LOL. i got mad at youtube for the ad bombardments that i get lately. I decided to remove my adblocker ublock origin and go for the kill. I installed tinywall open source browser, installed fiddler, and editied the fiddler HOSTS list since Microsoft erases any changes that i make to my system HOSTS file. I am also sick of MS updates interrupting me. I blocked Windows Updates, Mozilla communications, telemetry and ad sites/uris. I blocked youtube ads and popups. Which reminds me, i also enabled custom css in Firefox to remove annoying css cookie overlays since websites are trying to detect ublock and nag me about it. I went back to private filtering (fiddler, custom css and firewall). Now cloudflare tries to deem my system as a security threat. I should sue them because they are the threat. I don't have to set up my system for ads, tracking and espionage or be labelled a security threat. I'm mad. These tech companies go too far. Anyway, now my stsem is tight and rapidtables is not functioning (fiddler shows why). Thus lately, i've been using calculatorsoup instead. While waiting for my own converter to be fully operational.
  20. yes i see how it reaches ten but viiiviii is getting too far away from my goal. I suppose that i am trying to create a copyright year converter and not an addition and subtraction calculator. Which is why i say that viiiviii is not valid. Remember that my site is biology/nature related. I've added biographical notices (place of birth/death, profession etc.) I list books as references. Alot of books are very old (1400s, 1500s, 1600s, 1700s and 1800s). Alot of copyright dates are roman numerals and they do not contain non standard forms, such as vvvv for 20. My goal was emulate online calculators with a common subtractive exception. I added a loop to my code that checks the numbers in a reversed array, thus allowing me to query if current number is less than next number then invalid. VIIIVIII gets blocked in this code. I can further retsrain repetition by only permitting certain numbers to be repeated and only 3 times. Example, CCC and III but CCCC and IIII will be blocked. I'm getting a better grip now the picture is getting clearer.
  21. I was thinking about this whole problem and all of my coding attempts. I wondered how my code would handle repetition, so i tied it and my code failed to detect it. So i tried it using your script and your script also accepts it but oddly calculates the amount. I tried VIIIVIII. Your script outputs 10. I would think it should be 16 but technically an invalid number. This is so complicated.
  22. so i take that to mean a fee of my choosing? How about a pint 😁 just kidding. Although, as legal notice, posting the code in public is not a consent to usage of said code. Afterall, you are the copyright holder. I can post a copyright photo here but it does not grant legal rights to use it. Too many people use other peoples work illegally. I am not one of those people. I can analyze your logic and work it into mine but certainly not in part or in whole. I forgot to say Thank you for all of your time and hard work. In fact, Thank you to everyone posting in this thread. I appreciate you and this community. Best wishes, John
  23. well your code is very nice and seriously professional. The only negative aspect to your code is the calculation of non stadard numerals but noone should really care. However, it is your code not mine. I can't legally use someone elses code in a commercial application. Remember that my website is commercial. I'm not a thief, Sir. :-) I respect you and your intellectual property.
  24. Hi Barand, my new code post was the first attempt at isolation. The script is unfinished in the post. However, i just added the missing factors. My latest script appears to work as expected but i haven't tested every number combo. I got started on this because i actually saw an old book with MDVC and i didn't know how to calculate that. I was introduced to subtractive roman numerals at that point. I couldn't even remeber what D was (now i know it is 500). I don't use Latin numbers. Anyway, my first thought was to use an online converter for the MDVC but they all rejected this number as invalid. I yelled at the screen "BUT I SEE IT IN AN OLD BOOK'. LOL. I decided that i want to add a roman numeral converter to my site that allows subtractive Roman numerals. However, i have not seen subtractive numbers greater than 5 and really it doesn't make sense to write VIIX instead of III. I can understand MDVC but not MDIXC because it would be easier to write MDCI. I wanted to control the subtraction to five. Anyway, here is my latest code which also checks for my so-called valid subtraction and adds it to the final array. It seems to be working... <?php //limit 3999 or MMMCMXCIX $RomanNumeralInput = strtoupper('xiix'); //XICX ixcx MDIIC $RomanDecimal = array('I' => 1, 'IV' => 4, 'V' => 5, 'IX' => 9, 'X' => 10, 'XL' => 40, 'L' => 50, 'XC' => 90, 'C' => 100, 'CD' => 400, 'D' => 500, 'CM' => 900, 'M' => 1000); $invalid = $subtraction = $subtractionCount = $subtractionIsolated = $append = 0; echo $RomanNumeralInput . '<br>'; $Subtractive = array('IX', 'VIII', 'VII', 'VI'); $FollowedBy = array('X', 'L', 'C', 'D', 'M'); foreach ($Subtractive as $n) { foreach ($FollowedBy as $m) { $pos = strpos($RomanNumeralInput, $n . $m); if ($pos !== false) { $invalid = 1; break(2); } } } if ($invalid) { echo ' is a nonstandard Roman Numeral'; exit; } $validSubtraction = array('IV', 'III', 'II', 'I', 'V'); foreach ($validSubtraction as $m) { foreach ($FollowedBy as $n) { $pos = stripos($RomanNumeralInput, $m . $n); if ($pos !== false && $m . $n !== 'IX') { $subtraction = 1; $subtractionCount = strlen($m . $n); $subtractionIsolated = $m . $n; $RomanNumeralInput = str_replace($m.$n, '', $RomanNumeralInput); break(2); } } } $Isolation = array(); if (!empty($RomanNumeralInput)) { $RomanNumeral = str_split($RomanNumeralInput); $PlaceCount = count($RomanNumeral); if ($pos >= $PlaceCount) { $append = 1; unset($pos); } $count = 1; $stringcount = 0; $skip = 0; foreach ($RomanNumeral as $i) { if (isset($pos) && $stringcount === $pos) { array_push($Isolation, $subtractionIsolated); unset($pos); } if ($skip) { $skip = 0; $count++; $stringcount++; continue; } if ($count < $PlaceCount) { if ($RomanDecimal[$i] < $RomanDecimal[$RomanNumeral[$count]]) { array_push($Isolation, $i . $RomanNumeral[$count]); $count++; $stringcount++; $skip = 1; continue; } array_push($Isolation, $i); $count++; } else { array_push($Isolation, $i); } $stringcount++; } if ($append) { array_push($Isolation, $subtractionIsolated); } } else { array_push($Isolation, $subtractionIsolated); } echo '<br>'; print_r($Isolation); ?> the XICX is still irritating me. Which is why i keep trying to exclude it. It really is a strange non standard roman numeral. It annoys me like a mosquito. even ixcx but my latest script denies ixcx.
  25. Good morning, I have been thinking endlessly about this problem. I started to realize that one roadblock to understanding a roman numeral is a lack of isolation. I have no idea if a subtractive number exists or not. Thus, i was thinking that if we can separate paired numbers (VII or IX) versus singular numbers (X, M, C etc) then we will have a way to know what we are dealing with. Yet, i don't think that we need to isolate additive pairs (VI, VII etc.) because they will correctly be handled via addition from isolation. Thus, i have tried a quick script for subtractive isolation and used my previous code to detect a non standard subtraction. I need an opinion about this method. Do you think that it is a good idea? could this help us solve the problem? here is my new code which isolates numbers excluding non standard subtraction. Tell me what you think, please. <?php //limit 3999 or MMMCMXCIX $RomanNumeralInput = strtoupper('MMMCMXCIX'); //XICX ixcx $RomanDecimal = array('I' => 1, 'IV' => 4, 'V' => 5, 'IX' => 9, 'X' => 10, 'XL' => 40, 'L' => 50, 'XC' => 90, 'C' => 100, 'CD' => 400, 'D' => 500, 'CM' => 900, 'M' => 1000); $invalid = 0; $Subtractive = array('IX', 'VIII', 'VII', 'VI'); $FollowedBy = array('X', 'L', 'C', 'D', 'M'); foreach ($Subtractive as $n) { foreach ($FollowedBy as $m) { $pos = strpos($RomanNumeralInput, $n . $m); if ($pos !== false) { $invalid = 1; break(2); } } } if ($invalid) { echo $RomanNumeralInput . ' is a nonstandard Roman Numeral'; exit; } $RomanNumeral = str_split($RomanNumeralInput); $Isolation = array(); $PlaceCount = count($RomanNumeral); $count = 1; $skip = 0; foreach ($RomanNumeral as $i) { if ($skip) { $skip = 0; $count++; continue; } if ($count < $PlaceCount) { if ($RomanDecimal[$i] < $RomanDecimal[$RomanNumeral[$count]]) { array_push($Isolation, $i . $RomanNumeral[$count]); $count++; $skip = 1; continue; } array_push($Isolation, $i); $count++; } else { array_push($Isolation, $i); } } print_r($Isolation); ?> so now that numbers are isolated, we could have a better shot at analyzing the number for non standard input. right? Best wishes, John
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.