Solutions in spoiler tags, please.Find a solution to the equation
28x + 30y + 31z = 365
where x, y, and z are positive whole numbers.
A simple number puzzle
-
- Administrator
- Posts: 77287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
A simple number puzzle
From today's The Guardian:
Regards,
Hans
Hans
-
- Administrator
- Posts: 7138
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
-
- Administrator
- Posts: 77287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- BronzeLounger
- Posts: 1545
- Joined: 26 Jan 2010, 11:36
- Location: Melbourne, Australia
Re: A simple number puzzle
I'm sure this came up some months ago. 
Alan

Alan
-
- Administrator
- Posts: 77287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: A simple number puzzle
Not here in the Puzzles forum during the last year-and-a-half (I didn't check further back).
Regards,
Hans
Hans
-
- PlatinumLounger
- Posts: 5325
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: A simple number puzzle
Code:
Solutions:
Spoiler
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /l %%x in (1,1,13) do (
for /l %%y in (1,1,13) do (
for /l %%z in (1,1,12) do (
set /a prod=28*%%x
set /a prod+=30*%%y
set /a prod+=31*%%z
if !prod!==365 echo X is %%x, Y is %%y, Z is %%z
)
)
)
endlocal
pause
Spoiler
X is 1, Y is 4, Z is 7
X is 2, Y is 1, Z is 9
X is 2, Y is 1, Z is 9
John Gray
The Stone Age didn't end because we ran out of stones.
The Stone Age didn't end because we ran out of stones.
-
- Administrator
- Posts: 7138
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: A simple number puzzle
AlanMiller wrote:I'm sure this came up some months ago.
HansV wrote:Not here in the Puzzles forum during the last year-and-a-half (I didn't check further back).
Spoiler
I suspect Alan is obliquely referring to what the numbers (can) relate to...
Leif
-
- BronzeLounger
- Posts: 1545
- Joined: 26 Jan 2010, 11:36
- Location: Melbourne, Australia
Re: A simple number puzzle
Leif is again correct. 
Alan

Alan
-
- Administrator
- Posts: 77287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- BronzeLounger
- Posts: 1545
- Joined: 26 Jan 2010, 11:36
- Location: Melbourne, Australia
Re: A simple number puzzle
I'd forgotten about your batch file prowess. I'll have to analyze it and see how it ticks.John Gray wrote:Code:Solutions:Spoiler
Code: Select all
@echo off setlocal enabledelayedexpansion for /l %%x in (1,1,13) do ( for /l %%y in (1,1,13) do ( for /l %%z in (1,1,12) do ( set /a prod=28*%%x set /a prod+=30*%%y set /a prod+=31*%%z if !prod!==365 echo X is %%x, Y is %%y, Z is %%z ) ) ) endlocal pause
Spoiler
X is 1, Y is 4, Z is 7
X is 2, Y is 1, Z is 9

Alan
-
- PlatinumLounger
- Posts: 5325
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: A simple number puzzle
It's not particularly difficult and entirely 'brute force', without any refinements. The upper bounds of the FOR loops assume that the values of the other two variables were zeros. It could almost have been ported from Fortran!AlanMiller wrote:I'd forgotten about your batch file prowess. I'll have to analyze it and see how it ticks.![]()
John Gray
The Stone Age didn't end because we ran out of stones.
The Stone Age didn't end because we ran out of stones.
-
- Administrator
- Posts: 77287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: A simple number puzzle
That is very clever, John. It would have taken me months to come up with that. Nice to have a second solution...John Gray wrote:Code: (...)

Regards,
Hans
Hans