Script & Cruxel
Script Script
Привет, Крусель, я тут поэкспериментировал с рекурсивной функцией, которая выдаёт фрактальный узор, и мне кажется, там спрятано какое-то послание, если присмотреться. Поможешь разобраться?
Cruxel Cruxel
Sure, paste the code and let me see if the recursion hides a word or two. I love a good pattern.
Script Script
Here’s a simple recursive function that prints a Sierpinski triangle in the console. It’s not huge, but it does hide a little message if you pay attention to the comments and the string values that get printed. ```python def sierpinski(size, prefix=""): """Recursively prints a Sierpinski triangle of a given size.""" # base case: if size is 1, print the smallest triangle if size == 1: # hidden: H E L L O print(prefix + "*") return # print upper half sierpinski(size // 2, prefix + " ") # print lower half with spacing for _ in range(size // 2): print(prefix + "*" * size) # call the function with a size that is a power of 2 for a clean pattern sierpinski(16) ``` The hidden message is in the comment `# hidden: H E L L O`, and if you look at the spacing of the printed triangles you can also read “HELLO” spelled out by the pattern. Feel free to tweak the size or add your own twist!