QB64 Phoenix Edition
A puzzeltask - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2)
+--- Thread: A puzzeltask (/showthread.php?tid=1868)

Pages: 1 2 3 4


RE: A puzzeltask - justsomeguy - 08-01-2023

Just to clarify the tracks closest to us and to the right can hold the length of both cars and the locomotive? And the locomotive can push and pull from both front and back?


RE: A puzzeltask - Kernelpanic - 08-01-2023

(08-01-2023, 10:43 AM)justsomeguy Wrote: Just to clarify the tracks closest to us and to the right can hold the length of both cars and the locomotive? And the locomotive can push and pull from both front and back?
The tracks down and to the right are open. Of course, the locomotive can drive both forwards and backwards, so also pushing or pulling.

Maybe the translation of the German text of the task into English is a bit jolty, but I really tried my best.  Wink


RE: A puzzeltask - SMcNeill - 08-02-2023

Around here, the tracks tend to look like this:

------------------\------------------------/-----------------------
                     -------------------------

Now, with the side rail on an offset, two trains can pass each other, or an engine can detach from one end and attach itself to the other end.  It tends to use less room overall, I think (since the railway has to maintain X feet to either side of a track), so it's this type of junction or switchback that we tend to see around my neck of the woods.


RE: A puzzeltask - bplus - 08-02-2023

But can a locomotive and tender turn around in such a design if they don't fit on the side track?

In KP's design they can unless I misunderstand it's workings.


RE: A puzzeltask - Kernelpanic - 08-02-2023

Another note about the task:

Psychological blocks in brain teasers
In a series of interesting experiments, the German-American psychologist Prof. Martin Scheerer, who died in 1961, dealt with the problem of which psychological conditions generally exist when solving problems. He specifically pointed out what the psychological trick is in brain teasers.

Brainteasers are generally characterized by the fact that a psychological block is created at a certain point. Once this block is recognized, the solution appears amazingly simple.

I will post the solution tomorrow if no one haven't found one by then.


RE: A puzzeltask - mnrvovrfc - 08-02-2023

There is no solution.

Otherwise I think I solved it. I can't imagine that clunky locomotive being moved around for anything. Cannot do shunting (or "switching" as it's called in America, thanks Wikipedia) without a team, and without a team there is no solution. It might be my being naive about railroad work. Yet there is a flaw even with the solution due to the available spaces and the turns... that freckin' bumper block too.


RE: A puzzeltask - SMcNeill - 08-02-2023

I would imagine it goes like this:

A-------------------B
 \                    /
  \                  /
   \                /
    \____C___/
           |
           |
           |
             D

Train starts at A (and I didn't feel like trying to ascii draw that whole dang triangle).
Train unhooks the back of the car that it wants to swap positions with.
Train pulls the string of cars past C, then backs into D.  At this point it can disconnect the car that it wants to change position of.
Pull back out towards B until all cars are back on track between C and B.
Train then backs back up to A and reconnects all the other cars that were behind the car it wanted to move.
If the train wants to insert the car somewhere into its lineup, it simply disconnects the rear of the car that it wants to use at the insertion point.
Train then goes past C and backs up to D, connecting the unhooked car into its new position.
Train now pulls back up towards B, and then backs back to A, connecting to the rest of the row of cars left behind.
Repeat until cars are in the order that the train needs to be in.


RE: A puzzeltask - bplus - 08-02-2023

Solution dump all the cars they are a nuisance:
Code: (Select All)
_Title "Peace Train" 'from old post 2019-03-24 mod B+ 2019-03-26



'      play this: https://www.youtube.com/watch?v=UkTQri3a4Gg



Randomize Timer
Screen _NewImage(800, 600, 32)
_ScreenMove 200, 20

'background B+ mod
Dim Shared scape&
LoadLandscape
scapeWidth = _Width(scape&)
scapeHeight = _Height(scape&)
'PRINT scapeWidth, scapeHeight

'train stuff Code Hunter and Fellippe?
Dim temp As String
Dim Shared Pattern As String

Dim Shared Train(7, 10) As String
Dim Shared Coal(10) As String

Dim Smoke1 As String
Dim Smoke2 As String
Dim Smoke3 As String
Dim Smoke4 As String
Smoke1 = Space$(16) + "@@@@"
Smoke2 = Space$(16) + "          @ @ "
Smoke3 = Space$(16) + "    @@     @@     @     @     @    "
Smoke4 = Space$(16) + "       @@     @@     @     @     @ "
LoadTrain
col = 1
row = 7
p = 6

le = scapeWidth - 800
While 1
    Cls

    '    background stuff
    If le + 800 > scapeWidth Then
        te = scapeWidth - le
        _PutImage (0, 0)-(te, scapeHeight), scape&, 0, (scapeWidth - te, 0)-(scapeWidth, scapeHeight)
        _PutImage (te, 0)-(800, scapeHeight), scape&, 0, (0, 0)-(800 - te, scapeHeight)
    Else
        _PutImage (0, 0)-(800, scapeHeight), scape&, 0, (le, 0)-(le + 800, scapeHeight)
    End If
    '_PRINTSTRING (5, 5), STR$(le)
    le = le - 1
    If le < 0 Then le = scapeWidth


    'train stuff
    Color _RGBA32(255, 255, 255, 200), _RGBA32(0, 0, 0, 0)
    For j = 0 To 9
        '_PRINTSTRING (0, 16 * j + 112), MID$(Train(p, j + 1), i, 80)
        _PrintString (64, 16 * j + 442), Mid$(Train(p, j + 1), 1, 84)
    Next
    'If i < Len(Smoke4) Then
    '    If fcount Mod 30 < 15 Then
    '        _PrintString (0, 96 + 300), Mid$(Smoke1, i, 80)
    '        _PrintString (0, 64 + 300), Space$(8) + Mid$(Smoke1, i, 80)
    '        _PrintString (0, 32 + 300), Space$(24) + Mid$(Smoke3, i, 80)
    '    Else
    '        _PrintString (0, 80 + 280), Space$(4) + Mid$(Smoke1, i, 80)
    '        _PrintString (0, 48 + 280), Space$(12) + Mid$(Smoke2, i, 80)
    '        _PrintString (0, 32 + 280), Space$(24) + Mid$(Smoke4, i, 80)
    '    End If
    'End If

    fcount = fcount + 1
    If fcount = 60 Then fcount = 0
    If fcount Mod 6 = 0 Then
        col = col + 1: i = i + 1
        If col = Len(Pattern) + 1 Then col = 1
        If i > Len(Train(1, 1)) - 80 Then i = 1
        p = Val(Mid$(Pattern, col, 1))
    End If
    peace 167, 579, 18, a
    peace 215, 579, 18, a + _Pi / 2
    peace 263, 579, 18, a + _Pi
    peace 311, 579, 18, a + _Pi * 1.5

    peace 530, 591, 6, a + _Pi * .25
    peace 578, 591, 6, a + _Pi * .75
    peace 634, 591, 6, a + _Pi * 1.25
    peace 682, 591, 6, a + _Pi * 1.75

    peace 90, 585, 12, a + _Pi * .66
    peace 386, 585, 12, a + _Pi * 1.66

    peace 128, 419, 12, -a + _Pi * .1
    peace 175, 386, 10, -a - _Pi * .3
    peace 281, 351, 9, -a + _Pi * .5
    peace 328, 321, 10, -a + _Pi * .7
    peace 401, 318, 7, -a + _Pi * .9
    peace 477, 307, 9, -a + _Pi * 1.1
    peace 562, 317, 6, -a + _Pi * 1.5

    a = a - _Pi / 36
    For i = 1 To 5
        peace 608, 518, 28, 0
    Next

    _Display
    _Limit 90 '<<< EDIT
Wend

Sub LoadLandscape
    cur& = _Dest
    xmax = 800 * 6: ymax = 600
    scape& = _NewImage(xmax, ymax, 32)
    _Dest scape&

    For i = 0 To ymax
        midInk 0, 0, 128, 128, 128, 200, i / ymax
        Line (0, i)-(xmax, i)
    Next
    'the land
    startH = ymax - 200
    rr = 70: gg = 70: bb = 90
    For mountain = 1 To 6
        Xright = 0
        y = startH
        Color _RGB(rr, gg, bb)
        While Xright < xmax - 50
            ' upDown = local up / down over range, change along Y
            ' range = how far up / down, along X
            upDown = (Rnd * .8 - .4) * (mountain * .5)
            range = Xright + rand%(15, 25) * 2.5 / mountain
            If range > xmax - 50 Then range = xmax - 50
            lastx = Xright - 1
            For x = Xright To range
                test = y + upDown
                If Abs(test - startH) < .1 * startH Then y = test
                Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
                lastx = x
            Next
            Xright = range
        Wend
        x = lastx + 1
        While x <= xmax
            y = y + (startH - y) / 40
            Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
            lastx = x
            x = x + 1
        Wend
        rr = rand%(rr - 15, rr): gg = rand%(gg - 15, gg): bb = rand%(bb - 25, bb)
        If rr < 0 Then rr = 0
        If gg < 0 Then gg = 0
        If bb < 0 Then bb = 0
        startH = startH + rand%(5, 20)
    Next
    _Dest cur&
End Sub

Function rand% (lo%, hi%)
    rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
End Function

Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
    Color _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
End Sub

Sub LoadTrain
    Dim t As String

    For j = 1 To 10
        Read t: Coal(j) = t
    Next

    For i = 1 To 6
        For j = 1 To 10
            Read t: Train(i, j) = t + Coal(j)
        Next
    Next

    For i = 1 To Len(t)
        ' Reverse: "312465"
        t = Mid$("564213", i, 1)
        Pattern = Pattern + t + t
    Next
    Exit Sub

    Data "                             "
    Data "                             "
    Data "    _________________        "
    Data "   _|                \_____A "
    Data " =|                        | "
    Data " -|                        | "
    Data "__|________________________|_"
    Data "|__________________________|_"
    Data "   |_D__D__D_|  |_D__D__D_|  "
    Data "    \_/   \_/    \_/   \_/   "

    Data "      ====        ________                ___________"
    Data "  _D _|  |_______/        \__I_I_____===__|_________|"
    Data "   |(_)---  |   H\________/ |   |        =|___ ___|  "
    Data "   /     |  |   H  |  |     |   |         ||_| |_||  "
    Data "  |      |  |   H  |__--------------------| [___] |  "
    Data "  | ________|___H__/__|_____/[][]~\_______|       |  "
    Data "  |/ |   |-----------I_____I [][] []  D   |=======|__"
    Data "__/ =| o |=-O=====O=====O=====O \ ____Y___________|__"
    Data " |/-=|___|=    ||    ||    ||    |_____/~\___/       "
    Data "  \_/      \__/  \__/  \__/  \__/      \_/           "

    Data "      ====        ________                ___________"
    Data "  _D _|  |_______/        \__I_I_____===__|_________|"
    Data "   |(_)---  |   H\________/ |   |        =|___ ___|  "
    Data "   /     |  |   H  |  |     |   |         ||_| |_||  "
    Data "  |      |  |   H  |__--------------------| [___] |  "
    Data "  | ________|___H__/__|_____/[][]~\_______|       |  "
    Data "  |/ |   |-----------I_____I [][] []  D   |=======|__"
    Data "__/ =| o |=-~O=====O=====O=====O\ ____Y___________|__"
    Data " |/-=|___|=    ||    ||    ||    |_____/~\___/       "
    Data "  \_/      \__/  \__/  \__/  \__/      \_/           "

    Data "      ====        ________                ___________"
    Data "  _D _|  |_______/        \__I_I_____===__|_________|"
    Data "   |(_)---  |   H\________/ |   |        =|___ ___|  "
    Data "   /     |  |   H  |  |     |   |         ||_| |_||  "
    Data "  |      |  |   H  |__--------------------| [___] |  "
    Data "  | ________|___H__/__|_____/[][]~\_______|       |  "
    Data "  |/ |   |-----------I_____I [][] []  D   |=======|__"
    Data "__/ =| o |=-~~\  /~~\  /~~\  /~~\ ____Y___________|__"
    Data " |/-=|___|=O=====O=====O=====O   |_____/~\___/       "
    Data "  \_/      \__/  \__/  \__/  \__/      \_/           "

    Data "      ====        ________                ___________"
    Data "  _D _|  |_______/        \__I_I_____===__|_________|"
    Data "   |(_)---  |   H\________/ |   |        =|___ ___|  "
    Data "   /     |  |   H  |  |     |   |         ||_| |_||  "
    Data "  |      |  |   H  |__--------------------| [___] |  "
    Data "  | ________|___H__/__|_____/[][]~\_______|       |  "
    Data "  |/ |   |-----------I_____I [][] []  D   |=======|__"
    Data "__/ =| o |=-~~\  /~~\  /~~\  /~~\ ____Y___________|__"
    Data " |/-=|___|=   O=====O=====O=====O|_____/~\___/       "
    Data "  \_/      \__/  \__/  \__/  \__/      \_/           "

    Data "      ====        ________                ___________"
    Data "  _D _|  |_______/        \__I_I_____===__|_________|"
    Data "   |(_)---  |   H\________/ |   |        =|___ ___|  "
    Data "   /     |  |   H  |  |     |   |         ||_| |_||  "
    Data "  |      |  |   H  |__--------------------| [___] |  "
    Data "  | ________|___H__/__|_____/[][]~\_______|       |  "
    Data "  |/ |   |-----------I_____I [][] []  D   |=======|__"
    Data "__/ =| o |=-~~\  /~~\  /~~\  /~~\ ____Y___________|__"
    Data " |/-=|___|=    ||    ||    ||    |_____/~\___/       "
    Data "  \_/      \O=====O=====O=====O_/      \_/           "

    Data "      ====        ________                ___________"
    Data "  _D _|  |_______/        \__I_I_____===__|_________|"
    Data "   |(_)---  |   H\________/ |   |        =|___ ___|  "
    Data "   /     |  |   H  |  |     |   |         ||_| |_||  "
    Data "  |      |  |   H  |__--------------------| [___] |  "
    Data "  | ________|___H__/__|_____/[][]~\_______|       |  "
    Data "  |/ |   |-----------I_____I [][] []  D   |=======|__"
    Data "__/ =| o |=-~~\  /~~\  /~~\  /~~\ ____Y___________|__"
    Data " |/-=|___|=    ||    ||    ||    |_____/~\___/       "
    Data "  \_/      \_O=====O=====O=====O/      \_/           "
End Sub

Sub lyne (x0, y0, lngth, ra, thic, c As _Unsigned Long)
    Dim x As Integer, y As Integer, l As Integer
    While l < lngth
        l = l + 1: x = x0 + l * Cos(ra): y = y0 + l * Sin(ra)
        For radius = 0 To thic / 2
            Circle (x, y), radius, c, BF
        Next
    Wend
End Sub

Sub peace (x0, y0, r, raRot) ' 12 is about smallest
    thic = r / 5.5
    For rr = r - thic To r Step 1
        Circle (x0, y0), rr
    Next
    lyne x0, y0, r - .5 * thic, _Pi * 1.5 + raRot, thic, &H11FFFFFF
    lyne x0, y0, r - .5 * thic, _Pi * .5 + raRot, thic, &H11FFFFFF
    lyne x0, y0, r - .5 * thic, _Pi * .25 + raRot, thic, &H11FFFFFF
    lyne x0, y0, r - .5 * thic, _Pi * .75 + raRot, thic, &H11FFFFFF
End Sub



RE: A puzzeltask - mnrvovrfc - 08-02-2023

Rolleyes

The second half of "Full Metal Jacket" movie rarely referenced with things such as an officer:

"Joker, why are you wearing a peace sign in your uniform?"



I'm sorry if my previous post read arrogant. But I think Steve solved it! Bravo!


RE: A puzzeltask - Kernelpanic - 08-02-2023

(08-02-2023, 05:57 PM)SMcNeill Wrote: Repeat until cars are in the order that the train needs to be in.
I had real trouble understanding your proposed solution, but your last sentence showed me that this is not the solution. I think so! If I translated that correctly, no.
 
Only nine shunting operations are necessary!