Jump to content

Narcissist: Difference between revisions

Replaced PowerShell with sample that meets task objectives
(Replaced PowerShell with sample that meets task objectives)
Line 264:
 
=={{header|PowerShell}}==
{{works with|PowerShell|2}}
<lang PowerShell>
function entropy ($string) {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 PowerShell>
Narcissist 'Banana'
Narcissist @'
 
Param ( [string]$String )
If ( $String -eq $MyInvocation.MyCommand.Definition ) { 'Accept' }
Else { 'Reject' }
 
'@
</lang>
{{out}}
<pre>
Reject
4.74418336918292
Accept
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.