Skip to main content
edited body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5] (if n<45),
      # in [2,5] (if 45<=n<60) and in [0,5] (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out, 1 per line.
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5] (if n<45),
      # in [2,5] (if 45<=n<60) and in [0,5] (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5] (if n<45),
      # in [2,5] (if 45<=n<60) and in [0,5] (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out, 1 per line.
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}
edited body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5)5] (if n<45),
      # in [2,5)5] (if 45<=n<5045<=n<60) and in [0,5)5] (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5) (if n<45),
      # in [2,5) (if 45<=n<50) and in [0,5) (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5] (if n<45),
      # in [2,5] (if 45<=n<60) and in [0,5] (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}
added 608 characters in body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5) (if n<45),
      # in [2,5) (if 45<=n<50) and in [0,5) (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

R, 85 84 bytes

function(n)write(ifelse(t<-table(cut(runif(1e3,2*(n<60)+3*(n<45),5),0:5)),t,""),1,1)

-1 byte thanks to @Giuseppe

Try it online!

Explanation (ungolfed):

function(n){
      # Generate 1000 random uniform numbers in [5,5) (if n<45),
      # in [2,5) (if 45<=n<50) and in [0,5) (if n>=60).
    x = runif(1e3,2*(n<60)+3*(n<45),5) 
      # Code each by the number of the interval it falls in (0,1],(1,2]...(4,5]
    cx = cut(x,0:5)
      # Tabulate the intervals. Because cut() returns a factor,
      # zero counts are included 
    t = table(cx)
      # Vector-wise replace zero elements with "" and cat out
    t1 = ifelse(t,t,"")
    write(t1,1,1)
}
added 38 characters in body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15
Loading
deleted 11 characters in body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15
Loading
Source Link
J.Doe
  • 2.6k
  • 11
  • 15
Loading