Skip to main content
137
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70

R, 152 138137 bytes

-12 bytes thanks to Giuseppe -23 bytes thanks to digEmAll

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=revr=?rev((T=T+1)%/%(e=10^(0:log10(T)))%%10)%*%e*e)%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers

R, 152 138 bytes

-12 bytes thanks to Giuseppe -2 bytes thanks to digEmAll

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=rev((T=T+1)%/%(e=10^(0:log10(T)))%%10)%*%e)%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers

R, 152 137 bytes

-12 bytes thanks to Giuseppe -3 bytes thanks to digEmAll

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=?rev((T=T+1)%/%(e=10^(0:log10(T)))%%10)*e)%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers
138 bytes
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70

R, 152 142138 bytes

-1012 bytes thanks to Giuseppe -2 bytes thanks to digEmAll

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=r=rev((T=T+1)%/%10^%(e=10^(0:(b=ncharlog10(T)-1))%%10%*%10^(b:0%%10)%*%e)%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

I know that digEmAll has a 147 byte solution; waiting to see it!

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers

R, 152 142 bytes

-10 bytes thanks to Giuseppe

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=(T=T+1)%/%10^(0:(b=nchar(T)-1))%%10%*%10^(b:0))%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

I know that digEmAll has a 147 byte solution; waiting to see it!

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers

R, 152 138 bytes

-12 bytes thanks to Giuseppe -2 bytes thanks to digEmAll

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=rev((T=T+1)%/%(e=10^(0:log10(T)))%%10)%*%e)%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers
142 bytes
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70

R, 152 146142 bytes

-610 bytes thanks to Giuseppe.

n=scan()
F=i=!1:2
S=sum`?`=sum
while(S(?n>i))if(Sn==?(i[s]<-i[s<i[s]=i[s<-sign(S(?!(r=(T<-T+1T=T+1)%/%10^(0:(b=nchar(T)-1))%%10%*%10^(b:0))%%1:r)-S(?!T%%1:T))]+1)<=n)F[s]=T
F

Try it online!Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

I know that digEmAll has a 147 byte solution; waiting to see it!

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers

R, 152 146 bytes

-6 bytes thanks to Giuseppe.

n=scan()
F=i=!1:2
S=sum
while(S(n>i))if(S(i[s]<-i[s<-sign(S(!(r=(T<-T+1)%/%10^(0:(b=nchar(T)-1))%%10%*%10^(b:0))%%1:r)-S(!T%%1:T))]+1)<=n)F[s]=T
F

Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

I know that digEmAll has a 147 byte solution; waiting to see it!

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers

R, 152 142 bytes

-10 bytes thanks to Giuseppe

n=scan()
F=i=!1:2
`?`=sum
while(?n>i)if(n==?(i[s]=i[s<-sign((?!(r=(T=T+1)%/%10^(0:(b=nchar(T)-1))%%10%*%10^(b:0))%%1:r)-?!T%%1:T)]+1))F[s]=T
F

Try it online!

T is the integer currently being tried; the latest poor and rich numbers are stored in the vector F.

The shortest way I could find of reversing an integer was converting it to digits in base 10 with modular arithmetic, then converting back with powers of 10 inverted, but I expect to be outgolfed on this and other fronts.

I know that digEmAll has a 147 byte solution; waiting to see it!

Explanation (of previous, similar version):

n=scan() # input
i=0*1:3  # number of poor, middle class, and rich numbers so far
S=sum
while(S(n>i)){ # continue as long as at least one of the classes has less than n numbers
  if((i[s]=i[
    s<-2+sign(S(!(           # s will be 1 for poor, 2 for middle class, 3 for rich
      r=S((T<-T+1)%/%10^(0:( # reverse integer T with modular arithmetic
        b=log10(T)%/%1       # b is number of digits
        ))%%10*10^(b:0)) 
      )%%1:r)-               # compute number of divisors of r
      S(!T%%1:T))            # computer number of divisors of T
    ]+1)<=n){                # check we haven't already found n of that class
    F[s]=T
  }
}
F[-2] # print nth poor and rich numbers
146 bytes
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70
Loading
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70
Loading