Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 Re: Exercises » New Years Problem » 2017-01-16 00:20:58

But I thought your code was about as short as it could get!

#2 Re: Exercises » New Years Problem » 2017-01-14 02:43:51

Very yummy lunch, thanks, followed late afternoon by even yummier birthday party food!

That's a neat trick, using %n to choose specific output lines! It does away with introducing another variable, unlike the following variations of your code...







#3 Re: Exercises » New Years Problem » 2017-01-13 14:12:34

Yes, the functional approach is what I was trying for.

Just having a go now with your code to get it to return the x count as well. That would be via Length, I guess. 

...but lunch first.

...and may have to go out soon after.

#4 Re: Exercises » New Years Problem » 2017-01-13 13:47:38

The right tool for the job!

I tried using Table instead of For etc, but couldn't see how.

#5 Re: Exercises » New Years Problem » 2017-01-13 01:19:32


I got the same answer as Bobby's, also with M.

There are 236 solutions to "all values of x such that x^2 + 27 and x + 3 are prime".

#6 Re: Coder's Corner » Help in simple prob of loop » 2017-01-12 20:57:05

Here's a different method...

    While a>1
        For aa=1 To a
            Print "*";
        Next aa
        For bb=1 To b
            Print " ";
        Next bb
        For aa=1 To a
            Print "*";
        Next aa

And the output:

*******   *******
******      ******
*****         *****
****            ****
***               ***
**                  **
*                     *

#7 Re: Coder's Corner » Help in simple prob of loop » 2017-01-12 20:50:49

No, b$ isn't empty: it contains 21 blank spaces.

Each of the seven lines of printing in your first post contains two equal groups of asterisks that are separated by a group of blank spaces. Line 1 has 3 blank spaces, increasing by 3 in each subsequent line until reaching 21 blank spaces in the last (7th) line.

Right$(b$,d*3) for line 1 selects the right-most 3 blank spaces from b$, and, using the increasing value of d, for each subsequent loop selects 3 more spaces from b$ than for the previous line.

Right$(a$,c) for line 1 selects the right-most 7 asterisks from a$, and, using the reducing value of c, for each subsequent loop selects 1 less asterisk from a$ than for the previous line.

Btw, here is the output from my program: 

*******   *******
******      ******
*****         *****
****            ****
***               ***
**                  **
*                     *

#8 Re: Coder's Corner » Help in simple prob of loop » 2017-01-12 18:28:23


I don't know c or cpp, but here's a code in BASIC that will do it...

    a$="*******":b$="                     ":c=7:d=1
    While c>0
        Print Right$(a$,c)+Right$(b$,d*3)+Right$(a$,c)

It runs in LibertyBASIC (paid software) and JustBASIC (freeware), but in most other BASIC programs the code will need some tweaking to work.

#9 Re: Help Me ! » Can Someone Help Me Solve This » 2016-11-27 23:31:17


The grid has six of each of the letters 'S', 'I' and 'X' (not necessarily in order), from which the word 'SIX' can be formed six times.

If 'SIX' represents the number 6, then the sum of the value of the six of them and the seven occurrences of the number 6 is 78 (same as Monox D. I-Fly's answer in post #2).

This uses all grid entries.

#10 Re: Computer Math » A zeta-like sum » 2016-11-21 15:27:20

I just rebooted my PC to try and get under 50 seconds. Success! smile I've updated my post.

24 GB of RAM! I have 8.

Same thing: my Sharp PC-1500A had 8KB RAM, which I increased via a 16KB module to 24KB. Now it can do so much more!

#11 Re: Computer Math » A zeta-like sum » 2016-11-21 14:45:25


Here are the results from my PC, running on 64-bit Windows 10 Home with 24GB RAM, and M version

n=2000: {49.917894397904675, 14.369627144092833}

n=2000: {154.0926965884645, 14.369627144092856}
n=1750: {117.00484180506999, 14.362679551713114}

All without Monitor. With Monitor added 3% or so to the time.

#12 Re: Puzzles and Games » SOLS v5x5 » 2016-11-20 00:56:40

Sorry, Bobby...too tough for me.

I remember that discussion now about stefy's puzzle, but had to let it go then as I didn't have the first clue as to how to go about solving it...and still don't.

Btw, I initially wondered if 'two adjacent squares' included the central square and if 'adjacent' included 'diagonally adjacent', but from my reading of later posts in the discussion it seems that the answer to both questions is 'no'.

#13 Re: Puzzles and Games » SOLS v5x5 » 2016-11-19 11:01:53

Thanks...I'll have a read and report back. Most of today is planned for other things, so I won't be able to get into this right away.

But brekkie first...!

#14 Re: Puzzles and Games » SOLS v5x5 » 2016-11-19 10:49:06

Yes, please supply the link. Now that I've dipped my toe into the water I'd like to have a look.

#15 Re: Puzzles and Games » SOLS v5x5 » 2016-11-19 10:35:23

I was just in the middle of changing my post to say it might be something like that. smile

#16 Re: Puzzles and Games » SOLS v5x5 » 2016-11-19 10:21:49

Sorry, I'm not sure if I understand you correctly:

For a 5 x 5 there are over 209 million.

Re the SE 5x5, ubpdqn says, "there are 56 reduced forms and 161280 overall". Also, OEIS A002860.

For the 7 x 7 problem there are only 24 solutions

They're just the ones I found with that solver add-in, but I've no doubt that there are many more. The add-in is an optimisation program that gives one answer, and by changing numbers in a particular constraint I was able to extract further answers from it. I couldn't see an option to get all solutions.

The above OEIS link says there are 61,479,419,904,000 Latin squares for a 7x7.

#17 Re: Puzzles and Games » SOLS v5x5 » 2016-11-19 09:25:13

The Excel add-in that I used to find the 24 solutions to patchy1's 7x7 puzzle is an analytic solver.

#18 Re: Puzzles and Games » SOLS v5x5 » 2016-11-19 01:02:32

Congratulations! up

That's exactly what my problem needed...a full Latin Square list that could be searched for all answers. And the solution also lists the other two duplicate answers I found yesterday.

On my PC, compiling the list takes about 14 seconds, plus a further second for the search.

The 'ans' variable also runs in ubpdqn's (SE) code (replace 'ls /@ Permutations[Range[5]]' with 'ans')...change his criteria too, of course. Search output is the same as yours, and time is about 1 second.

This morning I generated a dummy 161280 list in a 'For' loop, incorporating two correct answers. That took 1 minute, and ubpdqn's code then found those two answers in 1 second. we're getting really close to solving a 7x7 for all answers! At your 5x5's speed it would only take about 170 years to compile the 7x7 list, plus a further 12 years to find all the answers. wink

Will your work help you with anonimnystefy's square problem?

#19 Re: Puzzles and Games » SOLS v5x5 » 2016-11-15 01:10:36

Hi Bobby;

Thanks for the matrix info...I think I might be getting it.

I got enzotib's code to work for me, except that I could only get it to give me one answer per evaluation. A subsequent evaluation (or more) gave another answer. Only two answers were ever found, and they were the same as ours.

I couldn't work out how to change the code to output both answers in the one run.

Also, my run time varies from zero to about 100 seconds because of the RandomInteger just after the While.

I can't see how we could use this code on a 7x7 grid like patchy1's puzzle, given the HUGE leap in the number of permutations from my 5x5 puzzle that solves nowhere near fast enough to even think of trying it...unless I can find my time machine.

#20 Re: Puzzles and Games » SOLS v5x5 » 2016-11-14 09:18:22

Good morning, Bobby;

Thanks for the info and the link - I'll check it all out. Yes, I'd thought the matrix would feature but I don't have any experience with them and didn't know how to implement it. It was on my to-do list for further research.

Gonna have brekkie in a minute and then I'm gone for the day.

Catch you later. smile

#21 Re: Puzzles and Games » SOLS v5x5 » 2016-11-13 21:16:39

Hi Bobby;

Excellent! They're the two answers I got, too.

One is just a flip over the S-W/N-E diagonal of the other. I hadn't noticed that before I found my second solution (the non-Solver one), otherwise I could have saved myself a fair bit of extra effort!

There don't seem to be any other solutions.

Could you give me an idea of how to do this in M?

I notice from your answers that you seem to have spotted that the four shaded squares can be treated as white squares for part of the coding. That's how I drew up my Excel Solver model, which helped simplify and shorten the code.

#22 Puzzles and Games » SOLS v5x5 » 2016-11-12 01:05:04

Replies: 21

Hi all;

This is a 5x5 version of the kind posted last year by patchy1, which was a 7x7 grid.

Each row A, C & E and each column 1,3 & 5 contain the numbers 1 to 5, and the number in each shaded square is the sum of the numbers in the eight white squares that immediately surround the shaded square.

No duplicate numbers are allowed in the white squares in any of the five rows and five columns.


I thought I'd post this 5x5 junior version as it's more doable than the huge 7x7.

I've found two solutions, but there may be more. One was with Excel's standard Solver, and the other was with a combination of logic, T&E and PoE on an Excel spreadsheet.

#23 Re: Help Me ! » What is the common operation? » 2016-10-30 20:00:58


For anyone coming across this thread before the puzzle's second appearance here (where it is discussed further), I gave a solution (not sure if it's 'the' solution) in post #13 of that second thread.

#24 Re: Help Me ! » [ASK] Are the Frequency and the Score Switched? » 2016-10-24 22:04:22


I agree with thickhead's reasoning and that the frequency and score should be switched for the problem to make sense.

If those two are switched, then the solution is one of those in the multiple-choice list.

Monox D. I-Fly has made an arithmetical error that accounts for his answer not appearing in the list.

#25 Re: Help Me ! » Permutation slot generator » 2016-10-21 02:15:17

I couldn't have destroyed that dream had not that word already been coined. You were bound to find out sooner or later...I'm just sorry it was through me!

In what sense?

In a totally tongue-in-cheek sense, zombies being fictional. As with 'photoshopped', you were bound to find out sooner or later; and so, if I've shattered another dream, I'm sorry it was through me...again!

Off to bed. I'll probably dream about zombies.

Board footer

Powered by FluxBB