## A simple number puzzle

HansV
Posts: 74393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

### A simple number puzzle

From today's The Guardian:
Find a solution to the equation

28x + 30y + 31z = 365

where x, y, and z are positive whole numbers.
Regards,
Hans

Leif
Posts: 7300
Joined: 16 Jan 2010, 08:21
Location: UK/France

### Re: A simple number puzzle

Spoiler
x = 1
y = 4
z = 7
Leif.

HansV
Posts: 74393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

### Re: A simple number puzzle

@Leif: correct!
Regards,
Hans

AlanMiller
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

HansV
Posts: 74393
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

John Gray
PlatinumLounger
Posts: 5159
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

### Re: A simple number puzzle

Code:
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 ``````
Solutions:
Spoiler
X is 1, Y is 4, Z is 7
X is 2, Y is 1, Z is 9
John Gray

Don't learn about safety by accident.

Leif
Posts: 7300
Joined: 16 Jan 2010, 08:21
Location: UK/France

### 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.

AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

### Re: A simple number puzzle

Leif is again correct.

Alan

HansV
Posts: 74393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

### Re: A simple number puzzle

Ah, OK
Regards,
Hans

AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

### Re: A simple number puzzle

John Gray wrote:Code:
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 ``````
Solutions:
Spoiler
X is 1, Y is 4, Z is 7
X is 2, Y is 1, Z is 9
I'd forgotten about your batch file prowess. I'll have to analyze it and see how it ticks.

Alan

John Gray
PlatinumLounger
Posts: 5159
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

### Re: A simple number puzzle

AlanMiller wrote:I'd forgotten about your batch file prowess. I'll have to analyze it and see how it ticks.
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!
John Gray

Don't learn about safety by accident.

HansV