Skip to main content
thinko
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 14 bytes

I⌊₂⁺¹·⁵‽X⁺·⁵N²I⌊⁺·⁵₂⊕‽X⁺·⁵N²

Try it online!Try it online! Link is to verbose version of code. Explanation:

            N   Input `n` as a number
         ⁺·⁵    Plus literal number `0.5`
        X    ²  Squared
       ‽        Random element of implicit range
   ⁺¹·⁵         Plus literal number `1.5`Incremented
               Square root
  ⁺·⁵           Plus literal number `0.5`
 ⌊              Floor
I               Cast to string
                Implicitly print

Example: For n=4, the implicit range is [0..20), which the remaining code maps 0..1 to 1, 2..5 to 2, 6..11 to 3 and 12..19 to 4, thus p(k)∝k as desired.

Charcoal, 14 bytes

I⌊₂⁺¹·⁵‽X⁺·⁵N²

Try it online! Link is to verbose version of code. Explanation:

            N   Input `n` as a number
         ⁺·⁵    Plus literal number `0.5`
        X    ²  Squared
       ‽        Random element of implicit range
   ⁺¹·⁵         Plus literal number `1.5`
               Square root
 ⌊              Floor
I               Cast to string
                Implicitly print

Example: For n=4, the implicit range is [0..20), which the remaining code maps 0..1 to 1, 2..5 to 2, 6..11 to 3 and 12..19 to 4, thus p(k)∝k as desired.

Charcoal, 14 bytes

I⌊⁺·⁵₂⊕‽X⁺·⁵N²

Try it online! Link is to verbose version of code. Explanation:

            N   Input `n` as a number
         ⁺·⁵    Plus literal number `0.5`
        X    ²  Squared
       ‽        Random element of implicit range
               Incremented
               Square root
  ⁺·⁵           Plus literal number `0.5`
 ⌊              Floor
I               Cast to string
                Implicitly print

Example: For n=4, the implicit range is [0..20), which the remaining code maps 0..1 to 1, 2..5 to 2, 6..11 to 3 and 12..19 to 4, thus p(k)∝k as desired.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 14 bytes

I⌊₂⁺¹·⁵‽X⁺·⁵N²

Try it online! Link is to verbose version of code. Explanation:

            N   Input `n` as a number
         ⁺·⁵    Plus literal number `0.5`
        X    ²  Squared
       ‽        Random element of implicit range
   ⁺¹·⁵         Plus literal number `1.5`
  ₂             Square root
 ⌊              Floor
I               Cast to string
                Implicitly print

Example: For n=4, the implicit range is [0..20), which the remaining code maps 0..1 to 1, 2..5 to 2, 6..11 to 3 and 12..19 to 4, thus p(k)∝k as desired.