From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id AD4E2BB9C for ; Thu, 24 Nov 2005 03:38:47 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAO2clXi011936 for ; Thu, 24 Nov 2005 03:38:47 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA15273 for ; Thu, 24 Nov 2005 03:38:46 +0100 (MET) Received: from evaki.its.uow.edu.au (evaki.its.uow.edu.au [130.130.68.32]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAO2ciEh002620 for ; Thu, 24 Nov 2005 03:38:45 +0100 Received: from csm-server-nat-ip.its.uow.edu.au ([130.130.68.220] helo=febris.its.uow.edu.au) by evaki.its.uow.edu.au with esmtp (Exim 4.54) id 1Ef70U-0001H0-UC; Thu, 24 Nov 2005 13:38:42 +1100 Received: from minerva.its.uow.edu.au (csm-server-nat-ip.its.uow.edu.au [130.130.68.220]) by febris.its.uow.edu.au (MOS 3.5.6-GR) with ESMTP id CFU30402; Thu, 24 Nov 2005 13:38:41 +1100 (EST) Received: (from minerva.its.uow.edu.au [220.239.42.10]) by minerva.its.uow.edu.au (MOS 3.6.4-CR) with HTTP/1.1 id AUT44679 (AUTH sk75); Thu, 24 Nov 2005 13:38:41 +1100 (EST) From: Simon Subject: Re: [Caml-list] Mandelbrot renderer To: christophe.raffalli@univ-savoie.fr Cc: caml-list@inria.fr X-Mailer: Mirapoint Webmail Direct 3.6.4-CR MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20051124133841.AUT44679@minerva.its.uow.edu.au> Date: Thu, 24 Nov 2005 13:38:41 +1100 (EST) X-Miltered: at nez-perce with ID 438527B7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 438527B4.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 renderer:01 ocaml:01 solver:01 unneeded:01 columns:01 iter:01 iter:01 cola:98 cola:98 cols:98 cols:98 imperative:01 int:01 int:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=FROM_ENDS_IN_NUMS autolearn=disabled version=3.0.3 > And as I said in another post, I really would like an OCaml sudoko GENERATOR (not a solver) on my portable phone, I almost finished all the grids I have in the demo of a java commercial program I found on getjar.com, so this now is urgent :-) This won't work on your phone, but it will generate a wide range of sudoku puzzles, all of them will most likely be near to impossible. It works by shuffling a sudoku puzzle I took from Tuesday's paper and coded in after I removed a few unneeded numbers, then applying a permutation to the numbers. Not the most complex, but it should produce a very large range of puzzles, although probably not every single possible least-complex puzzle. Yes, it's long for its simplicity, all in imperative style and it won't work on your phone :(. --- Random.self_init() let m = [| [| 9; 4; 0; 0; 0; 7; 0; 0; 0 |]; [| 0; 6; 0; 0; 0; 0; 0; 1; 0 |]; [| 0; 0; 8; 0; 0; 1; 0; 5; 3 |]; [| 3; 0; 7; 0; 0; 0; 0; 6; 0 |]; [| 0; 0; 0; 0; 2; 0; 0; 0; 0 |]; [| 0; 5; 0; 0; 0; 0; 0; 3; 7 |]; [| 0; 9; 0; 8; 0; 0; 1; 0; 0 |]; [| 0; 1; 0; 0; 0; 0; 0; 8; 0 |]; [| 0; 0; 0; 4; 0; 0; 0; 0; 9 |] |] let swap_row board rowA rowB = let t = board.(rowA) in let _ = board.(rowA) <- board.(rowB) in board.(rowB) <- t let swap_col board colA colB = for i = 0 to 8 do let t = board.(i).(colA) in let _ = board.(i).(colA) <- board.(i).(colB) in board.(i).(colB) <- t done let shuffle_rows board = for i = 0 to 2 do for j = 0 to 2 do swap_row board (i * 3 + j) (i * 3 + (Random.int 3)) done done let shuffle_cols board = for i = 0 to 2 do for j = 0 to 2 do swap_col board (i * 3 + j) (i * 3 + (Random.int 3)) done done (* shuffle the 3x3 squares in their rows *) let shuffle_square_rows board = let swap_square_row a b = for i = 0 to 2 do swap_row board (a + i) (b + i) done in for i = 0 to 2 do swap_square_row (i * 3) (Random.int 3 * 3) done (* shuffle the 3x3 squares in their columns *) let shuffle_square_cols board = let swap_square_col a b = for i = 0 to 2 do swap_col board (a + i) (b + i) done in for i = 0 to 2 do swap_square_col (i * 3) (Random.int 3 * 3) done let shuffle board = shuffle_rows board; shuffle_cols board; shuffle_square_rows board; shuffle_square_cols board (* swap the numbers around *) let permutation board = let arr = Array.init 10 (fun i -> i) in (* really crappy way of making a permutation *) for i = 0 to 999 do swap_row arr (i mod 9 + 1) (Random.int 9 + 1) done; for i = 0 to 8 do let row = board.(i) in for j = 0 to 8 do row.(j) <- arr.(row.(j)) done done let () = shuffle m; permutation m; Array.iter (fun r -> Array.iter (print_int) r; print_newline()) m