A simple number puzzle

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

A simple number puzzle

Post by HansV »

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

28x + 30y + 31z = 365

where x, y, and z are positive whole numbers.
Solutions in spoiler tags, please.
Best wishes,
Hans

User avatar
Leif
Administrator
Posts: 7192
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: A simple number puzzle

Post by Leif »

Spoiler
x = 1
y = 4
z = 7
Leif

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: A simple number puzzle

Post by HansV »

@Leif: correct! :wine:
Best wishes,
Hans

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

Re: A simple number puzzle

Post by AlanMiller »

I'm sure this came up some months ago. :confused:

Alan

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: A simple number puzzle

Post by HansV »

Not here in the Puzzles forum during the last year-and-a-half (I didn't check further back).
Best wishes,
Hans

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

Re: A simple number puzzle

Post by John Gray »

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

Venison is quiet deer, and quite dear.

User avatar
Leif
Administrator
Posts: 7192
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: A simple number puzzle

Post by Leif »

AlanMiller wrote:I'm sure this came up some months ago. :confused:
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

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

Re: A simple number puzzle

Post by AlanMiller »

Leif is again correct. :evilgrin:

Alan

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: A simple number puzzle

Post by HansV »

Ah, OK :blush:
Best wishes,
Hans

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

Re: A simple number puzzle

Post by AlanMiller »

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. :bravo:

Alan

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

Re: A simple number puzzle

Post by John Gray »

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

Venison is quiet deer, and quite dear.

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: A simple number puzzle

Post by HansV »

John Gray wrote:Code: (...)
That is very clever, John. It would have taken me months to come up with that. Nice to have a second solution... :thumbup:
Best wishes,
Hans