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

You are not logged in. #1 20060305 04:26:57
Math problem : 2 objects on an infinite axishi everybody , I've been struggling for some time now with this math problem , I still can't come up with a resolution without assume there's an end on the infinite axis It goes like this : #2 20060305 05:21:53
Re: Math problem : 2 objects on an infinite axisHi deuce. IPBLE: Increasing Performance By Lowering Expectations. #3 20060305 05:24:30
Re: Math problem : 2 objects on an infinite axis1. Are the flags same? IPBLE: Increasing Performance By Lowering Expectations. #4 20060305 05:40:23
Re: Math problem : 2 objects on an infinite axisI'm not 100% sure that I understand the rules in your question, but it sounds to me as though your concern is that on an infinite axis, you can't tell the robots to go in a given direction because if you pick the wrong direction then they'll never hit an end and so they'll never know that they're getting farther apart. #5 20060305 05:46:13
Re: Math problem : 2 objects on an infinite axisThe two robots may ostilate round their start points: Last edited by krassi_holmz (20060305 05:59:35) IPBLE: Increasing Performance By Lowering Expectations. #6 20060305 06:51:42
Re: Math problem : 2 objects on an infinite axisI'm ready with a program: Code:rob[g_] := ( Clear[l, k, r]; l = Length[g]; k = 1; Do[ If[ g[[i]] > 1, r[k] = i; k++; ] , {i, 1, l}]; {r[1], r[2]} ) d[data_] := ( w = data[[1]]; coor = data[[2]]; dir = data[[3]]; If[ w[[coor]] == 3, w[[coor]] = 1; w[[coor + dir]] += 2;, w[[coor]] = 1; dir = dir; w[[dir + coor]] += 2; ]; {w, dir} ) step[data_] := ( Clear[w, dir1, dir2, r, d1, d2, w1, w2]; w = data[[1]]; dir1 = data[[2]]; dir2 = data[[3]]; r = rob[w]; w; d1 = d[{w, r[[1]], dir1}]; w1 = d1[[1]]; dir1 = d1[[2]]; d2 = d[{w1, r[[2]], dir2}]; w2 = d2[[1]]; dir2 = d2[[2]]; {w2, dir1, dir2} ) IPBLE: Increasing Performance By Lowering Expectations. #7 20060305 07:06:17
Re: Math problem : 2 objects on an infinite axisThe output depends on what you want: Code:wd = {0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0}; data = {wd, 1, 1}; Print[data]; While[Max[Flatten[data]] < 5, data = step[data]; Print[data]]; Here's the output: Code:{{0,0,0,0,0,2,0,0,0,2,0,0,0,0},1,1} {{0,0,0,0,2,1,0,0,2,1,0,0,0,0},1,1} {{0,0,0,0,1,3,0,0,1,3,0,0,0,0},1,1} {{0,0,0,0,1,1,2,0,1,1,2,0,0,0},1,1} {{0,0,0,0,1,3,1,0,1,3,1,0,0,0},1,1} {{0,0,0,0,3,1,1,0,3,1,1,0,0,0},1,1} {{0,0,0,2,1,1,1,2,1,1,1,0,0,0},1,1} {{0,0,0,1,3,1,1,1,3,1,1,0,0,0},1,1} {{0,0,0,1,1,3,1,1,1,3,1,0,0,0},1,1} {{0,0,0,1,1,1,3,1,1,1,3,0,0,0},1,1} {{0,0,0,1,1,1,1,3,1,1,1,2,0,0},1,1} {{0,0,0,1,1,1,1,1,3,1,3,1,0,0},1,1} {{0,0,0,1,1,1,1,1,1,5,1,1,0,0},1,1} The first set is the "world": the 0s are empty cells and the 2s are the robots. IPBLE: Increasing Performance By Lowering Expectations. #8 20060305 07:15:41
Re: Math problem : 2 objects on an infinite axisHere's another example: Code:wd = {0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}; data = {wd, 1, 1}; Print[data]; While[Max[Flatten[data]] < 5, data = step[data]; Print[data]]; Code:{{0,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0},1,1} {{0,0,0,0,0,2,1,0,0,0,0,2,1,0,0,0,0,0},1,1} {{0,0,0,0,0,1,3,0,0,0,0,1,3,0,0,0,0,0},1,1} {{0,0,0,0,0,1,1,2,0,0,0,1,1,2,0,0,0,0},1,1} {{0,0,0,0,0,1,3,1,0,0,0,1,3,1,0,0,0,0},1,1} {{0,0,0,0,0,3,1,1,0,0,0,3,1,1,0,0,0,0},1,1} {{0,0,0,0,2,1,1,1,0,0,2,1,1,1,0,0,0,0},1,1} {{0,0,0,0,1,3,1,1,0,0,1,3,1,1,0,0,0,0},1,1} {{0,0,0,0,1,1,3,1,0,0,1,1,3,1,0,0,0,0},1,1} {{0,0,0,0,1,1,1,3,0,0,1,1,1,3,0,0,0,0},1,1} {{0,0,0,0,1,1,1,1,2,0,1,1,1,1,2,0,0,0},1,1} {{0,0,0,0,1,1,1,3,1,0,1,1,1,3,1,0,0,0},1,1} {{0,0,0,0,1,1,3,1,1,0,1,1,3,1,1,0,0,0},1,1} {{0,0,0,0,1,3,1,1,1,0,1,3,1,1,1,0,0,0},1,1} {{0,0,0,0,3,1,1,1,1,0,3,1,1,1,1,0,0,0},1,1} {{0,0,0,2,1,1,1,1,1,2,1,1,1,1,1,0,0,0},1,1} {{0,0,0,1,3,1,1,1,1,1,3,1,1,1,1,0,0,0},1,1} {{0,0,0,1,1,3,1,1,1,1,1,3,1,1,1,0,0,0},1,1} {{0,0,0,1,1,1,3,1,1,1,1,1,3,1,1,0,0,0},1,1} {{0,0,0,1,1,1,1,3,1,1,1,1,1,3,1,0,0,0},1,1} {{0,0,0,1,1,1,1,1,3,1,1,1,1,1,3,0,0,0},1,1} {{0,0,0,1,1,1,1,1,1,3,1,1,1,1,1,2,0,0},1,1} {{0,0,0,1,1,1,1,1,1,1,3,1,1,1,3,1,0,0},1,1} {{0,0,0,1,1,1,1,1,1,1,1,3,1,3,1,1,0,0},1,1} {{0,0,0,1,1,1,1,1,1,1,1,1,5,1,1,1,0,0},1,1} IPBLE: Increasing Performance By Lowering Expectations. #9 20060305 09:02:38
Re: Math problem : 2 objects on an infinite axisFirst of all, it will in general take an infinite number of steps to find the other robot due to their relative distance at the beginning being close to infinite. igloo myrtilles fourmis #10 20060305 10:06:48
Re: Math problem : 2 objects on an infinite axis
The starting locations that are chosen have a range of infinity, but their values must be finite. Thus, it must take a finite numbre of steps, if the algorithm worked, which krassi came up with a very good one, well done. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #11 20060305 13:19:38
Re: Math problem : 2 objects on an infinite axisI am not altered in my belief that the two points will be approximately infinitely apart. Last edited by John E. Franklin (20060305 13:24:35) igloo myrtilles fourmis #12 20060305 19:38:05
Re: Math problem : 2 objects on an infinite axisJohn, my algoritm is based on this oscillating. IPBLE: Increasing Performance By Lowering Expectations. #13 20060305 19:50:29
Re: Math problem : 2 objects on an infinite axisHere is it (Copyright (c) 2006 made with Paint (c) ): Last edited by krassi_holmz (20060305 19:53:56) IPBLE: Increasing Performance By Lowering Expectations. #14 20060305 22:37:22
Re: Math problem : 2 objects on an infinite axis
yeah krassi , this does it . 10x a lot . marking every move with a flag is actually the way to solve this .well done with the grafics and the code  looks really good. 10x again #15 20060306 00:33:49
Re: Math problem : 2 objects on an infinite axisСупер. IPBLE: Increasing Performance By Lowering Expectations. #16 20060306 00:39:40
Re: Math problem : 2 objects on an infinite axisпробвай в дира, клуб програмиране. IPBLE: Increasing Performance By Lowering Expectations. #17 20060306 07:47:26
Re: Math problem : 2 objects on an infinite axiskrassi, it doesn't work if the two bots start an odd distance away. Code:#include <iostream> #include <vector> #include <string> #include <fstream> #include <time.h> #include <conio.h> using namespace std; int main() { short bot1Pos, bot2Pos; int bot1Dir = 1, bot2Dir = 1; int x; unsigned long steps = 0; bool *flag = new bool[RAND_MAX]; for (x = 0; x < RAND_MAX; x++) { flag[x] = false; } srand(time(NULL)); bot1Pos = rand(); bot2Pos = rand(); cout << "Robots starting at: " << bot1Pos << " and " << bot2Pos << endl; while (bot1Pos != bot2Pos) { steps++; if (flag[bot1Pos]) { //cout << "There is a flag under bot1 at " << bot1Pos << " moving in the same direction to "; bot1Pos += bot1Dir; //cout << bot1Pos << endl; } else { //cout << "No flag at " << bot1Pos << "planting a flag, and changing directions."; flag[bot1Pos] = true; bot1Dir *= 1; bot1Pos += bot1Dir; //cout << " Now at " << bot1Pos << endl; } //cout << endl; if (flag[bot2Pos]) { //cout << "There is a flag under bot2 at " << bot2Pos << " moving in the same direction to "; bot2Pos += bot2Dir; //cout << bot2Pos << endl; } else { //cout << "No flag at " << bot2Pos << "planting a flag, and changing directions."; flag[bot2Pos] = true; bot2Dir *= 1; bot2Pos += bot2Dir; //cout << " Now at " << bot2Pos << endl; } //cout << endl; if (bot1Pos < 0 && bot1Dir == 1) bot1Pos = 0; if (bot1Pos < 0 && bot1Dir == 1) bot1Pos = RAND_MAX; if (bot2Pos < 0 && bot2Dir == 1) bot2Pos = 0; if (bot2Pos < 0 && bot2Dir == 1) bot2Pos = RAND_MAX; } cout << "Robots found each other at " << bot1Pos << endl; cout << "It took " << steps << " steps." << endl; return 0; } "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #18 20060306 08:22:35
Re: Math problem : 2 objects on an infinite axishey Ricky 10x much for the c++ code that's better than what I came up with ... still as I understood Krassi's solution  it works no matter the distance  the bots will meet eventually . Could you elaborate what the problem is . please . 10x again #19 20060306 08:52:54
Re: Math problem : 2 objects on an infinite axisRicky is rightmy mathematica code doesn't works for odd distanses!!! IPBLE: Increasing Performance By Lowering Expectations. #20 20060306 09:10:42
Re: Math problem : 2 objects on an infinite axisКраси голямо благодаря за задачата . Имаш една Загорка от мен :) Иначе аз съм в БГ , софия  ти в България ли си . не съм дори близо до вас като гледам колко сте навътре в среиозната математика ... все пак , налага се от време на време с някоя задача да се посблъскаме . Мерси отново за съдействието . #21 20060306 12:04:09
Re: Math problem : 2 objects on an infinite axisThe two robots move past each other if they are on adjacent blocks. Now any real life senario, there would be no problem. But when programming, the robots (or at least mine) don't check to see if they are on the same space till they each moved. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #22 20060306 17:56:03
Re: Math problem : 2 objects on an infinite axisIf meet means that the two robots must be in same cell, then if they are neightbourng, they will just pass each other over and over. IPBLE: Increasing Performance By Lowering Expectations. #23 20060309 23:48:07
Re: Math problem : 2 objects on an infinite axisYesterday I read an interestingmanual about the Lfunctions. Simply, the Lfunctions are "stringreplacing" functions. Code:Robots[distance_] := ( (*STRING REPLACING RULES*) robotrules = { (*two robots x *) "(frd)f(fdr)" > "fXf", "(frd)(fdr)" > "XX", (*if the robot is at empty cell, then reverse direction and place flag*) "(rd)" > "(fdr)", "(dr)" > "(frd)", (*if the robot is at flag then step*) "(frd)e" > "f(rd)", "(frd)f" > "f(frd)", "e(fdr)" > "(dr)f", "f(fdr)" > "(fdr)f", (*world extension*) "(frd)(ef)" > "f(rd)(ef)", "(fe)(fdr)" > "(fe)(dr)f" }; (*/STRING REPLACING RULES*) (*WORLD MAKING*) Clear[str]; str = "(fe)(rd)"; Do[str = str <> "e", {i, 1, distance}]; str = str <> "(rd)(ef)"; (*/WORLD MAKING*) (*COMPUTING*) Print["0 ::", str]; p = False; step = 1; While[p == False, str = StringReplace[str, robotrules]; p = MemberQ[Characters[str], "X"]; Print[step, "::", str]; step = step + 1; ] (*/COMPUTING*) ) It's quite simple. Code:0 :: (fe)(rd)eeeee(rd)(ef) 1 :: (fe)(fdr)eeeee(fdr)(ef) 2 :: (fe)(dr)feeee(dr)f(ef) 3 :: (fe)(frd)feeee(frd)f(ef) 4 :: (fe)f(frd)eeeef(frd)(ef) 5 :: (fe)ff(rd)eeeff(rd)(ef) 6 :: (fe)ff(fdr)eeeff(fdr)(ef) 7 :: (fe)f(fdr)feeef(fdr)f(ef) 8 :: (fe)(fdr)ffeee(fdr)ff(ef) 9 :: (fe)(dr)fffee(dr)fff(ef) 10 :: (fe)(frd)fffee(frd)fff(ef) 11 :: (fe)f(frd)ffeef(frd)ff(ef) 12 :: (fe)ff(frd)feeff(frd)f(ef) 13 :: (fe)fff(frd)eefff(frd)(ef) 14 :: (fe)ffff(rd)effff(rd)(ef) 15 :: (fe)ffff(fdr)effff(fdr)(ef) 16 :: (fe)fff(fdr)fefff(fdr)f(ef) 17 :: (fe)ff(fdr)ffeff(fdr)ff(ef) 18 :: (fe)f(fdr)fffef(fdr)fff(ef) 19 :: (fe)(fdr)ffffe(fdr)ffff(ef) 20 :: (fe)(dr)fffff(dr)fffff(ef) 21 :: (fe)(frd)fffff(frd)fffff(ef) 22 :: (fe)f(frd)fffff(frd)ffff(ef) 23 :: (fe)ff(frd)fffff(frd)fff(ef) 24 :: (fe)fff(frd)fffff(frd)ff(ef) 25 :: (fe)ffff(frd)fffff(frd)f(ef) 26 :: (fe)fffff(frd)fffff(frd)(ef) 27 :: (fe)ffffff(frd)fffff(rd)(ef) 28 :: (fe)fffffff(frd)ffff(fdr)(ef) 29 :: (fe)ffffffff(frd)ff(fdr)f(ef) 30 :: (fe)fffffffff(frd)(fdr)ff(ef) 31 :: (fe)fffffffffXXff(ef) the number is the number of steps and the string is the condition of the main "world" string in the internal "world" language. Last edited by krassi_holmz (20060310 00:02:11) IPBLE: Increasing Performance By Lowering Expectations. #24 20060310 00:24:13
Re: Math problem : 2 objects on an infinite axisActually for my second program I use an algoritm that is different from the original a little. IPBLE: Increasing Performance By Lowering Expectations. #25 20060310 00:41:48
Re: Math problem : 2 objects on an infinite axisYou just have to replace a pat of robotrules with this: Code:OriginalRobots[distance_] := ( robotrules = { (*two robots x *) "(frd)f(fdr)" > "fXf", "(frd)(fdr)" > "XX", "f(rd)" > "(fdr)f", "(dr)f" > "f(frd)", "e(rd)" > "(dr)f", "(dr)e" > "f(rd)", "(fe)(rd)" > "(fe)(dr)f", "(dr)(ef)" > "f(rd)(ef)", "(frd)e" > "f(rd)", "(frd)f" > "f(frd)", "e(fdr)" > "(dr)f", "f(fdr)" > "(fdr)f", "(frd)(ef)" > "f(rd)(ef)", "(fe)(fdr)" > "(fe)(dr)f" }; Clear[str]; str = "(fe)(rd)"; Do[str = str <> "e", {i, 1, distance}]; str = str <> "(rd)(ef)"; Print["0 ::", str]; p = False; step = 1; While[p == False, str = StringReplace[str, robotrules]; p = MemberQ[Characters[str], "X"]; Print[step, "::", str]; step = step + 1; ] ) It now gives 1 X for odd distances and 2X for even. It also needs less steps: Code:0 :: (fe)(rd)eeeee(rd)(ef) 1 :: (fe)(dr)feeee(dr)f(ef) 2 :: (fe)f(frd)eeeef(frd)(ef) 3 :: (fe)ff(rd)eeeff(rd)(ef) 4 :: (fe)f(fdr)feeef(fdr)f(ef) 5 :: (fe)(fdr)ffeee(fdr)ff(ef) 6 :: (fe)(dr)fffee(dr)fff(ef) 7 :: (fe)f(frd)ffeef(frd)ff(ef) 8 :: (fe)ff(frd)feeff(frd)f(ef) 9 :: (fe)fff(frd)eefff(frd)(ef) 10 :: (fe)ffff(rd)effff(rd)(ef) 11 :: (fe)fff(fdr)fefff(fdr)f(ef) 12 :: (fe)ff(fdr)ffeff(fdr)ff(ef) 13 :: (fe)f(fdr)fffef(fdr)fff(ef) 14 :: (fe)(fdr)ffffe(fdr)ffff(ef) 15 :: (fe)(dr)fffff(dr)fffff(ef) 16 :: (fe)f(frd)fffff(frd)ffff(ef) 17 :: (fe)ff(frd)fffff(frd)fff(ef) 18 :: (fe)fff(frd)fffff(frd)ff(ef) 19 :: (fe)ffff(frd)fffff(frd)f(ef) 20 :: (fe)fffff(frd)fffff(frd)(ef) 21 :: (fe)ffffff(frd)fffff(rd)(ef) 22 :: (fe)fffffff(frd)fff(fdr)f(ef) 23 :: (fe)ffffffff(frd)f(fdr)ff(ef) 24 :: (fe)fffffffffXfff(ef) IPBLE: Increasing Performance By Lowering Expectations. 