Two interwoven chains

9

In this question I defined a "chain" function as a function that:

  • is a permutation, meaning that every value maps to and is mapped to by exactly one value.

  • and allows any value can be obtained from any other value by repeated applications of the function or its inverse.

There are a lot of functions that do this and some of them are pretty simple (see the answers on that question). Now we are going to define a separate class of functions I am going to call "interwoven" functions. An interwoven function is a function on a set A, that has two infinite partitions a0 and a1 such that the function is a chain function on both a0 and a1.

This means that no value in a0 can map to a value in a1 under the function or vice versa.

Task

Your task is to write a code that performs or defines an interwoven function on the positive integers. Your function can be anything as long as it satisfies the criteria for being interwoven. You should include a explanation as to why your function is interwoven in the answer.

This is a question so answers will be scored in bytes, with less bytes being better.

Post Rock Garf Hunter

Posted 2017-08-08T20:58:26.943

Reputation: 55 382

@flawr Thanks! I was looking for that word but I couldn't think of it. – Post Rock Garf Hunter – 2017-08-08T21:14:00.877

I think this could be considered a dupe of the last challenge you linked, as you just have to make an additional transfromation, i.e. enumerating all the even and all the odd numbers seperately. I don't think any of the answers you're getting here will provide anything substantially new. – flawr – 2017-08-08T21:17:09.857

@flawr You could do that, but it wouldn't be the best way. I've done a little experimentation with this and there are some novel ways to perform these types of functions. – Post Rock Garf Hunter – 2017-08-08T21:19:03.693

Answers

2

Python, 46 42 37 bytes

5 bytes saved thanks to @notjagan

lambda x:1<x<4and x*2%5or x-(x&2)*4+4

Try it online!

Iterates the even and odd numbers with steps of 4 and links on 2 and 3:

=> 22 => 18 => 14 => 10 => 6 => 2 => 4 => 8 => 12 => 16 => 20 => 24 =>
=> 23 => 19 => 15 => 11 => 7 => 3 => 1 => 5 => 9 => 13 => 17 => 21 =>

Uriel

Posted 2017-08-08T20:58:26.943

Reputation: 11 708

1

JavaScript, 30 24 bytes

a=>(a+=a&2?-4:4)<0?a*a:a

Sequences:

  1. ... 19 15 11 7 3 1 5 9 13 17 21 ...
  2. ... 18 14 10 6 2 4 8 12 16 20 24 ...

Code snippet

f=a=>(a+=a&2?-4:4)<0?a*a:a
console.log('23 19 15 11 7 3 1 5 9 13 17'.split` `.map(a=>f(a|0)).join` `);
console.log('22 18 14 10 6 2 4 8 12 16 20'.split` `.map(a=>f(a|0)).join` `);

user72349

Posted 2017-08-08T20:58:26.943

Reputation:

0

Dyalog APL, 24 22 bytes

{x*1+0>x←4+⍵-8×2|⌊⍵÷2}

Try it online!

Same chains as my python answer.

Uriel

Posted 2017-08-08T20:58:26.943

Reputation: 11 708