(25C) 1D Rubik's Cube
|
04-21-2017, 11:45 PM
(This post was last modified: 04-26-2017 04:53 AM by nsg.)
Post: #1
|
|||
|
|||
(25C) 1D Rubik's Cube
This is an implementation of one-dimensional equivalent of Rubiks cube.
The string of 8 digits (colors) can has to be manipulated to produce an initial position. Move consists of the following: any 4 consecutive characters in the string turn 180 degrees in their place (4-substring reverses its order). For example 12345678 may be transformed into 1(2345)678 --> 1(5432)678 = 15432678 by reversing substring of length 4 starting from second character. If the input is some permutation of digits 12345678, then only even permutations can be completely sorted. Here are several challenges: 1. Warm up challenge. 12121212 STO 0 turn into 11112222 12341234 STO 0 turn into 11223344 2. Standard mode. a) 62783541 b) 87236451 c) 51382764 d) 53847261 e) 64381257 Select one of the initial permutaions a)-e). Save it to R0 Sort all digits to get 12345678 3. Extra credit. Extra challenging variant of the puzzle reverses substrings of length 6, rather than 4. This variant allows to sort all permutations, even and odd. To implement this variant modify lines 06 and 23 in the program (they are marked "variant" in the listing). change "06. 6" to "06. 4" and "23. 4" to "23. 6". Convert 87654321 to 12345678 (there are only 3 substrings of length 6, so at each moment only move 1,2 or 3 are acceptable) Code:
Initial setting: f PRGM FIX 0 10 STO 1 <starting combination of exactly 8 non-zero digits> STO 0 For example: 12121212 STO 0 To make a move: <n> R/S n=1..5, position of the first character of substring to reverse Output: updated position. For example: 3 R/S --> 12212112 Repeat moves until you achieve final position. |
|||
04-22-2017, 12:06 AM
Post: #2
|
|||
|
|||
RE: (25C) 1D Rubik's Cube
(ctd)
This is my first attempt at programming hp 25c (actually it was np 25, but I hope it still applies). My impression on the experience: I really like the language. int/frac, storage arithmetic, compares of x to y (rather than just to 0) were very useful and allowed to save a lot of steps. But! 49 steps is too damn little. To achieve my goal I had to manage (and downgrade) expectations several times. For example, initially, I wanted to implement different game, but then I realized that I am not even close to be able to fit it in 49 steps, so had to settle for this. Then, originally, I wanted start with initial random permutation (by applying several random moves to 12345678). That also proved to be too much to ask, so now user has to enter initial permutation himself and also check for completion. There was a nasty surprise: 10^x returns 99999999.60 on 8, 9999999.99 on 7 and 1000000003 on 9, which almost made me retarget the program to HP-33C mode -- there 10^x works as expected. I ended up rounding the result with Code:
and downgraded from 9 digit input (as I originally planned) to 8 digit input, so I do not have to calculate 10^9. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)