This is fairly difficult, i feel that they meticulously made it tough lol. Some of the problems that arose seem intentional.
like a boss...
This is fairly difficult, i feel that they meticulously made it tough lol. Some of the problems that arose seem intentional.
like a boss...
Last edited by Structure; 01-10-2020 at 11:00 AM.
"without goto we would be wtf'd"
Last edited by Structure; 01-10-2020 at 11:48 AM.
"without goto we would be wtf'd"
Yep, I linked the book from the Amazon website in my post which says the latest delivery is by Tuesday but I didn't order it from Amazon lol Found another website that was delivering within 24 hours and so placed the order on there . It's arrived now and I'm going to start reading it tonight. And really, I found it good just by looking at the reviews and Wiki, and I think it'll be a good adventure reading it. Thanks.
Also, thanks to everyone who participated in this discussion. Really nice ideas have emerged (the linear solution by Hodor!) out of this discussion and have opened different ways for me to think in while solving problems.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled
working on the formula...
Last edited by Structure; 01-14-2020 at 03:04 PM.
"without goto we would be wtf'd"
Code:if (time > 86) passWord = (((time-86)*20)+1094);
Last edited by Structure; 01-14-2020 at 03:39 PM.
"without goto we would be wtf'd"
That would work only for a specific test case, not all possible cases. If this formula was meant for the original test sample, your equation is wrong. Test it out yourself
What was the sample test you used which led you to this formula?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled
It is correct. Perhaps you are using it wrong?
The initial input is stated in the problem.
Last edited by Structure; 01-15-2020 at 09:56 AM.
For the first 86 you have to use your algorithm to get the correct passwords.
The pattern starts at 86... for any time over 86:This is a "shortcut".Code:passWord = (((time-86)*20)+1094)
time: 1001 = 19394
time: 50000000000 = 999999999374
as far as correct goes, every password at time, and strings displayed in the problem are 100% accurate.
your equation is wrong
Last edited by Structure; 01-15-2020 at 10:13 AM.
"without goto we would be wtf'd"
If the algorithm is working correctly it should look like this...
initial state: ....#..#.#..##......###...###....
001: 091 ....#...#....#.....#..#..#..#..................TIME: PASSWORD STRING
002: 132 ....##..##...##....#..#..#..##................
003: 102 ...#.#...#..#.#....#..#..#...#................
004: 154 ....#.#..#...#.#...#..#..##..##...............
005: 115 .....#...##...#.#..#..#...#...#...............
006: 174 .....##.#.#....#...#..##..##..##..............
007: 126 ....#..###.#...##..#...#...#...#..............
008: 213 ....#....##.#.#.#..##..##..##..##.............
009: 138 ....##..#..#####....#...#...#...#.............
010: 213 ...#.#..#...#.##....##..##..##..##............
011: 136 ....#...##...#.#...#.#...#...#...#............
012: 218 ....##.#.#....#.#...#.#..##..##..##...........
013: 133 ...#..###.#....#.#...#....#...#...#...........
014: 235 ...#....##.#....#.#..##...##..##..##..........
015: 149 ...##..#..#.#....#....#..#.#...#...#..........
016: 226 ..#.#..#...#.#...##...#...#.#..##..##.........
017: 170 ...#...##...#.#.#.#...##...#....#...#.........
018: 280 ...##.#.#....#####.#.#.#...##...##..##........
019: 287 ..#..###.#..#.#.#######.#.#.#..#.#...#........
020: 325 ..#....##....#####...#######....#.#..##.......
verified by: http://www.hpcodewars.org/past/cw22/...ProblemSet.pdf
Last edited by Structure; 01-15-2020 at 11:37 AM.
"without goto we would be wtf'd"
Oh yes, my bad. Sorry about that. I subtracted 84 instead of 86 which led me to think that the equation was wrong. Well done
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled
Thank You. Being polite goes a long way.
How i solved this problem...
Code:#include <stdio.h> #include <string.h> #define bit 4 char *buffer; char sit = '.', stand = '#'; char *initPattern = "#..#.#..##......###...###"; double time = 0.0; char *mask = "...##..#...#....#.#..#.##.##...#####.#.##.#####.#.##.#####..###.#####."; int mask_bits[14], places[128]; char toMatch[1024]; int addDots = 0; char new_string[1024], string_buffer[1024]; int starter = 0; double currentIndex; double setString(char *string) { int counter = 0, last = 0; double passValue = 0; int isReading = 0, bit_count = 0; memset(string_buffer,0,strlen(string_buffer)); while (counter < strlen(string)) { if (string[counter] == '#') { last = (counter+1); if (starter == 0) { starter = counter; if (counter == 0) strcat(string_buffer,"..."); }; passValue = (passValue + (counter)); }; counter++; addDots = (counter-last); }; if ((bit-starter) > 0) { if (currentIndex == 1) { for (int i=0;i<(bit-starter);i++) { strcat(string_buffer,"."); }; }; }; strcat(string_buffer,string); return passValue; }; void doDots() { for (int i=0;i<(bit-addDots);i++) strcat(string_buffer,"."); }; float cull(char *string,int count) { int kickValue = 0; for (int x=0;x<5;x++) { if (string[count-x] == '#') { if (x == 0) kickValue += 1; if (x == 1) kickValue += 2; if (x == 2) kickValue += 4; if (x == 3) kickValue += 8; if (x == 4) kickValue += 16; }; }; return kickValue; }; void patternLock(char *string) { int counter = 0, startRead = 0; int readCount = 0; memset(toMatch,0,sizeof(toMatch)); while (counter < strlen(string)) { if (counter == 4) startRead = 1; if (startRead == 1) { toMatch[counter-starter] = cull(string,counter-1); readCount += 1; }; counter++; }; }; void validMatches() { int ii = 0, ix = 0; for (int i=0;i<strlen(mask);i++) { ii++; if (ii == 5) { ii = 0; mask_bits[ix] = (int)cull(mask,i); ix++; }; }; }; double retrieve(char *string) { double x = setString(string); return x; }; void incorpPlaces() { memset(places,0,sizeof(places)); for (int b=0;b<sizeof(toMatch);b++) { for (int c=0;c<(sizeof(mask_bits)/sizeof(int));c++) { if ((mask_bits[c] == toMatch[b]) && (toMatch[b] != 0) ) { places[b] = mask_bits[c]; }; }; }; }; void displayResult(int id) { if (id < 100) printf("0"); if (id < 10) printf("0"); printf("%i: ",id); int passCode = 0; memset(new_string,0,strlen(new_string)); for (int i=0;i<(128);i++) { if (places[i] != 0) { strcat(new_string,"#"); passCode += i-4; } else { strcat(new_string,"."); }; }; printf("%i_",passCode); printf("%s\n",new_string); }; int main(int args, char *argv[]) { int maxGen = 100; validMatches(); currentIndex = 1; retrieve(initPattern); doDots(); printf("\n000: %s\n",string_buffer); patternLock(string_buffer); incorpPlaces(); displayResult(currentIndex); for (int lot=2;lot<=maxGen;lot++) { currentIndex = lot; retrieve(new_string); patternLock(string_buffer); incorpPlaces(); displayResult(currentIndex); }; return 0; };
Last edited by Structure; 01-16-2020 at 02:07 PM.
"without goto we would be wtf'd"
That only solves the simple where: a) the cycle length is 1; and b) the cycle repeats. It doesn't deal with input like
Which makes a much prettier dance:Code:initial state ".#." patterns "....#" "#...."
But much more difficult to solve
Edit: I wish I still had my code now. Anyway, The Nature of Code section 7.2. Look familiar? Now, there's probably a way to work calculate generation t for this particular case, like it's possible for the ones that end up being linear or semi-linear (cycling) but then how many other special cases are there and what if we get a random (see section 7.5 Wolfram Classification) one? I'm just going with what I said originally and considering this solved for cases where the pattern repeats in cycles of length=1 (i.e. the password being linear and the state being a "class 1" Wolfram class) (Cellular automaton - Wikipedia)
Last edited by Hodor; 01-16-2020 at 10:05 PM.
Some interesting reading as well (second link). In the second link scroll down to look at the graphs and read the discussion. Also worth reading is the section called "how hard are the problems? which is right at the bottom of the second link
Wolfram Rule 30 Prizes
Announcing the Rule 30 Prizes—Stephen Wolfram Writings
Last edited by Hodor; 01-16-2020 at 10:29 PM.
yep...Look familiar?
I had to alter the code a little bit:initial state ".#."
patterns
"....#"
"#...."
interesting...
Last edited by Structure; 01-17-2020 at 10:07 AM.
"without goto we would be wtf'd"
understatement.much more difficult to solve
"without goto we would be wtf'd"