OzoneAsai's picture
Create app.py
780b7ef verified
raw
history blame
1.69 kB
import streamlit as st
import math
def ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‹ใ‚‰้ †ๅˆ—ใ‚’็”Ÿๆˆใ™ใ‚‹(elements, index):
n = len(elements)
result = []
elements = sorted(elements)
steps = []
while n > 0:
factorial = math.factorial(n - 1)
pos, index = divmod(index, factorial)
result.append(elements.pop(pos))
step_detail = {
"ใ‚นใƒ†ใƒƒใƒ—": len(result),
"้ธใฐใ‚ŒใŸไฝ็ฝฎ": pos,
"ๆฎ‹ใ‚Šใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น": index,
"็พๅœจใฎ้ †ๅˆ—": result.copy(),
"ๆฎ‹ใ‚Šใฎ่ฆ็ด ": elements.copy()
}
steps.append(step_detail)
n -= 1
return result, steps
# Streamlitใ‚ขใƒ—ใƒชใฎ่จญๅฎš
st.title("ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‹ใ‚‰้ †ๅˆ—ใ‚’็”Ÿๆˆ")
# ใƒฆใƒผใ‚ถใƒผๅ…ฅๅŠ›
elements = st.text_input("่ฆ็ด ใ‚’ใ‚ซใƒณใƒžๅŒบๅˆ‡ใ‚Šใงๅ…ฅๅŠ›:", "1,2,3,4,5,6")
index = st.number_input("ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‚’ๅ…ฅๅŠ›:", min_value=0, value=88, step=1)
# ๅ…ฅๅŠ›ใ‚’ใƒชใ‚นใƒˆใซๅค‰ๆ›
elements = [int(e.strip()) for e in elements.split(",")]
# ้ †ๅˆ—ใฎ็”Ÿๆˆใจ้Ž็จ‹ใฎๅ–ๅพ—
if st.button("็”Ÿๆˆ"):
็”Ÿๆˆใ•ใ‚ŒใŸ้ †ๅˆ—, ้Ž็จ‹ = ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‹ใ‚‰้ †ๅˆ—ใ‚’็”Ÿๆˆใ™ใ‚‹(elements, index)
# ็ตๆžœใฎ่กจ็คบ
st.write(f"็”Ÿๆˆใ•ใ‚ŒใŸ้ †ๅˆ—: {็”Ÿๆˆใ•ใ‚ŒใŸ้ †ๅˆ—}")
# ้Ž็จ‹ใฎ่กจ็คบ
for step in ้Ž็จ‹:
st.write(f"ใ‚นใƒ†ใƒƒใƒ— {step['ใ‚นใƒ†ใƒƒใƒ—']}:")
st.write(f" ้ธใฐใ‚ŒใŸไฝ็ฝฎ: {step['้ธใฐใ‚ŒใŸไฝ็ฝฎ']}")
st.write(f" ๆฎ‹ใ‚Šใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น: {step['ๆฎ‹ใ‚Šใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น']}")
st.write(f" ็พๅœจใฎ้ †ๅˆ—: {step['็พๅœจใฎ้ †ๅˆ—']}")
st.write(f" ๆฎ‹ใ‚Šใฎ่ฆ็ด : {step['ๆฎ‹ใ‚Šใฎ่ฆ็ด ']}")