Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #396684 > unrolled thread
| Started by | DFS <nospam@dfs.com> |
|---|---|
| First post | 2026-02-19 16:55 -0500 |
| Last post | 2026-03-16 09:04 +0100 |
| Articles | 20 on this page of 218 — 21 participants |
Back to article view | Back to comp.lang.c
Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-02-19 16:55 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway jayjwa <jayjwa@atr2.ath.cx.invalid> - 2026-02-25 15:56 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-02-26 10:05 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway jayjwa <jayjwa@atr2.ath.cx.invalid> - 2026-02-26 13:20 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 17:06 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 17:27 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-02-26 14:31 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway jayjwa <jayjwa@atr2.ath.cx.invalid> - 2026-02-26 13:33 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 18:49 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 18:55 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 19:17 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 19:34 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-02-26 20:01 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 10:36 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-06 17:38 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-06 17:48 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-02-27 00:12 +0000
[OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-06 06:37 +0100
Re: [OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) Bart <bc@freeuk.com> - 2026-03-06 15:48 +0000
Re: [OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-06 18:17 +0100
Re: [OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) Bart <bc@freeuk.com> - 2026-03-06 21:46 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-02 00:44 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-02 11:07 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-02 06:35 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-02 17:50 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-02 21:15 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-03 20:48 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-03 22:47 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway David Brown <david.brown@hesbynett.no> - 2026-03-04 08:48 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-04 01:07 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-04 12:09 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-04 11:19 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway David Brown <david.brown@hesbynett.no> - 2026-03-04 12:58 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-11 11:31 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-04 13:20 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-04 08:30 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-04 14:36 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-04 10:02 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-04 19:27 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-05 13:49 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-05 21:02 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-05 20:39 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-05 19:24 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 13:54 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-12 05:50 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-13 11:58 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-13 23:00 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:54 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-15 23:42 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-06 12:02 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:43 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-02 17:40 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-02 21:09 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-03 08:23 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-03 06:20 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-03 23:56 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-03 15:51 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-04 11:45 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-04 07:01 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-11 11:37 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-04 08:29 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-04 16:02 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-04 08:09 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 10:34 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-06 08:46 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-04 11:25 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-05 13:46 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway David Brown <david.brown@hesbynett.no> - 2026-03-05 21:34 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-05 19:09 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-05 21:12 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 14:12 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-05 22:24 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-06 01:00 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 15:08 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 15:05 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-06 00:18 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-07 22:04 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-08 00:26 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-08 02:45 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-08 17:05 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 07:57 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-06 00:12 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-06 00:14 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 20:31 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-06 13:51 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-06 08:53 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 19:36 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-06 18:14 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-07 18:21 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-07 11:55 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-07 20:10 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 10:44 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-07 12:02 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-07 20:14 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 10:53 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-07 16:58 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-08 00:35 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 08:23 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-08 00:40 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-08 10:42 -0400
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-08 15:18 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-08 12:21 -0400
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-08 19:29 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-09 21:20 -0400
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-10 14:43 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-10 18:08 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Giovanni <lsodgf0@home.net.it> - 2026-03-10 17:18 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-10 16:32 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-10 15:25 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 07:07 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-11 13:49 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-10 20:24 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-10 15:29 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-11 00:29 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-11 00:33 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-11 11:04 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway antispam@fricas.org (Waldek Hebisch) - 2026-03-10 20:18 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-12 05:37 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-08 17:57 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-08 13:19 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-09 01:12 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-08 21:42 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-03-08 15:58 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway David Brown <david.brown@hesbynett.no> - 2026-03-09 08:09 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-09 08:53 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-03-09 15:25 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 14:40 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-12 05:55 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-08 16:00 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 12:44 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-08 17:36 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-08 13:27 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 06:33 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway David Brown <david.brown@hesbynett.no> - 2026-03-08 12:22 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 06:27 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-07 16:43 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-11 07:29 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-11 14:22 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-25 10:07 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-25 15:54 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-30 03:13 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-06 16:02 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 12:11 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 13:01 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 13:28 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-06 21:53 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-06 22:14 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-07 07:33 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-07 10:24 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-07 19:16 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-07 14:18 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-08 00:47 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-09 22:18 -0400
Re: Sort of trivial code challenge - may be interesting to you anyway Richard Harnden <richard.nospam@gmail.invalid> - 2026-03-10 10:14 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Richard Harnden <richard.nospam@gmail.invalid> - 2026-03-11 11:40 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-07 13:33 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Richard Harnden <richard.nospam@gmail.invalid> - 2026-03-07 14:53 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-07 15:44 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-07 19:53 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-07 10:22 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-11 11:40 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-11 11:00 -0400
Re: Sort of trivial code challenge - may be interesting to you anyway wij <wyniijj5@gmail.com> - 2026-03-12 00:00 +0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-11 18:03 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-11 17:52 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway wij <wyniijj5@gmail.com> - 2026-03-12 23:14 +0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-12 16:23 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-12 16:11 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 14:04 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-11 11:36 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-11 11:35 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-03 15:40 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-03 16:23 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2026-03-04 15:31 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-04 09:38 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-03 16:39 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-03 12:00 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-04 11:44 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-04 17:44 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-04 15:13 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-04 21:07 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-04 23:37 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 07:32 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 08:23 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-05 02:24 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 08:46 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 09:52 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway tTh <tth@none.invalid> - 2026-03-05 10:49 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 11:03 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway gazelle@shell.xmission.com (Kenny McCormack) - 2026-03-05 15:22 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-05 05:06 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 11:13 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway DFS <nospam@dfs.com> - 2026-03-05 14:11 -0500
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-06 03:35 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-05 14:49 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Janis Papanagnou <janis_papanagnou@hotmail.com> - 2026-03-05 19:27 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-05 19:46 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway tTh <tth@none.invalid> - 2026-03-05 20:50 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-05 22:34 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-06 07:48 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-06 11:49 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-06 13:41 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-06 15:33 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-06 14:42 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 13:49 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-06 02:17 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-05 20:06 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-06 14:58 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Michael S <already5chosen@yahoo.com> - 2026-03-06 17:13 +0200
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-06 08:37 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway scott@slp53.sl.home (Scott Lurndal) - 2026-03-03 17:29 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-03 19:20 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-03 16:26 -0800
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-04 05:27 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Opus <ifonly@youknew.org> - 2026-03-04 22:42 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway peter <peter.noreply@tin.it> - 2026-03-14 10:42 +0100
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:09 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bonita Montero <Bonita.Montero@gmail.com> - 2026-03-16 09:04 +0100
Page 1 of 11 [1] 2 3 … 11 Next page →
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2026-02-19 16:55 -0500 |
| Subject | Sort of trivial code challenge - may be interesting to you anyway |
| Message-ID | <10n80sc$3soe4$1@dont-email.me> |
Challenge is to output sequential numbers by column then row:
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
Kind of goes without saying the solution should handle any row x column
input:
input rows columns
input 1 1
1
input 1 4
1 2 3 4
input 5 2
1 6
2 7
3 8
4 9
5 10
input 2 20
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Simple enough. But the following 2 requirements take it from trivial to
less trivial!
--------------------------------------------------------------------
1) must be able to cut the output off at any arbitrary value
lower than rows x columns
--------------------------------------------------------------------
input = 5 5 (no cutoff)
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
input = 5 5 23 (cutoff at 23)
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19
5 10 15 20
input = 5 5 6
1 6
2
3
4
5
input = 5 5 3
1
2
3
input = 1 10 (no cutoff)
1 2 3 4 5 6 7 8 9 10
input = 1 10 3 (cutoff at 3)
1 2 3
--------------------------------------------------------------------
2) if you don't specify rows and columns, your solution must try
to calculate them to form a square (same # of rows and columns)
that includes only 1 to N.
If rows=columns can't be calculated, return message 'not possible'
--------------------------------------------------------------------
input = N
input = 1 (1 row and 1 column includes 1)
1
input = 2
not possible to output 1-2 where rows=columns
input = 3 (2 rows and 2 columns includes 3)
1 3
2
input = 4 (2 rows and 2 columns includes 4)
1 3
2 4
input = 5
not possible to output 1-5 where rows=columns
input = 6
not possible to output 1-6 where rows=columns
input = 7 (3 rows and 3 columns includes 7)
1 4 7
2 5
3 6
input = 8
1 4 7
2 5 8
3 6
input = 9
1 4 7
2 5 8
3 6 9
input = 10 11 or 12
not possible to output 1-10/11/12 where rows=columns
input = 13
1 5 9 13
2 6 10
3 7 11
4 8 12
input = 14
1 5 9 13
2 6 10 14
3 7 11
4 8 12
input = 15
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12
input = 16
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
input = 17 18 19 or 20
not possible to output 1-17/18/19/20 where rows=columns
input = 21
1 6 11 16 21
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
input = 22
1 6 11 16 21
2 7 12 17 22
3 8 13 18
4 9 14 19
5 10 15 20
input = 25
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
input = 26
not possible to output 1-26 where rows=columns
input = 27
not possible to output 1-27 where rows=columns
etc
* Extra Credit if you determine a formula for this requirement. I kind
of brute-forced it with 2 loops. As you can see, N = prime isn't
enough to know if it can be done.
-----------------------------------------------------------------------
My code is below.
Look for 'core routine' to see the master output algorithm
Requirement 1 is part of the core routine
Requirement 2 is the function "calc_rows_columns()"
If you try this, don't feel obligated to output the column headers as I
did. It's a nice-to-have.
No code spying until you post yours!
Enjoy!
--------------------------------------------------------------------------
C listing
--------------------------------------------------------------------------
// this public domain program outputs numbers by column then row
// usage examples
// $prog rows columns (print a sequential nbr matrix of size rows x columns)
// $prog rows columns stop (output discontinued past stop)
// $prog N (try to find rows=columns that will include only 1-N in output
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//print a separator line
void printline(int linewidth, char *linechar) {
for(int i = 0; i < linewidth; i++) {
printf(linechar);
}
printf("\n");
}
//print column count headers
void printcolheader(int cols, int charwidth) {
printline(cols * charwidth,"-");
for (int p = 1; p <= cols; p++) {
printf("%*d",charwidth,p);
}
printf("\n");
printline(cols * charwidth,"-");
}
//twist: try to find rows=columns that will include the input number
void calc_rows_columns(int *rows, int *cols, int nbr) {
int m = 10000;
for (int i = 1; i < m; i++) {
if (i*i == nbr) {
*rows = i;
*cols = i;
return;
}
}
for (int i = 2; i < m; i++) {
if ((i*(i-1) < nbr) && ((i*i) >= nbr)) {
*rows = i;
*cols = i;
return;
}
}
printf("%s%d%s\n","Not possible to output 1-", nbr ," where rows =
columns");
exit(0);
}
//core routine to write row x column data to screen
void output(int rows, int cols, int max)
{
//calc horizontal spacing of columns based on largest number (minimum 3)
char strmax[10];
sprintf(strmax, "%d", max);
int colwidth = 1 + strlen(strmax);
if (colwidth == 2) {colwidth = 3;}
//print column header lines
//TODO: maybe print no header columns beyond the column containing the
max value
printcolheader(cols, colwidth);
//nbr matrix
for (int r = 1; r <= rows; r++) {
if (r <= max) {
int nbr = r;
printf("%*d",colwidth,nbr);
for (int i = 0; i < cols-1; i++) {
nbr += rows;
if (nbr <= max) {
printf("%*d",colwidth,nbr);
}
}
printf("\n");
}
else
{
break;
}
}
//repeat the headers for readability
if (rows >= 40 && max >= 40) {printcolheader(cols, colwidth);}
}
int main(int argc, char *argv[]) {
//validation
if (argc < 2 || argc > 4) {
printf("Use one of these input formats:\n");
printf(" $prog rows columns\n");
printf(" $prog rows columns max (program will halt output past max)\n");
printf(" $prog N (program will try to determine a square matrix to
incl N)\n");
return 0;
}
//vars
int rows, cols, max;
//only 1 argument = try to calc the rows = columns values
// that will include the input number
if (argc == 2) {
max = atoi(argv[1]);
calc_rows_columns(&rows, &cols, max);
}
if (argc == 3) {
rows = atoi(argv[1]);
cols = atoi(argv[2]);
max = rows * cols;
}
if (argc == 4) {
rows = atoi(argv[1]);
cols = atoi(argv[2]);
max = atoi(argv[3]);
}
//write data to screen
output(rows, cols, max);
return 0;
}
--------------------------------------------------------------------------
[toc] | [next] | [standalone]
| From | jayjwa <jayjwa@atr2.ath.cx.invalid> |
|---|---|
| Date | 2026-02-25 15:56 -0500 |
| Message-ID | <87342oo84a.fsf@atr2.ath.cx> |
| In reply to | #396684 |
DFS <nospam@dfs.com> writes:
> Kind of goes without saying the solution should handle any row x
> column input:
> input 1 1
$ cc /version
Compaq C V6.4-005 on OpenVMS VAX V7.3
$ cc rowcol.c
$ link rowcol
$ mcr []rowcol 1 1
1
> input 2 20
> 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
> 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
$ mcr []rowcol 2 20
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
> Simple enough. But the following 2 requirements take it from trivial
> to less trivial!
Sure, sure... if you're a professional C programmer with a BS and 5+
years experience. This was a bit above where I am but once I started it
I had to finish it so here I am. Of course, the second case is the nasty
one and only last night did I find the way forward: I had put the
columns accumulator in the wrong place.
> input = 5 5 23 (cutoff at 23)
> 1 6 11 16 21
> 2 7 12 17 22
> 3 8 13 18 23
> 4 9 14 19
> 5 10 15 20
$ mcr []rowcol 5 5 23
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19
5 10 15 20
> input = 1 10 (no cutoff)
> 1 2 3 4 5 6 7 8 9 10
$ mcr []rowcol 1 10
1 2 3 4 5 6 7 8 9 10
> input = 1 10 3 (cutoff at 3)
> 1 2 3
$ mcr []rowcol 1 10 3
1 2 3
> --------------------------------------------------------------------
> 2) if you don't specify rows and columns, your solution must try
> to calculate them to form a square (same # of rows and columns)
> that includes only 1 to N.
>
> If rows=columns can't be calculated, return message 'not possible'
> --------------------------------------------------------------------
> input = 1 (1 row and 1 column includes 1)
> 1
@compile rowcol.c
KCC: ROWCOL
<PROGRAMMING>ROWCOL.PRE.1
<PROGRAMMING>ROWCOL.FAI.1
FAIL: ROWCOL
@load rowcol
LINK: Loading
@save rowcol
ROWCOL.EXE.2 Saved
@rowcol 1
1
> input = 2
> not possible to output 1-2 where rows=columns
@rowcol 2
Not possible to output 1-2 where rows=columns.
> input = 4 (2 rows and 2 columns includes 4)
> 1 3
> 2 4
@rowcol 4
1 3
2 4
> input = 5
> not possible to output 1-5 where rows=columns
@rowcol 5
Not possible to output 1-5 where rows=columns.
> input = 6
> not possible to output 1-6 where rows=columns
$ cc /define=DEBUG=1 rowcol.c
$ link rowcol
$ mcr []rowcol 6
validInput(): Looking at input value 6
1
Checking next grid...
1 3
2 4
Checking next grid...
1 4
2 5
3 6
Not possible to output 1-6 where rows=columns.
> input = 9
> 1 4 7
> 2 5 8
> 3 6 9
@rowcol 9
1 4 7
2 5 8
3 6 9
> input = 10 11 or 12
> not possible to output 1-10/11/12 where rows=columns
@rowcol 11
Not possible to output 1-11 where rows=columns.
> input = 25
> 1 6 11 16 21
> 2 7 12 17 22
> 3 8 13 18 23
> 4 9 14 19 24
> 5 10 15 20 25
@rowcol 25
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
> * Extra Credit if you determine a formula for this requirement. I kind
> of brute-forced it with 2 loops. As you can see, N = prime isn't
> enough to know if it can be done.
I can't see any. There's probably a better way to do this by putting the
col/rows counter stuff in a function but now that I have it working I
don't want to mess with it.
@rowcol
Please enter 1, 2, or 3 integers (in range 1-30) on the command line.
Ex: ROWCOL 5 5 23
@rowcol 4 5 6 7
Please enter 1, 2, or 3 integers (in range 1-30) on the command line.
Ex: ROWCOL 5 5 23
@rowcol 5 5 0
5, 5, and/or 0 are invalid input. All must be in range 1-30.
@rowcol 5 31 4
5, 31, and/or 4 are invalid input. All must be in range 1-30.
> My code is below.
I have not looked until I posted this. Obviously very different. I have
not used LLM/AI but I had to check my notes for the va_args stuff since
I almost never use it. Runs on/with GCC, Clang, KCC/TOPS-20 and Compaq C
(where I actually wrote it). Define DEBUG if you want to see what it's
doing.
/* rowcols.c
* The user enters 1-3 integers on the command line and the program
* attempts to print a grid pattern based on the numbers given. If
* a STOP NUMBER is given, cut the grid on that number. If one number
* is given, try to make a grid confined by ROWS = COLS, where grid is
* 1 - targetNum, such that this grid prints until targetNum number else
* print "not possible".
*
* Input is as:
* $rowcols ROWS COLUMNS (STOP NUMBER, if used).
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <iso646.h>
#include <stdbool.h> /* Written for Compaq C v6.4, adjust for C23 std */
#define AC_NORMAL "\x1b[m" /* ASCII color normal */
#define AC_RED "\x1b[31m" /* ASCII color red */
#define UPPERBOUNDS 30 /* Largest grid params we deal with, lest wonky output */
bool validInput( int num, ... ); /* Check any/all args against UPPERBOUNDS */
int main( int argc, char *argv[] ) {
int columns, rows; /* Track columns, rows to build grid */
int reqCols, reqRows; /* The number of cols/rows the user requests */
int targetNum; /* Stop num or grid target num (mode dependant) */
bool found; /* Flag if number found in grid */
int foundRows, foundCols; /* Track where targetNum found */
int cntRows, cntCols; /* Count rows/cols used to find num */
/* Determine course of action based on number of command line
* arguments (argc - 1: don't include program name in arg count).
* zero = give usage message
* one = make a grid 1 to targetNum where row = col or
* inform user if not possible
* two = make a grid, row by column as input on the cmd line
* three = as above, but stop at number given as 3rd parameter
* four or more = same as zero, usage message
*/
switch ( argc ) {
case 2:
/* Handle case of one integer given on command line. Check for
* valid input else the tables will not display correctly.
*/
targetNum = atoi( argv[1] );
if ( not validInput( 1, targetNum ) ) {
printf( "%d is invalid input. Please enter 1 - %d\n", targetNum, UPPERBOUNDS );
return EXIT_FAILURE;
}
/* Track if we found targetNum yet */
found = false;
/* Set reqRows = reqCols = 1 and keep stepping up until we hit
* targetNum. Tally cols and rows seen via accumulators. Check if
* equal on arriving at the target number. If yes, print
* table, else print "not possible". We only search until UPPERBOUNDS.
*/
for ( reqRows = 1, reqCols = 1; reqRows <= UPPERBOUNDS; reqRows++, reqCols++ ) {
cntRows = 0;
cntCols = 0;
rows = 1;
do {
columns = 0;
do {
/* Is this higher than the stop number? Blur
* it out if so. We can't cut out entirely
* because we need to print the rest of the
* lower numbers.
*/
if ( ( columns * reqRows + rows ) > targetNum ) {
/* Keep compiler happy when not using debugging output */
;
#ifdef DEBUG
printf( " " );
#endif /* DEBUG */
} else {
/* Increase column count of used columns */
if ( rows == 1 ) cntCols++;
#ifdef DEBUG
printf( "%2d ", columns * reqRows + rows);
#endif /* DEBUG */
/* If we spot the number, note it and where we found it
* but only on the first time.
*/
if ( ( (columns * reqRows + rows) == targetNum ) && !found ) {
found = true;
foundRows = rows;
foundCols = columns + 1;
}
}
} while ( columns++ < reqCols - 1 );
#ifdef DEBUG
printf("\n");
#endif /* DEBUG */
cntRows++;
} while ( rows++ < reqRows );
if ( found ) break;
#ifdef DEBUG
printf( "Checking next grid...\n\n" );
#endif /* DEBUG */
}
if ( (found) and (cntRows == cntCols) ) {
#ifdef DEBUG
printf( "targetNum %d found at row %d column %d.\n", targetNum, foundRows, foundCols );
printf( "Used %d rows, %d columns. Outputting grid.\n\n", cntRows, cntCols );
#endif /* DEBUG */
/* Output the grid we know is correct. targetNum already set */
reqRows = cntRows;
reqCols = cntCols;
rows = 1;
do {
columns = 0;
do {
/* Is this higher than the stop number? Blur
* it out if so. We can't cut out entirely
* because we need to print the rest of the
* lower numbers.
*/
if ( ( columns * reqRows + rows ) > targetNum )
printf( " " );
else
printf( "%2d ", columns * reqRows + rows);
} while ( columns++ < reqCols - 1 );
printf("\n");
} while ( rows++ < reqRows );
} else {
/* If we are here, the special case did not trip, and it's not possible to print grid. */
printf( "%sNot possible to output 1-%d where rows=columns.%s\n",
AC_RED, targetNum, AC_NORMAL );
}
break;
case 3:
/* Handle case of 2 integers given - print full grid */
reqRows = atoi( argv[1] );
reqCols = atoi( argv[2] );
/* First check user's input */
if ( not validInput( 2, reqRows, reqCols ) ) {
printf( "%d and/or %d is invalid input. Both must be in range 1-%d.\n",
reqRows, reqCols, UPPERBOUNDS );
return EXIT_FAILURE;
}
rows = 1;
do {
columns = 0;
do {
printf( "%2d ", columns * reqRows + rows);
} while ( columns++ < reqCols - 1 );
printf( "\n" );
} while ( rows++ < reqRows );
break;
case 4:
/* Handle 3 ints given - stop number case */
reqRows = atoi( argv[1] );
reqCols = atoi( argv[2] );
targetNum = atoi( argv[3] );
/* Check user input */
if ( not validInput( 3, reqRows, reqCols, targetNum ) ) {
printf( "%d, %d, and/or %d are invalid input. All must be in range 1-%d.\n",
reqRows, reqCols, targetNum, UPPERBOUNDS );
return EXIT_FAILURE;
}
rows = 1;
do {
columns = 0;
do {
/* Is this higher than the stop number? Blur
* it out if so. We can't cut out entirely
* because we need to print the rest of the
* lower numbers.
*/
if ( ( columns * reqRows + rows ) > targetNum )
printf( " " );
else
printf( "%2d ", columns * reqRows + rows);
} while ( columns++ < reqCols - 1 );
printf("\n");
} while ( rows++ < reqRows );
break;
default:
/* Give usage if anything else then bail */
printf( "Please enter 1, 2, or 3 integers (in range 1-%d) on the command line.\n",
UPPERBOUNDS );
printf( " Ex: %s 5 5 23\n", argv[0] );
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/* Assume valid, but switch to false at invalid input. Every one
* of these should be 1..UPPERBOUNDS, inclusive.
*/
bool validInput( int num, ... ) {
va_list arguments;
int i;
bool valid;
int chkValue;
va_start( arguments, num );
valid = true;
for ( i = 1; i <= num; i++ ) {
/* We need multiple checks on this value, but calling va_arg
* will jump to the next value (I think). Store it first and
* check that.
*/
chkValue = va_arg( arguments, int );
#ifdef DEBUG
printf( "validInput(): Looking at input value %d\n", chkValue );
#endif /* DEBUG */
if ( (chkValue < 1) or (chkValue > UPPERBOUNDS) ) valid = false;
}
va_end( arguments );
return valid;
}
/* EOF */
Glad to be done with this!
@logout
Good afternoon, JAYJWA ...
End of TOPS20:<SYSTEM>LOGOUT.CMD.1
Killed Job 12, User JAYJWA, TTY121 ATR2:/dev/pts/14, at 25-Feb-2026 15:46:17
Used 0:00:00 in 0:52:08
--
PGP Key ID: 781C A3E2 C6ED 70A6 B356 7AF5 B510 542E D460 5CAE
"The Internet should always be the Wild West!"
[toc] | [prev] | [next] | [standalone]
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2026-02-26 10:05 -0500 |
| Message-ID | <10npnfh$1n445$1@dont-email.me> |
| In reply to | #396698 |
On 2/25/2026 3:56 PM, jayjwa wrote:
> DFS <nospam@dfs.com> writes:
>
>> Kind of goes without saying the solution should handle any row x
>> column input:
...
>> Simple enough. But the following 2 requirements take it from trivial
>> to less trivial!
> Sure, sure... if you're a professional C programmer with a BS and 5+
> years experience.
I'm an rank amateur C coder, with about a year of dedicated experience,
and no formal education in programming.
I write more Python than anything (then duplicate the .py programs in C
for exercise).
What started this little program was I output a list of 200+ school
names by row then column, and didn't like the way it looked.
So I decided to try the column-then-row approach with numbers. Now that
I have it working I put the school names in alpha-order (in an array)
and index into it using the algorithm in this code.
Before and after: https://imgur.com/a/MSSeRxN
> This was a bit above where I am but once I started it
> I had to finish it so here I am.
"I had to finish" ha! I'm with you there.
>> * Extra Credit if you determine a formula for this requirement. I kind
>> of brute-forced it with 2 loops. As you can see, N = prime isn't
>> enough to know if it can be done.
> I can't see any. There's probably a better way to do this by putting the
> col/rows counter stuff in a function but now that I have it working I
> don't want to mess with it.
Give it a week and come back to it and you'll see all kinds of things
you could change/improve. Couple things I would suggest:
1) figure out where to put a break so your program doesn't print blank
lines if stop < rows (such as 8 8 3)
2) remove the 30 limit on the stop
$ ./rcj 10 11 108 says:
10, 11, and/or 108 are invalid input. All must be in range 1-30.
When it should print:
1 11 21 31 41 51 61 71 81 91 101
2 12 22 32 42 52 62 72 82 92 102
3 13 23 33 43 53 63 73 83 93 103
4 14 24 34 44 54 64 74 84 94 104
5 15 25 35 45 55 65 75 85 95 105
6 16 26 36 46 56 66 76 86 96 106
7 17 27 37 47 57 67 77 87 97 107
8 18 28 38 48 58 68 78 88 98 108
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
On my script I took out all the comments and blank lines and print
header rows and combined the two for..loops, and it's 57 LOC.
3 includes, 3 functions
=================================================================================
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void calc_rows_columns(int *rows, int *cols, int nbr) {
for (int i = 1; i < 1000; i++) {
if ((i*i == nbr) || (i*(i+1) < nbr && ((i+1)*(i+1) >= nbr))) {
*rows = i+1;
*cols = i+1;
return;
}
}
printf("%s%d%s\n","Not possible to output 1-", nbr ," where rows =
columns");
exit(0);
}
void output(int rows, int cols, int max)
{
char strmax[10];
sprintf(strmax, "%d", max);
int colwidth = 1 + strlen(strmax);
if (colwidth == 2) {colwidth = 3;}
for (int r = 1; r <= rows; r++) {
if (r <= max) {
int nbr = r;
printf("%*d",colwidth,nbr);
for (int i = 0; i < cols-1; i++) {
nbr += rows;
if (nbr <= max) {
printf("%*d",colwidth,nbr);
}
}
printf("\n");
}
else
{
break;
}
}
}
int main(int argc, char *argv[]) {
int rows, cols, max;
if (argc == 2) {
max = atoi(argv[1]);
calc_rows_columns(&rows, &cols, max);
}
if (argc == 3) {
rows = atoi(argv[1]);
cols = atoi(argv[2]);
max = rows * cols;
}
if (argc == 4) {
rows = atoi(argv[1]);
cols = atoi(argv[2]);
max = atoi(argv[3]);
}
output(rows, cols, max);
return 0;
}
=================================================================================
<snip jayjwa code>
> Glad to be done with this!
Congrats! Good job on seeing it all the way thru.
It was tougher than it looked initially, huh?
FYI: your code compiled cleanly 1st time on gcc
You did a lot of input/validity checking I didn't do. And I like the
red 'error' messages.
I notice you stopped at 30x30, I guess because of your monitor?
I have a wide-screen monitor, and can see 48 x 56:
https://imgur.com/a/PIZKGHH.
> @logout
> Good afternoon, JAYJWA ...
> End of TOPS20:<SYSTEM>LOGOUT.CMD.1
> Killed Job 12, User JAYJWA, TTY121 ATR2:/dev/pts/14, at 25-Feb-2026 15:46:17
> Used 0:00:00 in 0:52:08
Your name is close to my home state of Jawja.
[toc] | [prev] | [next] | [standalone]
| From | jayjwa <jayjwa@atr2.ath.cx.invalid> |
|---|---|
| Date | 2026-02-26 13:20 -0500 |
| Message-ID | <87qzq7nz8o.fsf@atr2.ath.cx> |
| In reply to | #396699 |
DFS <nospam@dfs.com> writes:
> I write more Python than anything (then duplicate the .py programs in
> C for exercise).
Python's great. I did some Java then got distracted by Python then got
distracted by C. Since (almost) all of the systems I use have C, C it is
for now.
> FYI: your code compiled cleanly 1st time on gcc
After I tested it on Linux, I see it did. Before, when I was building
another project (not mine), it errored out once the new GCC landed and
had to be fixed. Checking now, stdbool.h is there but accounts for the
new standard.
> I notice you stopped at 30x30, I guess because of your monitor?
I wanted it to run on TOPS-20, which is headless. That terminal is set
at 24x80 and doesn't resize if you log from something bigger. Actually,
it looks like 21x21 is the largest table it will print without the text
wrapping around and making a mess. You can change the #define at top to
something larger and it should work, assuming large enough screen to
output on.
> Your name is close to my home state of Jawja.
It was my login name in computer class in highschool. It just stuck over
the years for lack of anything better.
--
PGP Key ID: 781C A3E2 C6ED 70A6 B356 7AF5 B510 542E D460 5CAE
"The Internet should always be the Wild West!"
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 17:06 +0000 |
| Message-ID | <10npujd$1o81m$1@dont-email.me> |
| In reply to | #396684 |
On Thu, 19 Feb 2026 16:55:25 -0500, DFS wrote: > Challenge is to output sequential numbers by column then row: [snip] > Kind of goes without saying the solution should handle any row x column > input: > > input rows columns [snip] > -------------------------------------------------------------------- > 2) if you don't specify rows and columns, your solution must try > to calculate them to form a square (same # of rows and columns) > that includes only 1 to N. > > If rows=columns can't be calculated, return message 'not possible' > -------------------------------------------------------------------- [snip] > > * Extra Credit if you determine a formula for this requirement. I kind > of brute-forced it with 2 loops. As you can see, N = prime isn't > enough to know if it can be done. > ----------------------------------------------------------------------- Reasonably trivial. Took me about 20 minutes to get it working. Hint for the "Extra Credit" part: given the requirement that, when only "cut-off" specified, rows must equal columns, then the number of rows and columns are related to the square root of the cut-off value. And, the partial column can only have between 1 and n_rows values in it. So, invalid cut-off values are easy enough to compute by using some simple math. -- Lew Pitcher "In Skills We Trust" Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 17:27 +0000 |
| Message-ID | <10npvq8$1o81m$2@dont-email.me> |
| In reply to | #396700 |
On Thu, 26 Feb 2026 17:06:53 +0000, Lew Pitcher wrote: > On Thu, 19 Feb 2026 16:55:25 -0500, DFS wrote: > >> Challenge is to output sequential numbers by column then row: > [snip] >> Kind of goes without saying the solution should handle any row x column >> input: >> >> input rows columns > [snip] >> -------------------------------------------------------------------- >> 2) if you don't specify rows and columns, your solution must try >> to calculate them to form a square (same # of rows and columns) >> that includes only 1 to N. >> >> If rows=columns can't be calculated, return message 'not possible' >> -------------------------------------------------------------------- > [snip] >> >> * Extra Credit if you determine a formula for this requirement. I kind >> of brute-forced it with 2 loops. As you can see, N = prime isn't >> enough to know if it can be done. >> ----------------------------------------------------------------------- > > Reasonably trivial. Took me about 20 minutes to get it working. > Hint for the "Extra Credit" part: given the requirement that, when > only "cut-off" specified, rows must equal columns, then the > number of rows and columns are related to the square root of the > cut-off value. And, the partial column can only have between 1 > and n_rows values in it. So, invalid cut-off values are easy enough > to compute by using some simple math. Script started on Thu 26 Feb 2026 12:24:39 PM EST 12:24:39 $ ./rowcol 1 1 1 12:24:43 $ ./rowcol 2 3 1 3 5 2 4 6 12:24:51 $ ./rowcol 4 5 17 1 5 9 13 17 2 6 10 14 3 7 11 15 4 8 12 16 12:25:02 $ ./rowcol 17 Cut off value 17 not possible where rows=cols Usage: ./rowcol #_rows #_cols [ cut-off ] or ./rowcol cut-off 12:25:11 $ ./rowcol 19 Cut off value 19 not possible where rows=cols Usage: ./rowcol #_rows #_cols [ cut-off ] or ./rowcol cut-off 12:25:18 $ ./rowcol 21 1 6 11 16 21 2 7 12 17 3 8 13 18 4 9 14 19 5 10 15 20 12:25:21 $ 12:25:21 $ exit exit Script done on Thu 26 Feb 2026 12:25:33 PM EST -- Lew Pitcher "In Skills We Trust" Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2026-02-26 14:31 -0500 |
| Message-ID | <10nq735$1torm$2@dont-email.me> |
| In reply to | #396701 |
On 2/26/2026 12:27 PM, Lew Pitcher wrote:
> On Thu, 26 Feb 2026 17:06:53 +0000, Lew Pitcher wrote:
>
>> On Thu, 19 Feb 2026 16:55:25 -0500, DFS wrote:
>>
>>> Challenge is to output sequential numbers by column then row:
>> [snip]
>>> Kind of goes without saying the solution should handle any row x column
>>> input:
>>>
>>> input rows columns
>> [snip]
>>> --------------------------------------------------------------------
>>> 2) if you don't specify rows and columns, your solution must try
>>> to calculate them to form a square (same # of rows and columns)
>>> that includes only 1 to N.
>>>
>>> If rows=columns can't be calculated, return message 'not possible'
>>> --------------------------------------------------------------------
>> [snip]
>>>
>>> * Extra Credit if you determine a formula for this requirement. I kind
>>> of brute-forced it with 2 loops. As you can see, N = prime isn't
>>> enough to know if it can be done.
>>> -----------------------------------------------------------------------
>>
>> Reasonably trivial. Took me about 20 minutes to get it working.
incredible.
I spent at least 20 minutes just trying to make nested loops work:
for i in range(rows):
for j in range(cols):
I was trapped in my mind by the idea the code had to start like that,
with consecutive loops statements.
But it didn't.
>> Hint for the "Extra Credit" part: given the requirement that, when
>> only "cut-off" specified, rows must equal columns, then the
>> number of rows and columns are related to the square root of the
>> cut-off value.
Yes. I loop thru this many times:
if ((i*i == nbr) || (i*(i+1) < nbr && ((i+1)*(i+1) >= nbr)))
If no hit I consider it not possible.
>> And, the partial column can only have between 1
>> and n_rows values in it. So, invalid cut-off values are easy enough
>> to compute by using some simple math.
Let us know when you figure it out. I'm curious.
> Script done on Thu 26 Feb 2026 12:25:33 PM EST
code?
[toc] | [prev] | [next] | [standalone]
| From | jayjwa <jayjwa@atr2.ath.cx.invalid> |
|---|---|
| Date | 2026-02-26 13:33 -0500 |
| Message-ID | <87ms0vnym3.fsf@atr2.ath.cx> |
| In reply to | #396700 |
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> Hint for the "Extra Credit" part: given the requirement that, when
> only "cut-off" specified, rows must equal columns, then the
> number of rows and columns are related to the square root of the
> cut-off value. And, the partial column can only have between 1
> and n_rows values in it. So, invalid cut-off values are easy enough
> to compute by using some simple math.
I'm not seeing it. You can cleanly take the square root of 1, 4, and 9
but 6 and 7 yield floats around 2.x. 7 works for the puzzle but 6 does
not.
@rowcol 4
1 3
2 4
@rowcol 5
Not possible to output 1-5 where rows=columns.
@rowcol 6
Not possible to output 1-6 where rows=columns.
@rowcol 7
1 4 7
2 5
3 6
@rowcol 9
1 4 7
2 5 8
3 6 9
@rowcol 1
1
@
--
PGP Key ID: 781C A3E2 C6ED 70A6 B356 7AF5 B510 542E D460 5CAE
"The Internet should always be the Wild West!"
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 18:49 +0000 |
| Message-ID | <10nq4k5$1o81m$3@dont-email.me> |
| In reply to | #396704 |
On Thu, 26 Feb 2026 13:33:40 -0500, jayjwa wrote:
> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
>> Hint for the "Extra Credit" part: given the requirement that, when
>> only "cut-off" specified, rows must equal columns, then the
>> number of rows and columns are related to the square root of the
>> cut-off value. And, the partial column can only have between 1
>> and n_rows values in it. So, invalid cut-off values are easy enough
>> to compute by using some simple math.
> I'm not seeing it. You can cleanly take the square root of 1, 4, and 9
> but 6 and 7 yield floats around 2.x. 7 works for the puzzle but 6 does
> not.
>
> @rowcol 4
> 1 3
> 2 4
> @rowcol 5
> Not possible to output 1-5 where rows=columns.
> @rowcol 6
> Not possible to output 1-6 where rows=columns.
> @rowcol 7
> 1 4 7
> 2 5
> 3 6
> @rowcol 9
> 1 4 7
> 2 5 8
> 3 6 9
> @rowcol 1
> 1
> @
unsigned int n_rows, n_cols, cut_off;
/* ... */
/* handle standalone "cut_off" value */
n_rows = n_cols = ceil(sqrt(cut_off));
if ( (cut_off < (n_rows * (n_cols-1)) + 1) || (cut_off > (n_rows * n_cols)) )
{
fprintf(stderr,"Cut off value %u not possible where rows=cols\n",cut_off);
/* error handling as required */
}
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 18:55 +0000 |
| Message-ID | <10nq4vl$1o81m$4@dont-email.me> |
| In reply to | #396705 |
On Thu, 26 Feb 2026 18:49:41 +0000, Lew Pitcher wrote:
> On Thu, 26 Feb 2026 13:33:40 -0500, jayjwa wrote:
>
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>
>>> Hint for the "Extra Credit" part: given the requirement that, when
>>> only "cut-off" specified, rows must equal columns, then the
>>> number of rows and columns are related to the square root of the
>>> cut-off value. And, the partial column can only have between 1
>>> and n_rows values in it. So, invalid cut-off values are easy enough
>>> to compute by using some simple math.
>> I'm not seeing it. You can cleanly take the square root of 1, 4, and 9
>> but 6 and 7 yield floats around 2.x. 7 works for the puzzle but 6 does
>> not.
>>
>> @rowcol 4
>> 1 3
>> 2 4
>> @rowcol 5
>> Not possible to output 1-5 where rows=columns.
>> @rowcol 6
>> Not possible to output 1-6 where rows=columns.
>> @rowcol 7
>> 1 4 7
>> 2 5
>> 3 6
>> @rowcol 9
>> 1 4 7
>> 2 5 8
>> 3 6 9
>> @rowcol 1
>> 1
>> @
>
> unsigned int n_rows, n_cols, cut_off;
> /* ... */
> /* handle standalone "cut_off" value */
> n_rows = n_cols = ceil(sqrt(cut_off));
> if ( (cut_off < (n_rows * (n_cols-1)) + 1) || (cut_off > (n_rows * n_cols)) )
> {
> fprintf(stderr,"Cut off value %u not possible where rows=cols\n",cut_off);
> /* error handling as required */
> }
13:53:54 $ cat cutoff.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
unsigned int n_rows, n_cols, cut_off;
for (cut_off = 1 ; cut_off < 32; ++cut_off)
{
n_rows = n_cols = ceil(sqrt(cut_off));
if ( (cut_off < (n_rows * (n_cols-1)) + 1) || (cut_off > (n_rows * n_cols)) )
printf("Cut off value %u not possible where rows=cols\n",cut_off);
else
printf("Cut off = %u, Rows = %u, Cols = %u\n",cut_off,n_rows,n_cols);
}
return 0;
}
13:54:21 $ ./cutoff
Cut off = 1, Rows = 1, Cols = 1
Cut off value 2 not possible where rows=cols
Cut off = 3, Rows = 2, Cols = 2
Cut off = 4, Rows = 2, Cols = 2
Cut off value 5 not possible where rows=cols
Cut off value 6 not possible where rows=cols
Cut off = 7, Rows = 3, Cols = 3
Cut off = 8, Rows = 3, Cols = 3
Cut off = 9, Rows = 3, Cols = 3
Cut off value 10 not possible where rows=cols
Cut off value 11 not possible where rows=cols
Cut off value 12 not possible where rows=cols
Cut off = 13, Rows = 4, Cols = 4
Cut off = 14, Rows = 4, Cols = 4
Cut off = 15, Rows = 4, Cols = 4
Cut off = 16, Rows = 4, Cols = 4
Cut off value 17 not possible where rows=cols
Cut off value 18 not possible where rows=cols
Cut off value 19 not possible where rows=cols
Cut off value 20 not possible where rows=cols
Cut off = 21, Rows = 5, Cols = 5
Cut off = 22, Rows = 5, Cols = 5
Cut off = 23, Rows = 5, Cols = 5
Cut off = 24, Rows = 5, Cols = 5
Cut off = 25, Rows = 5, Cols = 5
Cut off value 26 not possible where rows=cols
Cut off value 27 not possible where rows=cols
Cut off value 28 not possible where rows=cols
Cut off value 29 not possible where rows=cols
Cut off value 30 not possible where rows=cols
Cut off = 31, Rows = 6, Cols = 6
13:54:25 $
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 19:17 +0000 |
| Message-ID | <10nq68l$1o81m$5@dont-email.me> |
| In reply to | #396706 |
On Thu, 26 Feb 2026 18:55:50 +0000, Lew Pitcher wrote:
> On Thu, 26 Feb 2026 18:49:41 +0000, Lew Pitcher wrote:
>
>> On Thu, 26 Feb 2026 13:33:40 -0500, jayjwa wrote:
>>
>>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>>
>>>> Hint for the "Extra Credit" part: given the requirement that, when
>>>> only "cut-off" specified, rows must equal columns, then the
>>>> number of rows and columns are related to the square root of the
>>>> cut-off value. And, the partial column can only have between 1
>>>> and n_rows values in it. So, invalid cut-off values are easy enough
>>>> to compute by using some simple math.
>>> I'm not seeing it. You can cleanly take the square root of 1, 4, and 9
>>> but 6 and 7 yield floats around 2.x. 7 works for the puzzle but 6 does
>>> not.
>>>
>>> @rowcol 4
>>> 1 3
>>> 2 4
>>> @rowcol 5
>>> Not possible to output 1-5 where rows=columns.
>>> @rowcol 6
>>> Not possible to output 1-6 where rows=columns.
>>> @rowcol 7
>>> 1 4 7
>>> 2 5
>>> 3 6
>>> @rowcol 9
>>> 1 4 7
>>> 2 5 8
>>> 3 6 9
>>> @rowcol 1
>>> 1
>>> @
>>
>> unsigned int n_rows, n_cols, cut_off;
>> /* ... */
>> /* handle standalone "cut_off" value */
>> n_rows = n_cols = ceil(sqrt(cut_off));
>> if ( (cut_off < (n_rows * (n_cols-1)) + 1) || (cut_off > (n_rows * n_cols)) )
>> {
>> fprintf(stderr,"Cut off value %u not possible where rows=cols\n",cut_off);
>> /* error handling as required */
>> }
>
> 13:53:54 $ cat cutoff.c
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
>
> int main(void)
> {
> unsigned int n_rows, n_cols, cut_off;
>
> for (cut_off = 1 ; cut_off < 32; ++cut_off)
> {
> n_rows = n_cols = ceil(sqrt(cut_off));
> if ( (cut_off < (n_rows * (n_cols-1)) + 1) || (cut_off > (n_rows * n_cols)) )
> printf("Cut off value %u not possible where rows=cols\n",cut_off);
> else
> printf("Cut off = %u, Rows = %u, Cols = %u\n",cut_off,n_rows,n_cols);
> }
> return 0;
> }
[snip]
Even simpler, I can remove a redundant test and get
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
unsigned int n_rows, n_cols, cut_off;
for (cut_off = 1 ; cut_off < 32; ++cut_off)
{
n_rows = n_cols = ceil(sqrt(cut_off));
if ( (cut_off < (n_rows * (n_cols-1)) + 1) )
printf("Cut off value %u not possible where rows=cols\n",cut_off);
else
printf("Cut off = %u, Rows = %u, Cols = %u\n",cut_off,n_rows,n_cols);
}
return 0;
}
with the same results.
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 19:34 +0000 |
| Message-ID | <10nq784$1o81m$6@dont-email.me> |
| In reply to | #396700 |
On Thu, 26 Feb 2026 17:06:53 +0000, Lew Pitcher wrote:
> On Thu, 19 Feb 2026 16:55:25 -0500, DFS wrote:
>
>> Challenge is to output sequential numbers by column then row:
> [snip]
>> Kind of goes without saying the solution should handle any row x column
>> input:
>>
>> input rows columns
> [snip]
>> --------------------------------------------------------------------
>> 2) if you don't specify rows and columns, your solution must try
>> to calculate them to form a square (same # of rows and columns)
>> that includes only 1 to N.
>>
>> If rows=columns can't be calculated, return message 'not possible'
>> --------------------------------------------------------------------
> [snip]
>>
>> * Extra Credit if you determine a formula for this requirement. I kind
>> of brute-forced it with 2 loops. As you can see, N = prime isn't
>> enough to know if it can be done.
>> -----------------------------------------------------------------------
>
> Reasonably trivial. Took me about 20 minutes to get it working.
> Hint for the "Extra Credit" part: given the requirement that, when
> only "cut-off" specified, rows must equal columns, then the
> number of rows and columns are related to the square root of the
> cut-off value. And, the partial column can only have between 1
> and n_rows values in it. So, invalid cut-off values are easy enough
> to compute by using some simple math.
/*
** From: DFS <nospam@dfs.com>
** Newsgroups: comp.lang.c
** Subject: Sort of trivial code challenge - may be interesting to you anyway
** Date: Thu, 19 Feb 2026 16:55:25 -0500
** Message-ID: <10n80sc$3soe4$1@dont-email.me>
**
** Challenge is to output sequential numbers by column then row:
** Kind of goes without saying the solution should handle any row x column
** input:
**
** input rows columns
** --------------------------------------------------------------------
** 2) if you don't specify rows and columns, your solution must try
** to calculate them to form a square (same # of rows and columns)
** that includes only 1 to N.
**
** If rows=columns can't be calculated, return message 'not possible'
** --------------------------------------------------------------------
**
** * Extra Credit if you determine a formula for this requirement. I kind
** of brute-forced it with 2 loops. As you can see, N = prime isn't
** enough to know if it can be done.
** -----------------------------------------------------------------------
**
** Solution by Lew Pitcher 2026-02-26
** cc -o rowcol -mtune=native -Wall -std=c99 -pedantic -lm rowcol.c
**
** NB: uses ceil(), sqrt(), and log10() calls from math lib
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
static int StrUint(const char *string, unsigned int *valu);
static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off);
int main(int argc, char *argv[])
{
int status = EXIT_FAILURE,
args_ok = 1;
unsigned int n_rows = 0,
n_cols = 0,
cut_off = 0;
switch (argc)
{
case 4: /* rowcol #rows #cols cutoff */
if ((StrUint(argv[3],&cut_off) == 0) || (cut_off == 0))
{
fprintf(stderr,"Invalid value for cut-off (\"%s\")\n",argv[3]);
args_ok = 0;
}
case 3: /* rowcol #rows #cols */
if ((StrUint(argv[1],&n_rows) == 0) || (n_rows == 0))
{
fprintf(stderr,"Invalid value for # rows (\"%s\")\n",argv[1]);
args_ok = 0;
}
if ((StrUint(argv[2],&n_cols) == 0) || (n_cols == 0))
{
fprintf(stderr,"Invalid value for # columns (\"%s\")\n",argv[2]);
args_ok = 0;
}
break;
case 2: /* rowcol cutoff */
if ((StrUint(argv[1],&cut_off) == 0) || (cut_off == 0))
{
fprintf(stderr,"Invalid value for cut off (\"%s\")\n",argv[1]);
args_ok = 0;
}
else
{
n_rows = n_cols = ceil(sqrt(cut_off));
if ( (cut_off < (n_rows * (n_cols-1)) + 1) )
{
fprintf(stderr,"Cut off value %u not possible where rows=cols\n",cut_off);
args_ok = 0;
}
}
break;
default:
args_ok = 0; /* default error msg is usage message */
break;
}
if (args_ok)
{
dosquare(n_rows,n_cols,cut_off);
status = EXIT_SUCCESS;
}
else fprintf(stderr,"Usage:\t%s #_rows #_cols [ cut-off ]\nor\t%s cut-off\n",argv[0],argv[0]);
return status;
}
/*
** StrUint() parse string for numeric decimal integer value
** returns 0 on failure,
** 1, valu updated on success
*/
static int StrUint(const char *string, unsigned int *valu)
{
int status = 0;
char *eptr;
unsigned long int result;
result = strtoul(string,&eptr,10);
if ((eptr !=string) && (*eptr == 0) && (result <= UINT_MAX))
{
*valu = result;
status = 1;
}
return status;
}
/*
** dosquare() prints out the specified square, with numbers
** ascending in columns
** Notes:
** 1) square printed with equal field_width, so that all cols
** have same width
** 2) function does not return a value
*/
static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
{
unsigned int field_width; /* for equal spacing of output data */
if (cut_off == 0) cut_off = n_rows * n_cols;
field_width = ceil(log10(cut_off)) + 1;
for (unsigned int row = 0; row < n_rows; ++row)
{
for (unsigned int col = 0; col < n_cols; ++col)
{
unsigned int valu = 1 + row + (col * n_rows);
if (valu <= cut_off)
printf("%-*u",field_width,valu);
}
puts("");
}
}
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-02-26 20:01 +0000 |
| Message-ID | <10nq8qf$1tsk7$1@dont-email.me> |
| In reply to | #396709 |
On Thu, 26 Feb 2026 19:34:29 +0000, Lew Pitcher wrote:
> On Thu, 26 Feb 2026 17:06:53 +0000, Lew Pitcher wrote:
>
>> On Thu, 19 Feb 2026 16:55:25 -0500, DFS wrote:
>>
>>> Challenge is to output sequential numbers by column then row:
>> [snip]
>>> Kind of goes without saying the solution should handle any row x column
>>> input:
>>>
>>> input rows columns
>> [snip]
>>> --------------------------------------------------------------------
>>> 2) if you don't specify rows and columns, your solution must try
>>> to calculate them to form a square (same # of rows and columns)
>>> that includes only 1 to N.
>>>
>>> If rows=columns can't be calculated, return message 'not possible'
>>> --------------------------------------------------------------------
>> [snip]
>>>
>>> * Extra Credit if you determine a formula for this requirement. I kind
>>> of brute-forced it with 2 loops. As you can see, N = prime isn't
>>> enough to know if it can be done.
>>> -----------------------------------------------------------------------
>>
>> Reasonably trivial. Took me about 20 minutes to get it working.
>> Hint for the "Extra Credit" part: given the requirement that, when
>> only "cut-off" specified, rows must equal columns, then the
>> number of rows and columns are related to the square root of the
>> cut-off value. And, the partial column can only have between 1
>> and n_rows values in it. So, invalid cut-off values are easy enough
>> to compute by using some simple math.
>
> /*
> ** From: DFS <nospam@dfs.com>
> ** Newsgroups: comp.lang.c
> ** Subject: Sort of trivial code challenge - may be interesting to you anyway
> ** Date: Thu, 19 Feb 2026 16:55:25 -0500
> ** Message-ID: <10n80sc$3soe4$1@dont-email.me>
> **
> ** Challenge is to output sequential numbers by column then row:
> ** Kind of goes without saying the solution should handle any row x column
> ** input:
> **
> ** input rows columns
> ** --------------------------------------------------------------------
> ** 2) if you don't specify rows and columns, your solution must try
> ** to calculate them to form a square (same # of rows and columns)
> ** that includes only 1 to N.
> **
> ** If rows=columns can't be calculated, return message 'not possible'
> ** --------------------------------------------------------------------
> **
> ** * Extra Credit if you determine a formula for this requirement. I kind
> ** of brute-forced it with 2 loops. As you can see, N = prime isn't
> ** enough to know if it can be done.
> ** -----------------------------------------------------------------------
> **
> ** Solution by Lew Pitcher 2026-02-26
> ** cc -o rowcol -mtune=native -Wall -std=c99 -pedantic -lm rowcol.c
> **
> ** NB: uses ceil(), sqrt(), and log10() calls from math lib
> */
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
> #include <limits.h>
>
> static int StrUint(const char *string, unsigned int *valu);
> static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off);
>
>
> int main(int argc, char *argv[])
> {
> int status = EXIT_FAILURE,
> args_ok = 1;
> unsigned int n_rows = 0,
> n_cols = 0,
> cut_off = 0;
>
> switch (argc)
> {
> case 4: /* rowcol #rows #cols cutoff */
> if ((StrUint(argv[3],&cut_off) == 0) || (cut_off == 0))
> {
> fprintf(stderr,"Invalid value for cut-off (\"%s\")\n",argv[3]);
> args_ok = 0;
> }
> case 3: /* rowcol #rows #cols */
> if ((StrUint(argv[1],&n_rows) == 0) || (n_rows == 0))
> {
> fprintf(stderr,"Invalid value for # rows (\"%s\")\n",argv[1]);
> args_ok = 0;
> }
> if ((StrUint(argv[2],&n_cols) == 0) || (n_cols == 0))
> {
> fprintf(stderr,"Invalid value for # columns (\"%s\")\n",argv[2]);
> args_ok = 0;
> }
> break;
>
> case 2: /* rowcol cutoff */
> if ((StrUint(argv[1],&cut_off) == 0) || (cut_off == 0))
> {
> fprintf(stderr,"Invalid value for cut off (\"%s\")\n",argv[1]);
> args_ok = 0;
> }
> else
> {
> n_rows = n_cols = ceil(sqrt(cut_off));
For any cut-off, the biggest allowable square has rows and columns
equal to the square root of the cut-off, rounded up to the nearest integer.
But, not all cut-offs are allowed in a square that size.
Looking at a few squares and cut-offs, we see
Size Min Cutoff Max Cutoff
1x1 1 1
2x2 3 4
3x3 7 9
4x4 13 16
5x5 21 25
We can see a relationship here:
Where row == col == ceiling(square_root(cut-off))
- the maximum cut-off for any square is row x col
- the minimum cut-off for any square is (row x col) - (row - 1)
or (row x col) - row + 1
Now, as we derive row and col from the square root of cut-off,
we know that cut-off will never be greater than row x col.
And, that just leaves us with the minimum to check.
> if ( (cut_off < (n_rows * (n_cols-1)) + 1) )
> {
> fprintf(stderr,"Cut off value %u not possible where rows=cols\n",cut_off);
> args_ok = 0;
> }
> }
> break;
>
> default:
> args_ok = 0; /* default error msg is usage message */
> break;
> }
>
> if (args_ok)
> {
> dosquare(n_rows,n_cols,cut_off);
> status = EXIT_SUCCESS;
> }
> else fprintf(stderr,"Usage:\t%s #_rows #_cols [ cut-off ]\nor\t%s cut-off\n",argv[0],argv[0]);
>
> return status;
> }
>
> /*
> ** StrUint() parse string for numeric decimal integer value
> ** returns 0 on failure,
> ** 1, valu updated on success
> */
> static int StrUint(const char *string, unsigned int *valu)
> {
> int status = 0;
> char *eptr;
> unsigned long int result;
>
> result = strtoul(string,&eptr,10);
>
> if ((eptr !=string) && (*eptr == 0) && (result <= UINT_MAX))
> {
> *valu = result;
> status = 1;
> }
> return status;
> }
>
> /*
> ** dosquare() prints out the specified square, with numbers
> ** ascending in columns
> ** Notes:
> ** 1) square printed with equal field_width, so that all cols
> ** have same width
> ** 2) function does not return a value
> */
> static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
> {
> unsigned int field_width; /* for equal spacing of output data */
>
> if (cut_off == 0) cut_off = n_rows * n_cols;
> field_width = ceil(log10(cut_off)) + 1;
>
> for (unsigned int row = 0; row < n_rows; ++row)
> {
> for (unsigned int col = 0; col < n_cols; ++col)
> {
> unsigned int valu = 1 + row + (col * n_rows);
> if (valu <= cut_off)
> printf("%-*u",field_width,valu);
> }
> puts("");
> }
> }
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2026-03-06 10:36 -0500 |
| Message-ID | <10oes9f$pas6$2@dont-email.me> |
| In reply to | #396709 |
On 2/26/2026 2:34 PM, Lew Pitcher wrote:
> static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
> {
> unsigned int field_width; /* for equal spacing of output data */
>
> if (cut_off == 0) cut_off = n_rows * n_cols;
> field_width = ceil(log10(cut_off)) + 1;
>
> for (unsigned int row = 0; row < n_rows; ++row)
> {
> for (unsigned int col = 0; col < n_cols; ++col)
> {
> unsigned int valu = 1 + row + (col * n_rows);
> if (valu <= cut_off)
> printf("%-*u",field_width,valu);
> }
> puts("");
> }
> }
I found a nit:
with 1-column inputs like 10 1 3 or 100 1 25, your program prints (row
- cutoff) blank lines after the cutoff.
prompt$./rc-lew 10 1 3
1
2
3
prompt$
Adding
if (valu > cut_off) {exit(0);}
right after
puts("");
fixes it.
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-03-06 17:38 +0000 |
| Message-ID | <10of3ds$n5hk$2@dont-email.me> |
| In reply to | #396822 |
On Fri, 06 Mar 2026 10:36:19 -0500, DFS wrote:
> On 2/26/2026 2:34 PM, Lew Pitcher wrote:
>
>
>> static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
>> {
>> unsigned int field_width; /* for equal spacing of output data */
>>
>> if (cut_off == 0) cut_off = n_rows * n_cols;
>> field_width = ceil(log10(cut_off)) + 1;
>>
>> for (unsigned int row = 0; row < n_rows; ++row)
>> {
>> for (unsigned int col = 0; col < n_cols; ++col)
>> {
>> unsigned int valu = 1 + row + (col * n_rows);
>> if (valu <= cut_off)
>> printf("%-*u",field_width,valu);
>> }
>> puts("");
>> }
>> }
>
>
> I found a nit:
>
> with 1-column inputs like 10 1 3 or 100 1 25, your program prints (row
> - cutoff) blank lines after the cutoff.
[snip]
Yes, I'm aware :-)
I fixed it in a later version, which I have not posted yet.
The restricted-C version I posted in response to Tim Rentsch's counter-counter
challenge behaves properly (albeit, with the UB that he identified).
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2026-03-06 17:48 +0000 |
| Message-ID | <10of423$n5hk$3@dont-email.me> |
| In reply to | #396831 |
On Fri, 06 Mar 2026 17:38:04 +0000, Lew Pitcher wrote:
> On Fri, 06 Mar 2026 10:36:19 -0500, DFS wrote:
>
>> On 2/26/2026 2:34 PM, Lew Pitcher wrote:
>>
>>
>>> static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
>>> {
>>> unsigned int field_width; /* for equal spacing of output data */
>>>
>>> if (cut_off == 0) cut_off = n_rows * n_cols;
>>> field_width = ceil(log10(cut_off)) + 1;
>>>
>>> for (unsigned int row = 0; row < n_rows; ++row)
>>> {
>>> for (unsigned int col = 0; col < n_cols; ++col)
>>> {
>>> unsigned int valu = 1 + row + (col * n_rows);
>>> if (valu <= cut_off)
>>> printf("%-*u",field_width,valu);
>>> }
>>> puts("");
>>> }
>>> }
>>
>>
>> I found a nit:
>>
>> with 1-column inputs like 10 1 3 or 100 1 25, your program prints (row
>> - cutoff) blank lines after the cutoff.
> [snip]
>
> Yes, I'm aware :-)
>
> I fixed it in a later version, which I have not posted yet.
And, here it is...
/*
** From: DFS <nospam@dfs.com>
** Newsgroups: comp.lang.c
** Subject: Sort of trivial code challenge - may be interesting to you anyway
** Date: Thu, 19 Feb 2026 16:55:25 -0500
** Message-ID: <10n80sc$3soe4$1@dont-email.me>
**
** Challenge is to output sequential numbers by column then row:
** Kind of goes without saying the solution should handle any row x column
** input:
**
** input rows columns
** --------------------------------------------------------------------
** 1) must be able to cut the output off at any arbitrary value
** lower than rows x columns
** --------------------------------------------------------------------
** 2) if you don't specify rows and columns, your solution must try
** to calculate them to form a square (same # of rows and columns)
** that includes only 1 to N.
**
** If rows=columns can't be calculated, return message 'not possible'
** --------------------------------------------------------------------
**
** * Extra Credit if you determine a formula for this requirement. I kind
** of brute-forced it with 2 loops. As you can see, N = prime isn't
** enough to know if it can be done.
** -----------------------------------------------------------------------
**
** From: Tim Rentsch <tr.17687@z991.linuxsc.com>
** Newsgroups: comp.lang.c
** Subject: Re: Sort of trivial code challenge - may be interesting to you anyway
** Date: Mon, 02 Mar 2026 00:44:57 -0800
** Message-ID: <86v7feei2e.fsf@linuxsc.com>
**
** Here is a counter challenge to make things more interesting: as above,
** but don't use nested loops (or goto's, etc).
**
** -----------------------------------------------------------------------
**
** From: Michael S <already5chosen@yahoo.com>
** Newsgroups: comp.lang.c
** Subject: Re: Sort of trivial code challenge - may be interesting to you anyway
** Date: Mon, 2 Mar 2026 11:07:20 +0200
** Message-ID: <20260302110720.00007698@yahoo.com>
**
** Another counter challenge could have been to commpletely avoid loops/goto.
**
** ==========================================================================
**
** DFS challenge; solution by Lew Pitcher 2026-02-26
** cc -o rowcol_CLC -mtune=native -Wall -std=c99 -pedantic -lm rowcol_CLC.c
**
** Tim Rentsch counter-challenge; solution by Lew Pitcher 2026-03-03
** cc -o rowcol_CLC -mtune=native -Wall -std=c99 -pedantic -lm -DNO_NESTED_LOOPS rowcol_CLC.c
**
** Michael S counter-challenge; solution by Lew Pitcher 2026-03-03
** cc -o rowcol_CLC -mtune=native -Wall -std=c99 -pedantic -lm -DNO_LOOPS rowcol_CLC.c
**
** NB: solutions use ceil(), sqrt(), and log10() calls from math lib
**
** This code released into the public domain. Lew Pitcher, 2026-03-04
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
/*
** define RIGHT_ALIGN to right-align all numeric results
** otherwise, numeric results will align to the left
*/
#ifdef RIGHT_ALIGN
#define FORMAT "%*u"
#else
#define FORMAT "%-*u"
#endif
static int StrUint(const char *string, unsigned int *valu);
static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off);
int main(int argc, char *argv[])
{
int status = EXIT_FAILURE,
args_ok = 1;
unsigned int n_rows = 0,
n_cols = 0,
cut_off = 0;
switch (argc)
{
case 4: /* rowcol #rows #cols cutoff */
if ((StrUint(argv[3],&cut_off) == 0) || (cut_off == 0))
{
fprintf(stderr,"Invalid value for cut-off (\"%s\")\n",argv[3]);
args_ok = 0;
}
case 3: /* rowcol #rows #cols */
if ((StrUint(argv[1],&n_rows) == 0) || (n_rows == 0))
{
fprintf(stderr,"Invalid value for # rows (\"%s\")\n",argv[1]);
args_ok = 0;
}
if ((StrUint(argv[2],&n_cols) == 0) || (n_cols == 0))
{
fprintf(stderr,"Invalid value for # columns (\"%s\")\n",argv[2]);
args_ok = 0;
}
/* cut-off value must occur within table bounds */
if (cut_off)
{
if (cut_off > n_rows * n_cols)
{
fprintf(stderr,"cut off value %u not found in table\n",cut_off);
args_ok = 0;
}
}
else cut_off = n_rows * n_cols;
break;
case 2: /* rowcol cutoff */
if ((StrUint(argv[1],&cut_off) == 0) || (cut_off == 0))
{
fprintf(stderr,"Invalid value for cut off (\"%s\")\n",argv[1]);
args_ok = 0;
}
else
{
/*
** Compute n_rows and n_cols, and validate that cut_off
** value occurs as last entry in final column
**
** ----- Narrative -----
** As problem definition states that, for this configuration,
** n_rows must equal n_cols, and that n_rows * n_cols must
** include the cut_off value, we first approximate the value
** of n_rows and n_cols by taking the square root of cut_off
** and rounding that value up to the nearest integer. This
** guarantees that n_rows * n_cols is the smallest square
** that will contain the cut_off value.
**
** But, this rounded value might be too big to place cut_off
** in the last column. So, we compute the first entry in
** the last column, and make sure that cut_off is not less
** than that value (if it is, then cut_off occurs in a column
** prior to the last column, and violates the constraints
** of this configuration).
**
** FWIW, because of the way we compute n_rows and n_cols,
** we know that cut_off will never /exceed/ n_rows * n_cols.
*/
n_rows = n_cols = ceil(sqrt(cut_off));
if ( (cut_off < (n_rows * (n_cols-1)) + 1) )
{
fprintf(stderr,"Cut off value %u not possible where rows=cols\n",cut_off);
args_ok = 0;
}
}
break;
default:
args_ok = 0; /* default error msg is usage message */
break;
}
if (args_ok) /* then our inputs are valid and within our constraints */
{
if (cut_off == 0) cut_off = n_rows * n_cols;
dosquare(n_rows,n_cols,cut_off);
status = EXIT_SUCCESS;
}
else fprintf(stderr,"Usage:\t%s #_rows #_cols [ cut-off ]\nor\t%s cut-off\n",argv[0],argv[0]);
return status;
}
/*
** StrUint() parse string for numeric decimal integer value
** returns 0 on failure,
** 1, valu updated on success
*/
static int StrUint(const char *string, unsigned int *valu)
{
int status = 0;
char *eptr;
unsigned long int result;
result = strtoul(string,&eptr,10);
/*
** NB: will honour the "-" negative flag, resulting in an extremely
** large unsigned value. We will consider this an error, detected
** by a result greater than UINT_MAX.
*/
if ((eptr !=string) && (*eptr == 0) && (result <= UINT_MAX))
{
*valu = result;
status = 1;
}
return status;
}
#ifdef NO_LOOPS
/*
** =================== NO LOOPS at all, so we go recursive ===================
*/
static int oneCol(unsigned int col, unsigned int row, unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
{
unsigned int field_width = ceil(log10(cut_off)) + 1;
unsigned int valu = 1 + row + (col * n_rows);
int want_eol = 0;
if (col > 0) want_eol = oneCol(col-1,row,n_rows,n_cols,cut_off);
if (valu <= cut_off)
{
printf(FORMAT,field_width,valu);
want_eol = 1;
}
return want_eol;
}
static void oneRow(unsigned int row, unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
{
if (row > 0) oneRow(row-1,n_rows,n_cols,cut_off);
if (oneCol(n_cols,row,n_rows,n_cols,cut_off)) putchar('\n');
}
static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
{
oneRow(n_rows-1,n_rows,n_cols,cut_off);
}
#else
#ifdef NO_NESTED_LOOPS
/*
** =================== NO NESTED LOOPS at all, so we go linear ===================
*/
static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
{
unsigned int field_width = ceil(log10(cut_off)) + 1;
int max = n_rows * n_cols,
want_eol = 0;
for (unsigned int count = 0; count < max; ++count)
{
unsigned int row, col, valu;
row = count / n_cols;
col = count % n_cols;
if (col == 0) want_eol = 0;
valu = 1 + row + (col * n_rows);
if (valu <= cut_off)
{
printf(FORMAT,field_width,valu);
want_eol = 1;
}
if ((col == n_cols - 1) && (want_eol)) putchar('\n');
}
}
#else
/*
** =================== NO RESTRICTIONS, so we use nested loops ===================
*/
static void dosquare(unsigned int n_rows, unsigned int n_cols, unsigned int cut_off)
{
unsigned int field_width = ceil(log10(cut_off)) + 1;
for (unsigned int row = 0; row < n_rows; ++row)
{
int want_eol = 0;
for (unsigned int col = 0; col < n_cols; ++col)
{
unsigned int valu = 1 + row + (col * n_rows);
if (valu <= cut_off)
{
printf(FORMAT,field_width,valu);
want_eol = 1;
}
}
if (want_eol) putchar('\n');
}
}
#endif
#endif
[snip]
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2026-02-27 00:12 +0000 |
| Message-ID | <10nqnhq$22rul$1@dont-email.me> |
| In reply to | #396684 |
On 19/02/2026 21:55, DFS wrote:
> Challenge is to output sequential numbers by column then row:
> input = 25
> 1 6 11 16 21
> 2 7 12 17 22
> 3 8 13 18 23
> 4 9 14 19 24
> 5 10 15 20 25
>
> input = 26
> not possible to output 1-26 where rows=columns
>
> input = 27
> not possible to output 1-27 where rows=columns
>
> etc
>
>
> * Extra Credit if you determine a formula for this requirement. I kind
> of brute-forced it with 2 loops. As you can see, N = prime isn't
> enough to know if it can be done.
> -----------------------------------------------------------------------
>
>
> My code is below.
>
> Look for 'core routine' to see the master output algorithm
> Requirement 1 is part of the core routine
> Requirement 2 is the function "calc_rows_columns()"
>
> If you try this, don't feel obligated to output the column headers as I
> did. It's a nice-to-have.
These don't appear in your examples, only in your C solution.
I did my version before I looked at your C code, as you said we weren't
allowed to look!
I used my scripting language to come up with the solution below for when
there is a single N input, as that looked more challenging.
It took 20 minutes to get output corresponding more or less to your
examples. (While columns are lined up, they don't exactly match in white
space esp. at the start of each line; see example after the code.)
Once the algorithm is done, rewriting to any other language, including
C, would be trivial.
--------------------------------------
func getrows(n)=
m:=s:=1
while s<n do ++m; s:=sqr(m) end
m
end
proc solve(n)=
rows:=cols:=getrows(n)
size:=rows*cols
println "input =", n
if size-n >= rows then
fprintln "not possible to output 1-# where rows=columns", n
println
return
end
fmt:=tostr(tostr(n).len+1)
for r in 1..rows do
i:=r
for c in 1..cols when i<=n do
print i:fmt # fmt = eg. "3" when N is 10..99
i+:=rows
end
println
end
println
end
for n in 1..27 do
solve(n)
end
----------------
Outputs for N = 25 and 26:
input = 25
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
input = 26
not possible to output 1-26 where rows=columns
[toc] | [prev] | [next] | [standalone]
| From | Janis Papanagnou <janis_papanagnou@hotmail.com> |
|---|---|
| Date | 2026-03-06 06:37 +0100 |
| Subject | [OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) |
| Message-ID | <b95dc8ac-5d0b-4170-87ff-4a3a2fc024c8@hotmail.com> |
| In reply to | #396711 |
On 27.02.26 01:12, Bart wrote:
> [...]
> I used my scripting language to come up with the solution below for when
> there is a single N input, as that looked more challenging.
>
> It took 20 minutes to get output corresponding more or less to your
> examples. (While columns are lined up, they don't exactly match in white
> space esp. at the start of each line; see example after the code.)
>
> Once the algorithm is done, rewriting to any other language, including
> C, would be trivial.
Just one question about your algorithm; why this line...?
for c in 1..cols when i<=n do
Assuming that 'when' works like 'while', it seems to me that
while i<=n do
should suffice. - No?
Janis
>
> --------------------------------------
> func getrows(n)=
> m:=s:=1
> while s<n do ++m; s:=sqr(m) end
> m
> end
>
> proc solve(n)=
> rows:=cols:=getrows(n)
> size:=rows*cols
>
> println "input =", n
>
> if size-n >= rows then
> fprintln "not possible to output 1-# where rows=columns", n
> println
> return
> end
>
> fmt:=tostr(tostr(n).len+1)
>
> for r in 1..rows do
> i:=r
> for c in 1..cols when i<=n do
> print i:fmt # fmt = eg. "3" when N is 10..99
> i+:=rows
> end
> println
> end
> println
> end
>
> for n in 1..27 do
> solve(n)
> end
>
> [...]
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2026-03-06 15:48 +0000 |
| Subject | Re: [OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) |
| Message-ID | <10oet0c$pb3m$1@dont-email.me> |
| In reply to | #396812 |
On 06/03/2026 05:37, Janis Papanagnou wrote:
> On 27.02.26 01:12, Bart wrote:
>> [...]
>> I used my scripting language to come up with the solution below for
>> when there is a single N input, as that looked more challenging.
>>
>> It took 20 minutes to get output corresponding more or less to your
>> examples. (While columns are lined up, they don't exactly match in
>> white space esp. at the start of each line; see example after the code.)
>>
>> Once the algorithm is done, rewriting to any other language, including
>> C, would be trivial.
>
> Just one question about your algorithm; why this line...?
>
> for c in 1..cols when i<=n do
>
> Assuming that 'when' works like 'while', it seems to me that
>
> while i<=n do
>
> should suffice. - No?
'when' is a per-iteration guard. It skips only that iteration when
false, unlike 'for-while' in Algol68 which terminates the loop.
In C terms it's more like for()if(){}.
('if' is not used as 'if' can be an expression-starter and there are
some grammatical issues.)
[toc] | [prev] | [next] | [standalone]
| From | Janis Papanagnou <janis_papanagnou@hotmail.com> |
|---|---|
| Date | 2026-03-06 18:17 +0100 |
| Subject | Re: [OT] Bart's scripting language solution (was Re: Sort of trivial code challenge - may be interesting to you anyway) |
| Message-ID | <10of27o$rndi$1@dont-email.me> |
| In reply to | #396823 |
On 06.03.26 16:48, Bart wrote:
> On 06/03/2026 05:37, Janis Papanagnou wrote:
>> On 27.02.26 01:12, Bart wrote:
>>> [...]
>>> I used my scripting language to come up with the solution below for
>>> when there is a single N input, as that looked more challenging.
>>>
>>> It took 20 minutes to get output corresponding more or less to your
>>> examples. (While columns are lined up, they don't exactly match in
>>> white space esp. at the start of each line; see example after the code.)
>>>
>>> Once the algorithm is done, rewriting to any other language,
>>> including C, would be trivial.
>>
>> Just one question about your algorithm; why this line...?
>>
>> for c in 1..cols when i<=n do
>>
>> Assuming that 'when' works like 'while', it seems to me that
>>
>> while i<=n do
>>
>> should suffice. - No?
>
> 'when' is a per-iteration guard. It skips only that iteration when
> false, unlike 'for-while' in Algol68 which terminates the loop.
Ah, okay, I see. A condition for exceptional cases during the loop.
My question on the algorithm still remains; can't that for/when loop
be replaced by the simpler while condition? - It appears to me that
the simpler 'while' condition is sufficient here to express what's
algorithmically needed.
Janis
>
> In C terms it's more like for()if(){}.
>
> ('if' is not used as 'if' can be an expression-starter and there are
> some grammatical issues.)
>
>
[toc] | [prev] | [next] | [standalone]
Page 1 of 11 [1] 2 3 … 11 Next page →
Back to top | Article view | comp.lang.c
csiph-web