Learn R Programming

cayleyR (version 0.1.0)

apply_operations: Apply Operation Sequence

Description

Applies a sequence of operations to a permutation state. Operations can be specified as "L"/"1" (shift left), "R"/"2" (shift right), or "X"/"3" (reverse first k elements).

Usage

apply_operations(state, operations, k)

Value

Integer vector representing the state after all operations

Arguments

state

Integer vector representing the initial permutation state

operations

Character vector of operations to apply sequentially

k

Integer, the parameter for reverse_prefix operations

Examples

Run this code
# Basic usage with numeric codes
apply_operations(1:5, c("1", "3"), k = 3)

# TopSpin puzzle example
start_state <- 1:20
operations <- c("1", "3", "2")  # Left, Reverse(4), Right
result <- apply_operations(start_state, operations, k = 4)
print(result)

# Using letter codes
apply_operations(1:5, c("L", "X", "R"), k = 3)

Run the code above in your browser using DataLab