Range of Numbers $x-y

By Naemuti on Jan 07, 2007

This is a simple custom identifier where you enter two numbers and the asc value of a character to seperate them with and it gives you a list of numbers between the first two, sperated by the character you specify.

Example: //echo -a $x-y(4,20,32) returns 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

//echo -a $x-y(-1,10,46) returns -1.0.1.2.3.4.5.6.7.8.9.10

//echo -a $x-y(10,-4,46) returns 10.9.8.7.6.5.4.3.2.1.0.-1.-2.-3.4.

x-y {
  if ($1-3 isnum) {
    if ($1 <= $2) {
      var %r = $1
      while (%r <= $2) {
        var %x = $addtok(%x,%r,$3)
        inc %r
      }
    }
    elseif ($1 > $2) {
      var %r = $1
      while (%r >= $2) {
        var %x = $addtok(%x,%r,$3)
        dec %r
      }
    }
  }
  return %x
}

Comments

Sign in to comment.
RubixCube   -  Sep 30, 2007

Updated your code:


alias x-y {
  if ($1 <= $2) {
    var %r = $1
    while (%r <= $2) {
      var %x = $addtok(%x,%r,$3)
      inc %r
    }
  }
  elseif ($1 > $2) {
    var %r = $1
    while (%r >= $2) {
      var %x = $addtok(%x,%r,$3)
      dec %r
    }
  } 
  return %x
}
 Respond  
Scakk   -  Sep 30, 2007

Works now. Thanks Lindrian.

 Respond  
Lindrian   -  Sep 30, 2007

Remove if ($1-3 isnum) { and it works fine.

 Respond  
Scakk   -  Sep 30, 2007

This is not working for me

//echo -a $x-y(3,15,32) -> /echo: insufficient parameters
//echo -a $x-y(3,4,32) -->
/echo: insufficient parameters
//echo -a $x-y(13,4,46) -> * /echo: insufficient parameters

I tried several more times with the same out come.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.