{
  "id": 2781052,
  "title": "Weekly Challenge: Rearranging Atoms",
  "url": "https://urgent.news/2026/08/23/weekly-challenge-rearranging-atoms",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-23T11:32:50.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/simongreennet/rearranging-atoms-56c4"
  },
  "original_language": "en",
  "account": "Weekly Challenge 387 Each week Mohammad S. Anwar provides a coding challenge with two tasks. Participants can solve the tasks using any programming language, though Python solutions are shared first before converting them to Perl. The challenge encourages practicing coding skills without using AI tools.\n\nTask 1: Rearrange Binary String\nParticipants are given a binary string and must rearrange it by replacing all occurrences of \"01\" with \"10\" until no more \"01\" patterns remain. The task is to determine the total number of steps required to complete the rearrangement.\n\nThe Python solution starts by validating the input string to ensure it only contains \"0\" and \"1\" characters. A counter variable tracks the number of iterations needed. While \"01\" is present in the string, the loop increments the counter and replaces \"01\" with \"10\" using a regular expression substitution. Finally, the count of iterations is returned.\n\nIn Perl, the solution follows a similar logic. Input validation, iteration counter, and the loop for replacing \"01\" with \"10\" are implemented. The total count of replacements is displayed as the output.\n\nExample input-output:\n- 111000 produces 0 steps as no \"01\" patterns exist.\n- 00011 requires 4 steps to fully rearrange.\n- 01011 takes 3 steps to resolve.\n- 010101 also needs 3 iterations.\n- 00001 takes 4 steps to reach the solution.\n\nTask 2: Rational Numbers\nThe second task involves analyzing a chemical formula containing elements, numbers, and parentheses. Participants must expand any grouped multipliers, count the total number of atoms for each element, and format the final inventory as a string sorted alphabetically by element name. Only elements with a count greater than 1 are included in the output.\n\nA function called expand_parens is defined to handle the expansion of the innermost parentheses followed by a number. It multiplies the atom count for each element by the provided multiplier.\n\nIn the main atom_count function, the code expands all parentheses using a regular expression, ensuring the final string consists solely of alphanumeric characters. It then counts the occurrences of each element in the input string. If the input lacks proper formatting, such as mismatched parentheses or incorrect symbols, an error is raised.\n\nFinally, the atom count for each element is returned, sorted alphabetically in the resulting string. Elements with a count greater than 1 are included, while those with a count of 1 or less are omitted.",
  "summary": "Weekly Challenge 387 Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge , My solutions…",
  "key_points": [
    "Participants rearrange binary strings by replacing 01 with 10 until no more 01 patterns exist",
    "Python solution validates input, counts iterations, replaces 01 with 10 using regex",
    "Perl implementation mirrors Python logic with similar input validation and iteration counting"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}