Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.4 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6925e2068081f40f549ced1b Challenge 137: Snowflake Generator 29 challenge-137

--description--

Given a multi-line string that uses newline characters (\n) to represent a line break, return a new string where each line is mirrored horizontally and attached to the end of the original line.

  • Mirror a line by reversing all of its characters, including spaces.

For example, given "* \n *\n* ", which logs to the console as:

* 
 *
* 

Return "* *\n ** \n* *", which logs to the console as:

*  *
 ** 
*  *

Take careful note of the whitespaces in the given and returned strings. Be sure not to trim any of them.

--hints--

generate_snowflake("* \n *\n* ") should return "* *\n ** \n* *".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(generate_snowflake("* \\n *\\n* "), "*  *\\n ** \\n*  *")`)
}})

generate_snowflake("X=~") should return "X=~~=X".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(generate_snowflake("X=~"), "X=~~=X")`)
}})

generate_snowflake(" X \n v \nX--=\n ^ \n X ") should return " X X \n v v \nX--==--X\n ^ ^ \n X X ".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(generate_snowflake(" X  \\n  v \\nX--=\\n  ^ \\n X  "), " X    X \\n  v  v  \\nX--==--X\\n  ^  ^  \\n X    X ")`)
}})

generate_snowflake("* *\n * * \n* * *\n * * \n* *") should return "* ** *\n * * * * \n* * ** * *\n * * * * \n* ** *".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(generate_snowflake("*   *\\n * * \\n* * *\\n * * \\n*   *"), "*   **   *\\n * *  * * \\n* * ** * *\\n * *  * * \\n*   **   *")`)
}})

generate_snowflake("* -\n * -\n* -") should return "* -- *\n * -- * \n* -- *".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(generate_snowflake("*  -\\n * -\\n*  -"), "*  --  *\\n * -- * \\n*  --  *")`)
}})

--seed--

--seed-contents--

def generate_snowflake(crystals):

    return crystals

--solutions--

def generate_snowflake(crystals):
    lines = crystals.split("\n")
    mirrored = []

    for line in lines:
        reversed_line = line[::-1]
        mirrored.append(line + reversed_line)

    return "\n".join(mirrored)