Learn R Programming

cayleyR (version 0.1.0)

reverse_prefix: Reverse Prefix

Description

Reverses the first k elements of the state vector, analogous to the turnstile operation in the TopSpin puzzle.

Usage

reverse_prefix(state, k)

Value

Integer vector with the first k elements reversed

Arguments

state

Integer vector representing the current permutation state

k

Integer, the number of leading elements to reverse

Examples

Run this code
# Basic example
reverse_prefix(1:10, 4)  # Returns c(4, 3, 2, 1, 5, 6, 7, 8, 9, 10)

# With variables
n <- 10
k <- 4
start_state <- 1:n
demo <- reverse_prefix(start_state, k)
print(demo)

Run the code above in your browser using DataLab