Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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
  • 73.7k
  • 10
  • 116
  • 268

#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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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
  • 73.7k
  • 10
  • 116
  • 268

#dc, 79

0?dvd*-p^p

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

Try it online 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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 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⌋2, n ]
 - # take difference. Stack: [ n-⌊√n⌋2 ]
 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⌋2, n, 0 ]
 - # take difference. Stack: [ n-⌊√n⌋2, 0 ]
 ^ # 0 to power of the result. Stack: [ 0^(n-⌊√n⌋2) ]
 p # print.

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

Source Link
Digital Trauma
  • 73.7k
  • 10
  • 116
  • 268
Loading

AltStyle によって変換されたページ (->オリジナル) /