Skip to main content
Commonmark migration
Source Link

#dc, 9

dc, 9

0?dvd*-^p

Outputs 1 for truthy and 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

#dc, 9

0?dvd*-^p

Outputs 1 for truthy and 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

dc, 9

0?dvd*-^p

Outputs 1 for truthy and 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

deleted 13 characters in body
Source Link
Digital Trauma
  • 73k
  • 9
  • 112
  • 264

#dc, 9

0?dvd*-^p

Outputs 01 for truthy and an integer > 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

#dc, 9

0?dvd*-^p

Outputs 0 for truthy and an integer > 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

#dc, 9

0?dvd*-^p

Outputs 1 for truthy and 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

added 147 characters in body
Source Link
Digital Trauma
  • 73k
  • 9
  • 112
  • 264

#dc, 79

0?dvd*-p^p

Outputs 0 for truthy and an integer > 0 for falsey.

Try it onlineTry it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

#dc, 7

?dvd*-p

Outputs 0 for truthy and an integer > 0 for falsey.

Try it online.

?          # Push input.  Stack: [ n ]
 dv        # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n ]
   d       # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n ]
    *      # multiply.  Stack: [ ⌊√n⌋², n ]
     -     # take difference. Stack: [ n-⌊√n⌋² ]
      p    # print.

#dc, 9

0?dvd*-^p

Outputs 0 for truthy and an integer > 0 for falsey.

Try it online.

0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ⌊√n⌋, n, 0 ]
    d        # duplicate.  Stack: [ ⌊√n⌋, ⌊√n⌋, n, 0 ]
     *       # multiply.  Stack: [ ⌊√n⌋², n, 0 ]
      -      # take difference. Stack: [ n-⌊√n⌋², 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-⌊√n⌋²) ]
        p    # print.

Note dc's ^ exponentiation command gives 00=1 and 0n=0, where n>0.

Source Link
Digital Trauma
  • 73k
  • 9
  • 112
  • 264
Loading