Skip to main content
deleted 640 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Try it online in the CJam interpreter: [Chrome] | [Firefox][CJam interpreter][1].

[Chrome][1]: http://cjam.aditsu.net/#code=q_'.e%3D%5CN%2F%7B)'%3F%3D%5CS%2F%3E_%2C(%25%7D%25%2F(__%2C*%7B(2%24z~%40f%3D.%5Cm%7C%7D%2Fff%7B1%24e%3D%3E%3A%3DN%7D&input=Cop%20is%20a%20Person.%0ACriminal%20is%20a%20Person.%0ASheriff%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Criminal.%0ABankRobber%20is%20a%20Criminal.%0ACop%20has%20a%20badge.%0ACriminal%20has%20a%20criminal_record.%0APerson%20has%20a%20name.%0AIs%20Crooked_Cop%20a%20Person%3F%0ADoes%20Criminal%20have%20a%20name%3F%0AIs%20Crooked_Cop%20a%20BankRobber%3F%0ADoes%20Person%20have%20a%20potato%3F%0AIs%20Cop%20a%20Cop%3F

[Firefox]: http://cjam.aditsu.net/#code=q_'.e%3D%5CN%2F%7B)'%3F%3D%5CS%2F%3E_%2C(%2525%7D%2525%2F(__%2C*%7B(2%24z~%40f%3D.%5Cm%7C%7D%2Fff%7B1%24e%3D%3E%3A%3DN%7D&input=Cop%20is%20a%20Person.%0ACriminal%20is%20a%20Person.%0ASheriff%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Criminal.%0ABankRobber%20is%20a%20Criminal.%0ACop%20has%20a%20badge.%0ACriminal%20has%20a%20criminal_record.%0APerson%20has%20a%20name.%0AIs%20Crooked_Cop%20a%20Person%3F%0ADoes%20Criminal%20have%20a%20name%3F%0AIs%20Crooked_Cop%20a%20BankRobber%3F%0ADoes%20Person%20have%20a%20potato%3F%0AIs%20Cop%20a%20Cop%3F

Try it online in the CJam interpreter: [Chrome] | [Firefox]

[Chrome]: http://cjam.aditsu.net/#code=q_'.e%3D%5CN%2F%7B)'%3F%3D%5CS%2F%3E_%2C(%25%7D%25%2F(__%2C*%7B(2%24z~%40f%3D.%5Cm%7C%7D%2Fff%7B1%24e%3D%3E%3A%3DN%7D&input=Cop%20is%20a%20Person.%0ACriminal%20is%20a%20Person.%0ASheriff%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Criminal.%0ABankRobber%20is%20a%20Criminal.%0ACop%20has%20a%20badge.%0ACriminal%20has%20a%20criminal_record.%0APerson%20has%20a%20name.%0AIs%20Crooked_Cop%20a%20Person%3F%0ADoes%20Criminal%20have%20a%20name%3F%0AIs%20Crooked_Cop%20a%20BankRobber%3F%0ADoes%20Person%20have%20a%20potato%3F%0AIs%20Cop%20a%20Cop%3F

[Firefox]: http://cjam.aditsu.net/#code=q_'.e%3D%5CN%2F%7B)'%3F%3D%5CS%2F%3E_%2C(%2525%7D%2525%2F(__%2C*%7B(2%24z~%40f%3D.%5Cm%7C%7D%2Fff%7B1%24e%3D%3E%3A%3DN%7D&input=Cop%20is%20a%20Person.%0ACriminal%20is%20a%20Person.%0ASheriff%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Criminal.%0ABankRobber%20is%20a%20Criminal.%0ACop%20has%20a%20badge.%0ACriminal%20has%20a%20criminal_record.%0APerson%20has%20a%20name.%0AIs%20Crooked_Cop%20a%20Person%3F%0ADoes%20Criminal%20have%20a%20name%3F%0AIs%20Crooked_Cop%20a%20BankRobber%3F%0ADoes%20Person%20have%20a%20potato%3F%0AIs%20Cop%20a%20Cop%3F

Try it online in the [CJam interpreter][1].

[1]: http://cjam.aditsu.net/#code=q_'.e%3D%5CN%2F%7B)'%3F%3D%5CS%2F%3E_%2C(%25%7D%25%2F(__%2C*%7B(2%24z~%40f%3D.%5Cm%7C%7D%2Fff%7B1%24e%3D%3E%3A%3DN%7D&input=Cop%20is%20a%20Person.%0ACriminal%20is%20a%20Person.%0ASheriff%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Cop.%0ACrooked_Cop%20is%20a%20Criminal.%0ABankRobber%20is%20a%20Criminal.%0ACop%20has%20a%20badge.%0ACriminal%20has%20a%20criminal_record.%0APerson%20has%20a%20name.%0AIs%20Crooked_Cop%20a%20Person%3F%0ADoes%20Criminal%20have%20a%20name%3F%0AIs%20Crooked_Cop%20a%20BankRobber%3F%0ADoes%20Person%20have%20a%20potato%3F%0AIs%20Cop%20a%20Cop%3F

deleted 15 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
q_ e# Push all input from STDIN and a copy. '.e= e# Count the number of dots/statements (C). \N/ e# Split the original input at linefeeds. { e# For each line: )'?= e# Pop the last character and check if it is a question mark. e# Pushes 1 for '?', 0 for '.'. \S/ e# Split the modified line at spaces. > e# Remove the first chunk ("Does" or "Is") for questions. _,(% e# Keep the first and last element of the resulting array. }% e# /  e# Split the line array into chunks of length C. (_ e# Extract the first chunk (statements) and push a copy. e# The original becomes an accumulator for ≺. _,* e# Repeat the statements C times. { e# For each of the repeated statements: ( e# Shift out the first name. e# ["w" "x"] -> ["x"] "w" 2$z~ e# Copy the accumulator, zip it and dump. e# [["x" "y"] ["z" "w"]] -> ["x" "z"] ["y" "w"] @f= e# Rotate the shifted out name on top and check for equality. e# ["y" "w"] "w" -> [0 1] .* e# Vectorized string repetition. e# ["x" "z"] [0 1] -> ["" "z"] \m* e# Swap the result with the shifted array and apply Cartesian product. e# ["" "z"] ["x"] -> [["" "x"] ["z" "x"]] e# This accounts for transitivity; we had ["w" "x"] and ["z" "w"], e# so now we have ["z" "x"]. | e# Perform set union with the accumulator to add the new pairs. }/ e# ff{ e# For each of the questions on the bottom of the stack. 1$e= e# Count the occurrences of the question pair in the accumulator. > e# Remove 0 or 1 elements from the question pair. := e# Check for equality. e# If the question pair occurs in the accumulator, this pushes the e# second name of the question pair. Otherwise, it pushes 1 if the e# names are equal (to account for reflexivity) and 0 otherwise. N e# Push a linefeed. } e# 
q_ e# Push all input from STDIN and a copy. '.e= e# Count the number of dots/statements (C). \N/ e# Split the original input at linefeeds. { e# For each line: )'?= e# Pop the last character and check if it is a question mark. e# Pushes 1 for '?', 0 for '.'. \S/ e# Split the modified line at spaces. > e# Remove the first chunk ("Does" or "Is") for questions. _,(% e# Keep the first and last element of the resulting array. }% e# /  e# Split the line array into chunks of length C. (_ e# Extract the first chunk (statements) and push a copy. e# The original becomes an accumulator for ≺. _,* e# Repeat the statements C times. { e# For each of the repeated statements: ( e# Shift out the first name. e# ["w" "x"] -> ["x"] "w" 2$z~ e# Copy the accumulator, zip it and dump. e# [["x" "y"] ["z" "w"]] -> ["x" "z"] ["y" "w"] @f= e# Rotate the shifted out name on top and check for equality. e# ["y" "w"] "w" -> [0 1] .* e# Vectorized string repetition. e# ["x" "z"] [0 1] -> ["" "z"] \m* e# Swap the result with the shifted array and apply Cartesian product. e# ["" "z"] ["x"] -> [["" "x"] ["z" "x"]] e# This accounts for transitivity; we had ["w" "x"] and ["z" "w"], e# so now we have ["z" "x"]. | e# Perform set union with the accumulator to add the new pairs. }/ e# ff{ e# For each of the questions on the bottom of the stack. 1$e= e# Count the occurrences of the question pair in the accumulator. > e# Remove 0 or 1 elements from the question pair. := e# Check for equality. e# If the question pair occurs in the accumulator, this pushes the e# second name of the question pair. Otherwise, it pushes 1 if the e# names are equal (to account for reflexivity) and 0 otherwise. N e# Push a linefeed. } e# 
q_ e# Push all input from STDIN and a copy. '.e= e# Count the number of dots/statements (C). \N/ e# Split the original input at linefeeds. { e# For each line: )'?= e# Pop the last character and check if it is a question mark. e# Pushes 1 for '?', 0 for '.'. \S/ e# Split the modified line at spaces. > e# Remove the first chunk ("Does" or "Is") for questions. _,(% e# Keep the first and last element of the resulting array. }%/ e# Split the line array into chunks of length C. (_ e# Extract the first chunk (statements) and push a copy. e# The original becomes an accumulator for ≺. _,* e# Repeat the statements C times. { e# For each of the repeated statements: ( e# Shift out the first name. e# ["w" "x"] -> ["x"] "w" 2$z~ e# Copy the accumulator, zip it and dump. e# [["x" "y"] ["z" "w"]] -> ["x" "z"] ["y" "w"] @f= e# Rotate the shifted out name on top and check for equality. e# ["y" "w"] "w" -> [0 1] .* e# Vectorized string repetition. e# ["x" "z"] [0 1] -> ["" "z"] \m* e# Swap the result with the shifted array and apply Cartesian product. e# ["" "z"] ["x"] -> [["" "x"] ["z" "x"]] e# This accounts for transitivity; we had ["w" "x"] and ["z" "w"], e# so now we have ["z" "x"]. | e# Perform set union with the accumulator to add the new pairs. }/ e# ff{ e# For each of the questions on the bottom of the stack. 1$e= e# Count the occurrences of the question pair in the accumulator. > e# Remove 0 or 1 elements from the question pair. := e# Check for equality. e# If the question pair occurs in the accumulator, this pushes the e# second name of the question pair. Otherwise, it pushes 1 if the e# names are equal (to account for reflexivity) and 0 otherwise. N e# Push a linefeed. } e# 
added 1176 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Code (WIP)

q_ e# Push all input from STDIN and a copy. '.e= e# Count the number of dots/statements (C). \N/ e# Split the original input at linefeeds. { e# For each line: )'?= e# Pop the last character and check if it is a question mark. e# Pushes 1 for '?', 0 for '.'. \S/ e# Split the modified line at spaces. > e# Remove the first chunk ("Does" or "Is") for questions. _,(% e# Keep the first and last element of the resulting array. }% e# / e# Split the line array into chunks of length C. (_ e# Extract the first chunk (statements) and push a copy.  e# The original becomes an accumulator for ≺. _,* e# Repeat the statements C times. { e# For each of the repeated statements: ( e# Shift out the first name.  e# ["w" "x"] -> ["x"] "w" 2$z~ e# Copy the accumulator, zip it and dump.  e# [["x" "y"] ["z" "w"]] -> ["x" "z"] ["y" "w"] @f= e# Rotate the shifted out name on top and check for equality.  e# ["y" "w"] "w" -> [0 1] .* e#  Vectorized string repetition.  e# ["x" "z"] [0 1] -> ["" "z"] \m* e# Swap the result with the shifted array and apply Cartesian product. e#  ["" "z"] ["x"] -> [["" "x"] ["z" "x"]] e# This accounts for transitivity; we had ["w" "x"] and ["z" "w"], e# so now we have ["z" "x"]. | e# Perform set union with the accumulator to add the new pairs. }/ e# ff{ e# For each of the questions on the bottom of the stack. 1$e= e# Count the occurrences of the question pair in the accumulator. > e# Remove 0 or 1 elements from the question pair. := e# Check for equality. e# If the question pair occurs in the accumulator, this pushes the e# second name of the question pair. Otherwise, it pushes 1 if the  e# names are equal (to account for reflexivity) and 0 otherwise. N e# Push a linefeed. } e# 

Code (WIP)

q_ e# '.e= e# \N/ e# { e# )'?= e# \S/ e# > e# _,(% e# }% e# / e# (_ e# _,* e# { e# ( e# 2$z~ e# @f= e# .* e# \m* e# | e# }/ e# ff{ e# 1$e= e# > e# := e# N e# } e# 

Code

q_ e# Push all input from STDIN and a copy. '.e= e# Count the number of dots/statements (C). \N/ e# Split the original input at linefeeds. { e# For each line: )'?= e# Pop the last character and check if it is a question mark. e# Pushes 1 for '?', 0 for '.'. \S/ e# Split the modified line at spaces. > e# Remove the first chunk ("Does" or "Is") for questions. _,(% e# Keep the first and last element of the resulting array. }% e# / e# Split the line array into chunks of length C. (_ e# Extract the first chunk (statements) and push a copy.  e# The original becomes an accumulator for ≺. _,* e# Repeat the statements C times. { e# For each of the repeated statements: ( e# Shift out the first name.  e# ["w" "x"] -> ["x"] "w" 2$z~ e# Copy the accumulator, zip it and dump.  e# [["x" "y"] ["z" "w"]] -> ["x" "z"] ["y" "w"] @f= e# Rotate the shifted out name on top and check for equality.  e# ["y" "w"] "w" -> [0 1] .* e#  Vectorized string repetition.  e# ["x" "z"] [0 1] -> ["" "z"] \m* e# Swap the result with the shifted array and apply Cartesian product. e#  ["" "z"] ["x"] -> [["" "x"] ["z" "x"]] e# This accounts for transitivity; we had ["w" "x"] and ["z" "w"], e# so now we have ["z" "x"]. | e# Perform set union with the accumulator to add the new pairs. }/ e# ff{ e# For each of the questions on the bottom of the stack. 1$e= e# Count the occurrences of the question pair in the accumulator. > e# Remove 0 or 1 elements from the question pair. := e# Check for equality. e# If the question pair occurs in the accumulator, this pushes the e# second name of the question pair. Otherwise, it pushes 1 if the  e# names are equal (to account for reflexivity) and 0 otherwise. N e# Push a linefeed. } e# 
added 1176 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
fixed to comply with new test case
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
deleted 4 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
deleted 1 character in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
previous versions were invalid
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
previous versions were invalid
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
fixed bug
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
deleted 54 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 2 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 1 character in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading