fork(1) download
  1. function twoLines(a,b,c,d,t) {
  2. let l1o = b - a
  3. let l2o = d - c
  4. let r = 0
  5. for(let l1=1;l1<=l1o;l1++) {
  6. for(let i=0;i<=(l1o-l1);i++) {
  7. let a_ = a + i
  8. let b_ = a_ + l1
  9. let l2 = (l1o + l2o - l1)
  10. for(let c_ = Math.max(b_ + 1, c - (l2 - l2o)); c_<=c && c_+l2<=t;c_++) {
  11. let d_ = c_ + l2
  12. console.log(`${a_}--${b_} (${b_-a_}) ${c_}--${d_} (${d_ - c_})`)
  13. r++
  14. }
  15. }
  16. }
  17. return r
  18. }
  19. let r = twoLines(2,4,6,8,10)
  20. console.log(`${r} перестановок`)
Success #stdin #stdout 0.02s 16908KB
stdin
Standard input is empty
stdout
2--3 (1) 5--8 (3)
2--3 (1) 6--9 (3)
3--4 (1) 5--8 (3)
3--4 (1) 6--9 (3)
2--4 (2) 6--8 (2)
5 перестановок