in Technology

Print Mines

Create a field of 6×5 size. That prints like the following:

-------------------------------
|  1 |  2 |  3 |  4 |  5 |  6 |
|  7 |  8 |  9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 |
-------------------------------

The input to the application will be a string of numbers, separated by commands. E.g.

23,3,4,10

These numbers represent the mines on the field. And you have to put two crosses “XX” in their places. So the output will look like this:

-------------------------------
|  1 |  2 | XX | XX |  5 |  6 |
|  7 |  8 |  9 | XX | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | XX | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 |
-------------------------------

Write a Comment

Comment

  1. Logic for the general case:

    Consider a matrix of MxN integers.

    Since we are going to assign values in linearly ascending order, we can treat this as a linear block of MxN integers. Then the yth element is at index y.

    We are given a list of input integers, and the corresponding elements are to be flagged.

    So the program boils down to:

    for i in 1 .. MxN
    do
    set array to i
    done

    get(input)
    for i in (split input on record_separator)
    do
    set array element at i to invalid value
    done

    output array in M rows and N columns with invalid value replaced by appropriate character(s).

  2. Great DVB! Many people solved this puzzle pretty fast! I got to start thinking better 😉

    BTW, people are free to submit Logic Builders! I will be glad to publish them here with due credit.