Narcissist: Difference between revisions

Content added Content deleted
(Replaced PowerShell with sample that meets task objectives)
Line 264: Line 264:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
{{works with|PowerShell|2}}
<lang PowerShell>
<lang PowerShell>
function entropy ($string) {
function Narcissist
{
$n = $string.Length
Param ( [string]$String )
$string.ToCharArray() | group | foreach{
If ( $String -eq $MyInvocation.MyCommand.Definition ) { 'Accept' }
$p = $_.Count/$n
Else { 'Reject' }
$i = [Math]::Log($p,2)
-$p*$i
} | measure -Sum | foreach Sum
}
}
entropy $(get-content "$($MyInvocation.MyCommand.Name )" -Raw)
</lang>
</lang>
<lang PowerShell>
Narcissist 'Banana'
Narcissist @'

Param ( [string]$String )
If ( $String -eq $MyInvocation.MyCommand.Definition ) { 'Accept' }
Else { 'Reject' }

'@
</lang>
{{out}}
<pre>
<pre>
Reject
4.74418336918292
Accept
</pre>
</pre>