#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1274
Task: \boxed{}

</think>

Write a Python function that transforms a given string into a "zigzag" pattern based on a specified number of rows, then reads the characters row by row to form the transformed str
Generated: 2026-02-13T02:34:47.029465
"""

def zigzag_conversion(s: str, rows: int) -> str:
    if rows == 1 or rows >= len(s):
        return s

    # Create a list of strings for each row
    zigzag = [''] * rows
    current_row = 0
    going_down = False

    for char in s:
        zigzag[current_row] += char
        # Change direction when we reach the top or bottom row
        if current_row == 0 or current_row == rows - 1:
            going_down = not going_down
        # Move up or down
        current_row += 1 if going_down else -1

    # Join all rows to form the final string
    return ''.join(zigzag)

if __name__ == '__main__':
    test_string = "PAYPALISHIRING"
    test_rows = 3
    result = zigzag_conversion(test_string, test_rows)
    print(result)