Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	File size: 2,031 Bytes
			
			| f7df10a 26e70f3 c53ab25 f2e9284 c53ab25 f7df10a 370a167 f7df10a 26e70f3 f7df10a 4ebd7fa c53ab25 4ebd7fa c53ab25 370a167 c53ab25 f7df10a c53ab25 f7df10a c53ab25 f7df10a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap
import random
# Function to modify the generated number according to the rules
def modify_number(number):
    modified_number = ''
    for digit in number:
        if digit not in '01':  # Change any digit that is not 0 or 1 to 1
            modified_number += '1'
        else:
            modified_number += digit
    return modified_number
# Function to create the grid based on the boolean string
def create_grid(boolean_string):
    if len(boolean_string) != 16:
        st.error("The generated string is not 16 digits long.")
        return None
    
    # Convert string to a list of integers
    grid = np.array([int(bit) for bit in boolean_string]).reshape(4, 4)
    
    # Create a colormap for the grid
    cmap = ListedColormap(['white', 'black'])
    
    # Plot the grid
    fig, ax = plt.subplots()
    ax.matshow(grid, cmap=cmap)
    
    # Add grid lines and remove ticks
    ax.set_xticks(np.arange(-0.5, 4, 1), minor=True)
    ax.set_yticks(np.arange(-0.5, 4, 1), minor=True)
    ax.grid(which='minor', color='gray', linestyle='-', linewidth=2)
    ax.tick_params(left=False, bottom=False, labelleft=False, labelbottom=False)
    
    return fig
# Function to generate a random number between 0 and 1111111111111111
def generate_number():
    random_number = random.randint(0, 1111111111111111)  # Generate a random number between 0 and 1111111111111111
    random_number_str = str(random_number)
    if len(random_number_str) < 16:
        random_number_str = random_number_str.zfill(16)  # Pad with zeros to ensure 16 digits
    return modify_number(random_number_str)
st.title("4x4 Boolean Grid")
# Button to generate the boolean string
if st.button("Generate Random Boolean String"):
    boolean_string = generate_number()
    st.write(f"Generated Boolean String: {boolean_string}")
    
    # Display the grid
    fig = create_grid(boolean_string)
    if fig:
        st.pyplot(fig)
 |