Skip to main content
deleted 34 characters in body
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = 3 Length@x}, {x[[1,- 1]]2},  {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@   Rescale[Range[(s - 1) 3 + 1]Rescale[Range@s, {1, (s - 1) 3 + 1}, {1, sLength@x}]]   f[l_]g[x := Flatten[(Replace[#,{{__}}] x_:> g@x /; Length@x= >x f[l_] 1,:= {0}])Flatten[g &/@  SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l]f@l  (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = Length@x}, {x[[1, 1]],  Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@   Rescale[Range[(s - 1) 3 + 1], {1, (s - 1) 3 + 1}, {1, s}]]   f[l_] := Flatten[(Replace[#, x_:> g@x /; Length@x > 1, {0}]) &/@  SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l] (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = 3 Length@x - 2}, {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@ Rescale[Range@s, {1, s}, {1, Length@x}]] g[x : {{__}}] := x f[l_] := Flatten[g /@ SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f@l  (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
deleted 1 character in body
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = Length@x}, {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@ Rescale[Range[(s - 1) 3 + 1], {1, (s - 1) 3 + 1}, {1, s}]] f[l_] := Flatten[(Replace[#, x_:> g@x /; Length@x >=> 21, {0}]) &/@ SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l] (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = Length@x}, {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@ Rescale[Range[(s - 1) 3 + 1], {1, (s - 1) 3 + 1}, {1, s}]] f[l_] := Flatten[(Replace[#, x_:> g@x /; Length@x >= 2, {0}]) &/@ SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l] (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = Length@x}, {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@ Rescale[Range[(s - 1) 3 + 1], {1, (s - 1) 3 + 1}, {1, s}]] f[l_] := Flatten[(Replace[#, x_:> g@x /; Length@x > 1, {0}]) &/@ SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l] (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
added 633 characters in body
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = Length@x}, {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@ Rescale[Range[(s - 1) 3 + 1], {1, (s - 1) 3 + 1}, {1, s}]] f[l_] := Flatten[(Replace[#, x_:> g@x /; Length@x >= 2, {0}]) &/@ SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l] (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 
{{4, 5}, {1, 2}, {1, 5}, {3, 5}} /. {a : ___, b : PatternSequence[{x_, j_}, {x_, k_}], c : ___} :> {a, Sequence @@ Table[{x, j + n (k - j)/3}, {n, 0, 3}], c} (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {3, 5}} *) 

Edit

For supporting multiple adjacent values you may do the much more convoluted:

g[x_] := Module[{s = Length@x}, {x[[1, 1]], Interpolation[x[[All, 2]], InterpolationOrder -> 1][#]} & /@ Rescale[Range[(s - 1) 3 + 1], {1, (s - 1) 3 + 1}, {1, s}]] f[l_] := Flatten[(Replace[#, x_:> g@x /; Length@x >= 2, {0}]) &/@ SplitBy[l, First], 1] l = {{4, 5}, {1, 2}, {1, 5}, {1, 8}, {3, 5}, {3, 7}}; f[l] (* {{4, 5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {3, 5}, {3, 17/3}, {3, 19/3}, {3, 7}} *) 
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466
Loading