Skip to main content

AI, Sudoku and the lily pond - the acceleration of the digital transformation

On November 8, 2022, I gave a keynote on digital trends at the Museum of Transport in Lucerne. On November 30 came ChatGPT. On December 15, I cancelled my Christmas vacation to completely review my courses and lectures and dive (deeply) into the AI pond. What happened?

To understand what happened, let's first do a short mental exercise: I've been following the development of digitalization for over 25 years. So let's assume there is an idyllic pond, somewhere in a beautiful corner of the forest. There are beautiful water lilies in the pond. They have been growing steadily lately. Let's assume that the area of the pond covered by the water lilies has doubled every week over the last 25 years. Today, half of the pond is covered by water lilies. How long will it take until it is completely covered by water lilies?


The answer to the water lily question above is: one week. This story is about exponential growth. What went down with A.I. use late last year is comparable to the water lily story. A.I. use (I'm not talking about development) has taken a striking leap the likes of which I haven't seen in 25 years. From my perspective, it's not sunrise or coffee break in this area - it's 5 minutes to 12 o'clock and we need to ask the fundamental questions now. Probably someone is programming AI with AI right this minute. And AI might be  programming itself without us noticing. 




At the Hotel Innovation Day in Lucerne, I first presented my vision of digital transformation (see the fig. above). Today, it is estimated that more than half a billion apps exist in the cloud. And the trend is rising exponentially (the orange line in the graph). This has become possible because, in turn, the expertise needed to create apps has declined (probably also exponentially) over the past decades (the blue line). At the time of my keynote in Lucerne, it was already possible to create complete web apps without programming a line code. Which brought us to the point, where end users can conveniently create solutions on their own, without any development skills. Among hundreds, Ninox.com might stand as example platform here.  

I ventured a prediction on November 8 that it will take about two more years for apps to program apps themselves. And about five years until AI programs itself and we don't even notice. I was wrong about the growth factor, and massively so. What followed in the field of A.I. use at the end of last year is comparable to the lilypond story. We are speaking about A.I. imminently immersing all the potential challenges of our everyday life. 


A basic, fully Chat-GPT written Sudoku solver running on my standard Web hosting. Try it out! https://good-morning-ai.ch/sudoku/ 

On November 30, OpenAI launched ChatGPT. Most evidently, this app is capable of programming apps. That is the topic of the experiment at the end of this post. It demonstrates that ChatGPT is able to program a complete Sudoku web app and install it on a standard web hosting. True, it's a suboptimal solution without advanced puzzle input testing, it took several iterations to get the functionality the way I wanted it. But that was less due to ChatGPT and more due to my imprecise requests. I emphasize that I didn't code a single line of code in the whole exercise. 

The fact is, apps can program apps now. Not two years from now. But, can A.I. program A.I., too? I'll do an experiment on that sometime soon, too. But the very fact that apps are now programming apps without our technical intervention raises immense ethical, social, economic, and educational questions. Are we allowing this to happen? And where will it lead? These questions spark an intense debate among experts and specialists from various fields. 

On one hand, software programming itself software presents great potential for innovation, problem-solving, and improving efficiency. As technology continues to advance, the benefits of AI-driven software development are becoming more apparent. By leveraging software to program software, we can harness the power of artificial intelligence to solve complex problems, streamline processes, and boost productivity.

However, the development and use of software programming software should be undertaken responsibly. This includes considering ethical implications, potential social consequences, and the need to maintain human values and creativity in the process. I believe that we urgently need to stress the importance of transparency, fairness, and accountability in AI-driven software development to mitigate potential risks, such as biased algorithms and a loss of human control.

The experiment:

I have to write a complete sudoku solver with 9 quadrants in php an install it to a standard web hosting. The interface should have text area where I can interactively enter a grid to solve, a solve button which runs the program and completes the grid and a reset button that clears the grid. Please write this for me and explain how I can deploy it to the hosting. 

(ChatGPT-4)

I can help you create a basic Sudoku solver in PHP, along with an HTML interface. Here's an outline of the process:

  1. Create the PHP script that will solve the Sudoku puzzle.
  2. Create an HTML interface for input and display of the Sudoku puzzle.
  3. Deploy the PHP script and the HTML file to your web hosting.
(and after a few interactions and iterations...)

Step 1: Create the PHP script that will solve the Sudoku puzzle

Create a file named sudoku_solver.php and add the following code:

<?php
header('Content-Type: application/json');

function is_valid($grid, $row, $col, $num) {
    for ($i = 0; $i < 9; $i++) {
        if ($grid[$row][$i] == $num || $grid[$i][$col] == $num) {
            return false;
        }
    }

    $start_row = floor($row / 3) * 3;
    $start_col = floor($col / 3) * 3;

    for ($i = 0; $i < 3; $i++) {
        for ($j = 0; $j < 3; $j++) {
            if ($grid[$i + $start_row][$j + $start_col] == $num) {
                return false;
            }
        }
    }

    return true;
}

function solve($grid, $position = 0) {
    if ($position == 81) {
        return $grid;
    }

    $row = floor($position / 9);
    $col = $position % 9;

    if ($grid[$row][$col] != 0) {
        return solve($grid, $position + 1);
    }

    for ($num = 1; $num <= 9; $num++) {
        if (is_valid($grid, $row, $col, $num)) {
            $grid[$row][$col] = $num;

            if ($solution = solve($grid, $position + 1)) {
                return $solution;
            }
        }
    }

    $grid[$row][$col] = 0;
    return false;
}

$input = json_decode(file_get_contents('php://input'), true);
$grid = $input['grid'];

if (count($grid) != 9 || count($grid[0]) != 9) {
    echo json_encode("Invalid input format.");
    exit;
}

$solution = solve($grid);

if ($solution) {
    echo json_encode($solution);
} else {
    echo json_encode("No solution found.");
}
?>


Step 2: Create an HTML interface for input and display of the Sudoku puzzle

Create a file named index.html and add the following code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sudoku Solver</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }

        input[type="button"] {
            margin-top: 20px;
            padding: 10px;
            font-size: 18px;
            cursor: pointer;
        }
    </style>
    <script>
        function sendData() {
            let grid = document.getElementById('sudoku-input').value.split('\n').map(row => row.split(' ').map(cell => parseInt(cell.trim())));

            if (grid.length !== 9 || grid.some(row => row.length !== 9)) {
                alert('Invalid input format. Please enter 9 rows with 9 numbers separated by spaces in each row. Use 0 for missing numbers.');
                return;
            }

            fetch('sudoku_solver.php', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({grid: grid})
            })
            .then(response => response.json())
            .then(data => {
                if (typeof data === 'string') {
                    alert(data);
                } else {
                    document.getElementById('sudoku-output').value = data.map(row => row.join(' ')).join('\n');
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }

        function resetGrid() {
            loadSamplePuzzle();
            document.getElementById('sudoku-output').value = '';
        }

        function loadSamplePuzzle() {
            const samplePuzzle = `0 2 0 0 0 0 0 0 0
0 3 6 0 7 9 2 0 0
1 0 9 5 0 8 0 0 0
0 6 1 0 0 0 9 8 0
9 0 0 0 8 0 0 0 7
0 8 7 0 0 0 4 6 0
0 0 0 3 0 6 7 0 4
0 0 4 2 5 0 8 1 0
0 0 0 0 0 0 0 2 0`;
            document.getElementById('sudoku-input').value = samplePuzzle;
        }
    </script>
</head>
<body onload="loadSamplePuzzle()">
    <h1>Sudoku Solver</h1>
    <form>
        <label for="sudoku-input">Input Sudoku Grid:</label><br>
        <textarea id="sudoku-input" name="sudoku-input" rows="9" cols="20" placeholder="Enter 9 rows with 9 numbers separated by spaces in each row. Use 0 for missing numbers"></textarea><br>
        <input type="button" value="Solve" onclick="sendData()" />
        <input type="button" value="Reset" onclick="resetGrid()" /><br><br>
        <label for="sudoku-output">Solved Sudoku Grid:</label><br>
        <textarea id="sudoku-output" name="sudoku-output" rows="9" cols="20" readonly></textarea>
    </form>
</body>
</html>


Step 3: Deploy the PHP script and the HTML file to your web hosting
  1. Upload both sudoku_solver.php and index.html to your web hosting, in the same directory (usually the public_html folder).
  2. Make sure your web hosting supports PHP.
  3. Open your browser and navigate to the URL where you uploaded the files (e.g., http://example.com/index.html).
  4. You should now be able to interact with the Sudoku grid, enter a puzzle, solve it, and reset the grid.

sudoku_solver.php is a PHP script that solves a given Sudoku puzzle using a backtracking algorithm. Here is an explanation and documentation for the script:


please write an explanation and a documentation for the sudoku_solver.php

Overview

The script takes a JSON-encoded input of a 9x9 grid representing the Sudoku puzzle, with 0s representing the empty cells. It then tries to solve the puzzle using the backtracking algorithm and returns the solved grid in JSON format. If the puzzle has no solution, the script returns a "No solution found" message.

Functions

is_valid($grid, $row, $col, $num)

This function checks if it's valid to place a given number $num in a specific cell, specified by the $row and $col indices, in the $grid. It returns true if the number can be placed in the cell without violating Sudoku rules (i.e., no duplicates in the row, column, or 3x3 subgrid) and false otherwise.

solve($grid, $position)

This is a recursive function that uses a backtracking algorithm to solve the given Sudoku $grid. The $position parameter is an integer representing the current cell index, ranging from 0 to 80 (inclusive). The function returns the solved grid if a solution is found, or false if there is no solution.

Main script

The script sets the content type to application/json using the header() function, as it will return JSON-encoded data.

It reads the input JSON data sent via a POST request using file_get_contents('php://input') and decodes it into a PHP array using json_decode(). The input should be a 9x9 grid representing the Sudoku puzzle.

It checks if the input grid dimensions are valid (9x9). If the input format is invalid, it returns an "Invalid input format" message.

It calls the solve() function with the input grid to try and solve the puzzle.

If the solve() function returns a solution, the script encodes the solved grid in JSON format and returns it. If there is no solution, it returns a "No solution found" message.

Usage

Upload the sudoku_solver.php file to your web server and send a POST request to its URL with the JSON-encoded input grid. The script will return the solved grid in JSON format or an error message if there is no solution or the input format is invalid.

To use the script with the provided HTML file, make sure both the index.html and sudoku_solver.php files are in the same directory on your web server. The HTML file includes JavaScript code to send the input grid and receive the solved grid from the PHP script.

Popular posts from this blog

An Ethical Framework for Exams and Continuous Assessment with AI

Throughout the history of education, a multitude of diverse and even contentious methodologies have been employed to assess knowledge and aptitude. Several assessment methods have been employed, ranging from oral examinations to written tests, all with the overarching objective of discerning the extent to which students comprehend the subject matter in a manner that is equitable, comprehensive, and optimal. In the present context, amidst the cusp of a forthcoming epoch, the ongoing discourse persists, albeit with a futuristic inclination. The emergence of Artificial Intelligence (AI) has brought about transformative changes in the field of education, revolutionizing the tools and methodologies employed for assessment and evaluation. As we transition into this emerging era, it is crucial to discuss the implications for the fundamental principles and ideals of education. The conventional methods of assessment, commonly characterized by high-stakes examinations and standardized tests, ha...

Rethinking Exams in the Age of Chatbots

Today's experiment explores the potential of ChatGPT to assist me in the realm of exams, particularly within my field of teaching, Business Analysis. Can ChatGPT create a question for an exam? Indeed, it can do even more! In the experiment below, ChatGPT showcases (to varying extents) its ability to not only generate an exam question but also to engage in several related tasks: Generate a difficult critical question Solve the question Critically evaluate the solution (its own solution!) Attribute a mark between 1 and 6 Attribute a severe mark between 1 and 6 Defend a mark Refute a mark Generate a variation of the question which is difficult to solve Generate a variation of the question which is even more difficult to solve Give a correction scale with marks from 1 to 6  The impact of AI and chatbots like ChatGPT impact on university exams is becoming increasingly evident. Students and teachers alike are beginning to discover these tools, questioning their potential to generate, cor...

How to augment a Course with AI and Student Personas

As an educator in the field of business analysis, I've always sought innovative ways to enhance the learning experience for my students. My latest experiment (see below) into this endeavor involved leveraging ChatGPT to not only understand the learning process better but also to tailor it to individual student needs. Here's a glimpse into this fascinating journey. It began with identifying eight phases of a learning process with ChatGPT. These phases ranged from orientation to reflection and evaluation, encompassing the entire spectrum of a student's learning journey. The goal was to understand how students navigate through these phases and how they could be supported in each step. Building on these phases, I adapted them into a model for student personas . This involved considering various aspects of a student's academic life, personal characteristics, and learning styles. From this model, I created ten distinct student personas. Each persona represented a unique c...