Narcissist: Difference between revisions
Content added Content deleted
(Added Befunge example.) |
(Added PowerShell) |
||
Line 251: | Line 251: | ||
<pre>: (narcissist "(Str) (= Str (str narcissist))") |
<pre>: (narcissist "(Str) (= Str (str narcissist))") |
||
-> T</pre> |
-> T</pre> |
||
=={{header|PowerShell}}== |
|||
<lang PowerShell> |
|||
function entropy ($string) { |
|||
$n = $string.Length |
|||
$string.ToCharArray() | group | foreach{ |
|||
$p = $_.Count/$n |
|||
$i = [Math]::Log($p,2) |
|||
-$p*$i |
|||
} | measure -Sum | foreach Sum |
|||
} |
|||
entropy $(get-content "$($MyInvocation.MyCommand.Name )" -Raw) |
|||
</lang> |
|||
<pre> |
|||
4.74418336918292 |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |