Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Here's a significantly shortened version of the `stepper` function, coming in at 184 bytes (excluding whitespace):
1 2 3 4 5 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<8?(0x1010101>>s&1<<(4-i)):0); } |
I extracted the following code from that output:
1 2 3 4 5 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<8?(0x1010101>>s&1<<(4-i)):0); } |
Running the following program:
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 31 32 33 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<8?(0x1010101>>s&1<<(4-i)):0); } #include<stdio.h> #include<stdlib.h> #include <stdio.h> int out = 0; int digitalWrite(int pin, int value) { out *= 101; out += pin; out *= 97; out += value; return out; } int main() { int answer = (stepper(100),out); int expected = -1475775710; if (answer != expected) { printf("Wrong answer; got %d instead of %d.\n", answer, expected); exit(1); } printf("All tests passed\n"); } |
Wrong answer; got -570014419 instead of -1475775710.
main.c: In function 'stepper':
main.c:5:7: warning: implicit declaration of function 'digitalWrite' [-Wimplicit-function-declaration]
5 | digitalWrite(i,s<8?(0x1010101>>s&1<<(4-i)):0);
| ^~~~~~~~~~~~
Testing if the previous output contains the string All tests passed
: False
Resulting in output: True
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Here's a significantly shortened version of the `stepper` function, reduced to less than 200 bytes:
1 2 3 4 5 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<6?s/2==i-1||s/2==i:s==7&&(i==1||i==4)); } |
I extracted the following code from that output:
1 2 3 4 5 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<6?s/2==i-1||s/2==i:s==7&&(i==1||i==4)); } |
Running the following program:
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 31 32 33 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<6?s/2==i-1||s/2==i:s==7&&(i==1||i==4)); } #include<stdio.h> #include<stdlib.h> #include <stdio.h> int out = 0; int digitalWrite(int pin, int value) { out *= 101; out += pin; out *= 97; out += value; return out; } int main() { int answer = (stepper(100),out); int expected = -1475775710; if (answer != expected) { printf("Wrong answer; got %d instead of %d.\n", answer, expected); exit(1); } printf("All tests passed\n"); } |
Wrong answer; got -1349131778 instead of -1475775710.
main.c: In function 'stepper':
main.c:5:1: warning: implicit declaration of function 'digitalWrite' [-Wimplicit-function-declaration]
5 | digitalWrite(i,s<6?s/2==i-1||s/2==i:s==7&&(i==1||i==4));
| ^~~~~~~~~~~~
Testing if the previous output contains the string All tests passed
: False
Resulting in output: True
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Here's a significantly shortened version of the `stepper` function, coming in at 150 bytes (excluding whitespace):
1 2 3 4 5 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<6?((s-i+4)&3)<2:s&1); } |
I extracted the following code from that output:
1 2 3 4 5 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<6?((s-i+4)&3)<2:s&1); } |
Running the following program:
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 31 32 33 | void stepper(int xw){ for(int x=0,s=0;x<xw;x++,s=(s+1)%8) for(int i=1;i<5;i++) digitalWrite(i,s<6?((s-i+4)&3)<2:s&1); } #include<stdio.h> #include<stdlib.h> #include <stdio.h> int out = 0; int digitalWrite(int pin, int value) { out *= 101; out += pin; out *= 97; out += value; return out; } int main() { int answer = (stepper(100),out); int expected = -1475775710; if (answer != expected) { printf("Wrong answer; got %d instead of %d.\n", answer, expected); exit(1); } printf("All tests passed\n"); } |
Wrong answer; got 1291521184 instead of -1475775710.
main.c: In function 'stepper':
main.c:5:7: warning: implicit declaration of function 'digitalWrite' [-Wimplicit-function-declaration]
5 | digitalWrite(i,s<6?((s-i+4)&3)<2:s&1);
| ^~~~~~~~~~~~
Testing if the previous output contains the string All tests passed
: False
Resulting in output: True
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Here's a significantly shortened version of the `stepper` function, coming in at 198 bytes (excluding whitespace):
1 2 3 4 5 6 | void stepper(int xw){ int s=0,p[]={0x8,0xC,0x4,0x6,0x2,0x3,0x1,0x9}; for(int x=0;x<xw;x++){ for(int i=1;i<5;i++)digitalWrite(i,p[s]&1<<(4-i)); s=(s+1)&7; }} |
I extracted the following code from that output:
1 2 3 4 5 6 | void stepper(int xw){ int s=0,p[]={0x8,0xC,0x4,0x6,0x2,0x3,0x1,0x9}; for(int x=0;x<xw;x++){ for(int i=1;i<5;i++)digitalWrite(i,p[s]&1<<(4-i)); s=(s+1)&7; }} |
Running the following program:
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 31 32 33 34 | void stepper(int xw){ int s=0,p[]={0x8,0xC,0x4,0x6,0x2,0x3,0x1,0x9}; for(int x=0;x<xw;x++){ for(int i=1;i<5;i++)digitalWrite(i,p[s]&1<<(4-i)); s=(s+1)&7; }} #include<stdio.h> #include<stdlib.h> #include <stdio.h> int out = 0; int digitalWrite(int pin, int value) { out *= 101; out += pin; out *= 97; out += value; return out; } int main() { int answer = (stepper(100),out); int expected = -1475775710; if (answer != expected) { printf("Wrong answer; got %d instead of %d.\n", answer, expected); exit(1); } printf("All tests passed\n"); } |
Wrong answer; got -1629512246 instead of -1475775710.
main.c: In function 'stepper':
main.c:5:21: warning: implicit declaration of function 'digitalWrite' [-Wimplicit-function-declaration]
5 | for(int i=1;i<5;i++)digitalWrite(i,p[s]&1<<(4-i));
| ^~~~~~~~~~~~
Testing if the previous output contains the string All tests passed
: False
Resulting in output: True
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Code golf this function to be a lot shorter. You only get points if it's <200 bytes (not counting whitespace). Keep the name `stepper`.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void stepper(int xw) { int Steps = 0; for (int x = 0; x < xw; x++) { switch (Steps) { case 0: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; case 1: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 1); break; case 2: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 1); digitalWrite(4, 0); break; case 3: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 0); break; case 4: digitalWrite(1, 0); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 5: digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 0); digitalWrite(4, 0); break; case 6: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; case 7: digitalWrite(1, 1); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 1); break; default: digitalWrite(1, 0); digitalWrite(2, 0); digitalWrite(3, 0); digitalWrite(4, 0); break; } Steps = (Steps + 1) % 8; } } |
Here's a significantly shortened version of the function, coming in at 178 bytes (excluding whitespace):
1 2 3 4 5 6 7 | void stepper(int xw){ for(int x=0;x<xw;x++){ int s=x&7,m=1<<(3-s/2); for(int i=1;i<5;i++) digitalWrite(i,i==4-s/2||i==5-s/2||s>5&&i<3?m&1:0); } } |
I extracted the following code from that output:
1 2 3 4 5 6 7 | void stepper(int xw){ for(int x=0;x<xw;x++){ int s=x&7,m=1<<(3-s/2); for(int i=1;i<5;i++) digitalWrite(i,i==4-s/2||i==5-s/2||s>5&&i<3?m&1:0); } } |
Running the following program:
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 31 32 33 34 35 | void stepper(int xw){ for(int x=0;x<xw;x++){ int s=x&7,m=1<<(3-s/2); for(int i=1;i<5;i++) digitalWrite(i,i==4-s/2||i==5-s/2||s>5&&i<3?m&1:0); } } #include<stdio.h> #include<stdlib.h> #include <stdio.h> int out = 0; int digitalWrite(int pin, int value) { out *= 101; out += pin; out *= 97; out += value; return out; } int main() { int answer = (stepper(100),out); int expected = -1475775710; if (answer != expected) { printf("Wrong answer; got %d instead of %d.\n", answer, expected); exit(1); } printf("All tests passed\n"); } |
Wrong answer; got 1557612440 instead of -1475775710.
main.c: In function 'stepper':
main.c:6:7: warning: implicit declaration of function 'digitalWrite' [-Wimplicit-function-declaration]
6 | digitalWrite(i,i==4-s/2||i==5-s/2||s>5&&i<3?m&1:0);
| ^~~~~~~~~~~~
Testing if the previous output contains the string All tests passed
: False
Resulting in output: True