fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.09s 54720KB
stdin
import matplotlib.pyplot as plt
import networkx as nx
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet

# PDF 輸出路徑
pdf_path = "HarryPotter_TimeTurner_Logic.pdf"
doc = SimpleDocTemplate(pdf_path, pagesize=A4)
styles = getSampleStyleSheet()
story = []

# 標題
story.append(Paragraph("哈利波特《阿茲卡班的逃犯》時光器悖論的邏輯分析", styles["Title"]))
story.append(Spacer(1, 12))

# 簡介文字
intro = """
本文件將以四大邏輯律(同一律、矛盾律、排中律、充足理由律)檢視
《哈利波特:阿茲卡班的逃犯》中「時光器」情節的邏輯錯誤,並搭配表格與流程圖清楚呈現矛盾之處。
"""
story.append(Paragraph(intro, styles["Normal"]))
story.append(Spacer(1, 12))

# 表格數據
data = [
    ["邏輯律", "電影中的錯誤"],
    ["同一律", "同一人物出現兩個版本(哈利同時存在)"],
    ["矛盾律", "命題同時為真與假(施放又未施放護法咒)"],
    ["排中律", "命題真值模糊(既有施法又無施法)"],
    ["充足理由律", "因果循環(護法咒無起源)"]
]

table = Table(data, colWidths=[100, 340])
table.setStyle(TableStyle([
    ("BACKGROUND", (0, 0), (-1, 0), colors.lightblue),
    ("TEXTCOLOR", (0, 0), (-1, 0), colors.black),
    ("ALIGN", (0, 0), (-1, -1), "CENTER"),
    ("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
    ("FONTSIZE", (0, 0), (-1, -1), 10),
    ("BOX", (0, 0), (-1, -1), 1, colors.black),
    ("GRID", (0, 0), (-1, -1), 0.5, colors.grey),
]))
story.append(table)
story.append(Spacer(1, 24))

# 流程圖繪製
G = nx.DiGraph()
nodes = {
    "Harry1": "哈利(當下)",
    "TimeTurner": "使用時光器",
    "Harry2": "哈利(回到過去)",
    "Patronus": "施放護法咒",
    "Loop": "因果循環:護法咒無起源"
}
for n, label in nodes.items():
    G.add_node(n, label=label)

edges = [
    ("Harry1", "TimeTurner"),
    ("TimeTurner", "Harry2"),
    ("Harry2", "Patronus"),
    ("Patronus", "Harry1"),
    ("Patronus", "Loop")
]
G.add_edges_from(edges)

# 標註四大邏輯律
annotations = {
    ("Harry1", "TimeTurner"): "同一律\n(哈利仍是同一人?)",
    ("Harry2", "Patronus"): "矛盾律\n(已施放/未施放)",
    ("Patronus", "Harry1"): "排中律\n(真或假不明確)",
    ("Patronus", "Loop"): "充足理由律\n(因果循環缺乏原因)"
}

plt.figure(figsize=(6, 5))
pos = nx.spring_layout(G, seed=42)
nx.draw_networkx_nodes(G, pos, node_size=2800, node_color="lightyellow", edgecolors="black")
nx.draw_networkx_labels(G, pos, labels=nx.get_node_attributes(G, "label"), font_size=8)
nx.draw_networkx_edges(G, pos, arrowstyle="->", arrowsize=15)

for edge, text in annotations.items():
    x0, y0 = pos[edge[0]]
    x1, y1 = pos[edge[1]]
    xm, ym = (x0 + x1) / 2, (y0 + y1) / 2
    plt.text(xm, ym, text, fontsize=6, color="darkred", ha="center", va="center",
             bbox=dict(boxstyle="round,pad=0.2", facecolor="mistyrose", edgecolor="red", alpha=0.6))

plt.axis("off")
flowchart_path = "flowchart.png"
plt.savefig(flowchart_path, bbox_inches="tight", dpi=150)
plt.close()

# 插入流程圖到 PDF
story.append(Paragraph("時光器悖論流程圖(含四大邏輯律標註)", styles["Heading2"]))
story.append(Image(flowchart_path, width=400, height=300))
story.append(Spacer(1, 12))

# 輸出 PDF
doc.build(story)
print(f"已輸出 PDF 檔案:{pdf_path}")
stdout
Standard output is empty