Spaces:
Sleeping
Sleeping
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['ๆฎใใฎ่ฆ็ด ']}") | |