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

#Perl, (削除) 363 (削除ここまで)(削除) 353 (削除ここまで)(削除) 350 (削除ここまで)(削除) 347 (削除ここまで)(削除) 343 (削除ここまで)(削除) 297 (削除ここまで)(削除) 266 (削除ここまで) 264

Perl, (削除) 363 (削除ここまで)(削除) 353 (削除ここまで)(削除) 350 (削除ここまで)(削除) 347 (削除ここまで)(削除) 343 (削除ここまで)(削除) 297 (削除ここまで)(削除) 266 (削除ここまで) 264

#Perl, (削除) 363 (削除ここまで)(削除) 353 (削除ここまで)(削除) 350 (削除ここまで)(削除) 347 (削除ここまで)(削除) 343 (削除ここまで)(削除) 297 (削除ここまで)(削除) 266 (削除ここまで) 264

Perl, (削除) 363 (削除ここまで)(削除) 353 (削除ここまで)(削除) 350 (削除ここまで)(削除) 347 (削除ここまで)(削除) 343 (削除ここまで)(削除) 297 (削除ここまで)(削除) 266 (削除ここまで) 264

deleted 2 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11

#Perl, (削除) 363 (削除ここまで) (削除) 353 (削除ここまで) (削除) 350 (削除ここまで) (削除) 347 (削除ここまで) (削除) 343 (削除ここまで) (削除) 297 (削除ここまで) 266(削除) 266 (削除ここまで) 264

$_=<>;s/able to fly/X/g;$m=' ?(not )?\b(P|\w+)';while(s/$m.{8}$m\.//){$h';$h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1=1while s/$m.{8}map$m\.//;map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe

#Perl, (削除) 363 (削除ここまで) (削除) 353 (削除ここまで) (削除) 350 (削除ここまで) (削除) 347 (削除ここまで) (削除) 343 (削除ここまで) (削除) 297 (削除ここまで) 266

$_=<>;s/able to fly/X/g;$m=' ?(not )?\b(P|\w+)';while(s/$m.{8}$m\.//){$h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1}map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe

#Perl, (削除) 363 (削除ここまで) (削除) 353 (削除ここまで) (削除) 350 (削除ここまで) (削除) 347 (削除ここまで) (削除) 343 (削除ここまで) (削除) 297 (削除ここまで) (削除) 266 (削除ここまで) 264

$_=<>;s/able to fly/X/g;$m=' ?(not )?\b(P|\w+)';$h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1while s/$m.{8}$m\.//;map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
Evan Smaller
Source Link
Thaylon
  • 1.4k
  • 9
  • 11

#Perl, (削除) 363 (削除ここまで) (削除) 353 (削除ここまで) (削除) 350 (削除ここまで) (削除) 347 (削除ここまで) (削除) 343 (削除ここまで) (削除) 297 (削除ここまで) 268266

$_=<>;s/able to fly/X/g;$m='( not)?(not )?\b(P|\w+)';while(s/$m.{7,8}$m\.//){$h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1}map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
# Read one line from STDIN
$_=<>;
# Replaces special attribute with X
s/able to fly/X/g;
# Prepare attribute match
$m='( not)?(not )?\b(P|\w+)';
# Match "Everything that is A is also B. "
# "\bA........ \bB\."
# Match "Pigs are B. "
# "\bP........\bB\."
while(s/$m.{7,8}$m\.//)
{
 # Add facts for A => B and !B => !A, where A may equal "P" for "Pigs are"
 # Facts are stored as a hash of hashes %h; keys%h are the source attributes;
 # keys%{$h{$a}} are the attributes that follow from attribute $a
 # A "not attribute" is stored as "Nattribute", while a "attribute" is just stored as "attribute"
 $h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1
}
# For all known source attributes ... (this should really be keys%h but we dont mind the extra hashrefs)
map{%x=0,r($_,$_)}%h;
sub r
{
 ($a,$b)=@_;
 # ... remember that we hit a negation and therefor an inconsistency ...
 # If we check/add $b and find an existing "N$b" that means that attribute $b is supposed to be true and not true at the same time
 # It is cheaper bytewise to just add up all consistency errors (remember each fact has a hard value of 1) than to exit right here
 $e+=$h{$a}{N.$b};
 # ... remember that we processed this attribute for the current source attribute so we prevent loops ...
 $x{$b}++or
 # ... add a new fact and then follow the chains (again omitting keys).
 $h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}
}
# Did we happen on an inconsistency? Do pigs fly? Dont pigs fly? Maybe (Bitwise or is okay too)
print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe

#Perl, (削除) 363 (削除ここまで) (削除) 353 (削除ここまで) (削除) 350 (削除ここまで) (削除) 347 (削除ここまで) (削除) 343 (削除ここまで) (削除) 297 (削除ここまで) 268

$_=<>;s/able to fly/X/g;$m='( not)? ?\b(P|\w+)';while(s/$m.{7,8}$m\.//){$h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1}map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
# Read one line from STDIN
$_=<>;
# Replaces special attribute with X
s/able to fly/X/g;
# Prepare attribute match
$m='( not)? ?\b(P|\w+)';
# Match "Everything that is A is also B. "
# "\bA........ \bB\."
# Match "Pigs are B. "
# "\bP.......\bB\."
while(s/$m.{7,8}$m\.//)
{
 # Add facts for A => B and !B => !A, where A may equal "P" for "Pigs are"
 # Facts are stored as a hash of hashes %h; keys%h are the source attributes;
 # keys%{$h{$a}} are the attributes that follow from attribute $a
 # A "not attribute" is stored as "Nattribute", while a "attribute" is just stored as "attribute"
 $h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1
}
# For all known source attributes ... (this should really be keys%h but we dont mind the extra hashrefs)
map{%x=0,r($_,$_)}%h;
sub r
{
 ($a,$b)=@_;
 # ... remember that we hit a negation and therefor an inconsistency ...
 # If we check/add $b and find an existing "N$b" that means that attribute $b is supposed to be true and not true at the same time
 # It is cheaper bytewise to just add up all consistency errors (remember each fact has a hard value of 1) than to exit right here
 $e+=$h{$a}{N.$b};
 # ... remember that we processed this attribute for the current source attribute so we prevent loops ...
 $x{$b}++or
 # ... add a new fact and then follow the chains (again omitting keys).
 $h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}
}
# Did we happen on an inconsistency? Do pigs fly? Dont pigs fly? Maybe (Bitwise or is okay too)
print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe

#Perl, (削除) 363 (削除ここまで) (削除) 353 (削除ここまで) (削除) 350 (削除ここまで) (削除) 347 (削除ここまで) (削除) 343 (削除ここまで) (削除) 297 (削除ここまで) 266

$_=<>;s/able to fly/X/g;$m=' ?(not )?\b(P|\w+)';while(s/$m.{8}$m\.//){$h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1}map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
# Read one line from STDIN
$_=<>;
# Replaces special attribute with X
s/able to fly/X/g;
# Prepare attribute match
$m=' ?(not )?\b(P|\w+)';
# Match "Everything that is A is also B. "
# "\bA........ \bB\."
# Match "Pigs are B. "
# "\bP........\bB\."
while(s/$m.{8}$m\.//)
{
 # Add facts for A => B and !B => !A, where A may equal "P" for "Pigs are"
 # Facts are stored as a hash of hashes %h; keys%h are the source attributes;
 # keys%{$h{$a}} are the attributes that follow from attribute $a
 # A "not attribute" is stored as "Nattribute", while a "attribute" is just stored as "attribute"
 $h{1ドル?N.2ドル:2ドル}{3ドル?N.4ドル:4ドル}=$h{3ドル?4ドル:N.4ドル}{1ドル?2ドル:N.2ドル}=1
}
# For all known source attributes ... (this should really be keys%h but we dont mind the extra hashrefs)
map{%x=0,r($_,$_)}%h;
sub r
{
 ($a,$b)=@_;
 # ... remember that we hit a negation and therefor an inconsistency ...
 # If we check/add $b and find an existing "N$b" that means that attribute $b is supposed to be true and not true at the same time
 # It is cheaper bytewise to just add up all consistency errors (remember each fact has a hard value of 1) than to exit right here
 $e+=$h{$a}{N.$b};
 # ... remember that we processed this attribute for the current source attribute so we prevent loops ...
 $x{$b}++or
 # ... add a new fact and then follow the chains (again omitting keys).
 $h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}
}
# Did we happen on an inconsistency? Do pigs fly? Dont pigs fly? Maybe (Bitwise or is okay too)
print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
more commentary
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
improved regexp, removed pigs-while
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added 48 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
srsly
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
srsly
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added 1 character in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added 17 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added 17 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
new explanation
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
turns out i didnt need the not replacement anymore
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
and another 3 less with || -> or
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
replace && || with and or and saved some ()
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
Replaced foreach with map.
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added explanation
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added explanation
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
remove unused function ... ooops
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
added 70 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
deleted 2 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
deleted 5 characters in body
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading
Source Link
Thaylon
  • 1.4k
  • 9
  • 11
Loading

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