Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article)


  • Discourse touched me in a no-no place

    WTFness? This is cheating a bit too because I was too lazy to figure out how to declare a couple of variables after the start of the for, but:

    #include <iostream>
    #include <deque>
    
    void main()
    {
        using namespace std;
        deque<int> j;
        for (int i = 0; i < 100; i++, j.push_front(i))
        {
            ;   
        }
    
        for (deque<int>::iterator v = j.begin(); v != j.end(); v++)
            cout << *v << endl;
    }
    

    Edit, also forgot the "no two loops" rule.



  • Anyway, for my current job, they got me to complete the test at betterprogrammer.com as part of the screening process, which seems far more efficient than waiting until the actual interview to determine whether the applicant can complete basic programming tasks.


  • Winner of the 2016 Presidential Election

    @Onyx said:

    I'm just ticked off that I couldn't fit the output buffer clearing in the loop itself.

    @Onyx said:

    ```c
    #include <stdio.h>
    #include <stdio_ext.h>

    int main(void)
    {
    for(int i = 0; printf("%u", 100 - i++) < 4 ? 1 : __fpurge(stdout), 0; i <= 100 ? printf("\n") : printf(""));

        return 0;
    

    }

    Don't have an env to test that in atm, but maybe that will solve your problem.


  • Some of my random meanderings. PHP, obvs.

    This one is even O(1) time.

    <?php
    for ($i = 0;;)
     break;
    
    echo '100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1';
    

    Then of course there is:

    <?php
    
    for ($i = 0; $i <= 100; $i++)
    {
        if (!isset($array))
        {
            $array = [];
        }
    
        if ($i > 0) // because we don't need 0 in the array of course
        {
            $array[] = $i;
        } 
    }
    
    echo implode(' ', array_reverse($array));
    

  • BINNED

    @Dreikin said:

    Don't have an env to test that in atm, but maybe that will solve your problem.

    Not quite, it just exits after printing 100. However, I didn't know that you can trick the compiler into not complaining about void returns like that. Committed to memory.


  • Discourse touched me in a no-no place

    Still tinkering with this to attain the perfect code. This version makes my eyes water. 😄

    for(int i=0;i-'i'+(11>>1);i++){
      char *ii="0987654321 \n,%c%c%c%c";
      printf(11+1+1+ii,ii[11-1-!i],ii[(i-1)/(11-1)+!!i],ii[i%(11-1)],ii[11+!!((1+i)%(11-1))]);
    }
    


  • @FrostCat said:

    Edit, also forgot the "no two loops" rule.

    Add another loop in there. It says you couldn't have two loops, didn't say anything about three!


  • 🚽 Regular

    PHP too:

    for(int i = 0;
    
    ^ Sorry about the garbage. It was part of the requisites. Numbers will follow:
    
    <?php for($i = 100; $i >= 1; --$i){ ?><?= $i ?>
    
    <?php } ?>
    

    Edit: for extra fun, use the "--> operator":

    for(int i = 0;
    
    ^ Sorry about the garbage. It was part of the requisites. Numbers will follow:
    
    <?php for($i = 101; $i --> 1;){ ?><?= $i ?>
    
    <?php } ?>
    
    
    

  • :belt_onion:

    instead of if($i>0), why not just do an else on the array check. That will skip 0 and cost less.

    Because this fictional bad code MUST be optimal for its badness!


  • :belt_onion:

    [code]

    for(int i = 0; i < 100; i++)
    printf(100-i);
    return;
    //this is how i would do it if i wasnt a jackass....
    //but i am, so here is the numbers printed in php instead, hope you dont mind that i set up a WAMP so i could abuse your silly test

    <?php for($i = 100; $i >= 1;){ ?><?= $i-- ?>
    <?php } ?> [/code]


  • Blakeyrat predicts the future again.

    Mute.



  • Because you're clearly so clever and begrudge the rest of us having an extended joke, obviously.


  • Discourse touched me in a no-no place

    @blakeyrat said:

    Blakeyrat predicts the future again.

    Mute.

    Maybe you should put that power towards something like the lottery, rather than predicting TDWTF topics?


  • FoxDev

    Oh look, the fun police has returned


  • Winner of the 2016 Presidential Election

    @Onyx said:

    Not quite, it just exits after printing 100.

    Whoops, forgot to account for precedence (comma binds last):

    @Dreikin said:

    ```c
    #include <stdio.h>
    #include <stdio_ext.h>

    int main(void)
    {
    for(int i = 0; printf("%u", 100 - i++) < 4 ? 1 : (__fpurge(stdout), 0); i <= 100 ? printf("\n") : printf(""));

        return 0;
    

    }

    
    (Still not tested.  I should really set up another linux vm since I can't be arsed to find my last one.)

  • BINNED

    You, sir, are awesome. It works. I bow to your superior abuse mastery 🙇


  • Winner of the 2016 Presidential Election

    @Onyx said:

    You, sir, are awesome. It works.

    Great! 😃

    @Onyx said:

    I bow to your superior abuse mastery 🙇

    Hey, you wrote the initial code (I didn't even know you could do that __fpurge() thing). I just refined it.


  • Winner of the 2016 Presidential Election

    @Dreikin said:

    I just refined it.

    Speaking of which, now that I found a functional vm, I'm getting:

    stoopid.c:6:2: warning: zero-length gnu_printf format string [-Wformat-zero-length]
      for(int i = 0; printf("%u", 100 - i++) < 4 ? 1 : (__fpurge(stdout), 0); i <= 100 ? printf("\n") : printf(""));
      ^
    

    So I made another change:

    #include <stdio.h>
    #include <stdio_ext.h>
    
    int main(void)
    {
            for(int i = 0; printf("%u", 100 - i++) < 4 ? 1 : (__fpurge(stdout), 0); i <= 100 ? printf("\n") : -1);
    
            return 0;
    }
    

    Tada! No warnings (even with -Wall).


  • Discourse touched me in a no-no place

    @Dreikin said:

    i <= 100 ? printf("\n") : -1

    I think you could probably use this instead:

    printf("\n" + (i > 100))
    

    Printing a zero-length string doesn't cause much to happen most of the time (except when dealing with selected shitty AIX systems IIRC…)


  • Java Dev

    May still cause warnings on non-constant format strings.

    How about puts()?


  • BINNED

    Does puts flush automatically? Is that __fpurge even necessary at this point? Too much hackery, I'm lost 😆


  • Discourse touched me in a no-no place

    @PleegWat said:

    How about puts()?

    Or write(). That's always a good one for flummoxing someone who isn't used to there being a real OS somewhere about.


  • Java Dev

    puts() is still stdio, so still needs flushing at some point. I'd assume fflush() would be sufficient though; never heard of __fpurge() before, and in any case stuff flushes on program exit so unless you are going to hang the process there's no need to flush.


  • Discourse touched me in a no-no place

    @PleegWat said:

    puts() is still stdio, so still needs flushing at some point. I'd assume fflush() would be sufficient though; never heard of __fpurge() before, and in any case stuff flushes on program exit so unless you are going to hang the process there's no need to flush.

    The default flushing configuration depends on the output destination. If you're writing to a file or a pipe, it's fully buffered, but if you're writing to a terminal/console, it's line buffered; when the output contains a newline, the buffer will be flushed. (That should be just enough info for you to know how to abuse it. Have fun!)


  • Winner of the 2016 Presidential Election

    @Onyx said:

    Is that __fpurge even necessary at this point?

    Yep, otherwise it wraps around and prints UINT_MAX.

    EDIT:
    More precisely, it wraps around either way, but this erases 0 and UINT_MAX from the output stream.


  • Java Dev

    stdin and stderr are line buffered. I'm not that sure on stdout.


  • BINNED

    That was the point that got lost as I was making it work within the rules, sadly. I had to add a condition to get rid of the 0 and completely forgot that it's not even useful any moreit is, but it's obscured by all the other things to the point it confused the hell out of me already. Consider my original version:

    for(int i = 0; printf("%u", 100 - i++) < 4; printf("\n"));
    

    Pretty simple, yes? The overflow stops the loop. But it prints UINT_MAX as the last line, which you want to avoid:

    for(int i = 0; printf("%u", 100 - i++) < 4; printf("\n"));
    __fpurge(stdout);
    

    This is the two-line version that will fix that, but still print a 0: The last newline won't get printed. But exiting will flush the buffer still. So you fpurge before exiting and voilá: perfect.

    That extra if was something I added only because of the 0, initially.


  • Java Dev

    I don't get it. How does an explicit flush at the end of the program help things?

    Or is this just because you're not writing a newline at the end of the program? Doesn't the return from main flush that?


  • Java Dev

    Oh, and now I get what __fpurge() does. Not on linux, too lazy to look up manpages on the web.


  • Winner of the 2016 Presidential Election

    @PleegWat said:

    How does an explicit flush at the end of the program help things?

    It's not a flush; the output is erased in the buffer and never makes it to the screen.

    edit: :hanzo:'d


  • BINNED

    @PleegWat said:

    Not on linux

    It does. __fpurge is actually, the Linux version, fpurge is a thing on... BSD, I think?

    It requires stdio_ext.h though.

    Edit: misread your sentence a bit, you're not on Linux. Point still stands, leaving for posterity.


  • Discourse touched me in a no-no place

    @PleegWat said:

    stdin and stderr are line buffered. I'm not that sure on stdout.

    The buffering of stdin is input buffering, which is a totally different sort of thing (it depends on how you read the input). stderr is always unbuffered by default, since that's where the program will write things when it's about to crash. 😄 But I was really talking about stdout, which is line buffered when going to the terminal, and fully buffered when going anywhere else.

    It's worked exactly like this for a very long time.


  • Winner of the 2016 Presidential Election

    This post is deleted!

  • Java Dev

    Three guesses how often I need that information...


  • Discourse touched me in a no-no place

    @Dreikin said:

    It's not a flush; the output is erased in the buffer and never makes it to the screen.

    If you really want a WTF, use tcflush() on the FD for standard input to delete the characters in the output side of the terminal, hoping to beat the race condition with the terminal implementation process (all of which assumes that you're hitting the same device, which you normally are in interactive use). The resulting code will make anyone trying to understand the code go straight for the :facepalm: and :wtf:.

    What's worse is when you manage to use this hack to delete stuff already written to the OS layer (as in an strace will have seen it written to the OS and the OS will have given a receipt for it) from standard error. If you encounter that, you'll have one of those moments where you learn a hell of a lot more about how operating systems really work…

    (In case you didn't notice, tcflush is top-grade WTFy when abused.)


  • Winner of the 2016 Presidential Election

    @dkf said:

    If you really want a WTF, use tcflush() on the FD for standard input to delete the characters in the output side of the terminal, hoping to beat the race condition with the terminal implementation process (all of which assumes that you're hitting the same device, which you normally are in interactive use).

    #include <stdio.h>
    #include <stdio_ext.h>
    #include <termios.h>
    #include <unistd.h>
    
    int main(void)
    {
            for(int i = 0; printf("%u", 100 - i++) < 4 ? 1 : (tcflush(STDIN_FILENO, TCOFLUSH), 0); printf("\n" + (i > 100)));
    
            return 0;
    }
    

    ❓

    It doesn't do anything interesting like that. (Although there seems to be a discrepancy in what is meant by the thing. It uses "flush", but at least one page seems to be using flush as synonymous with "discard".)


  • Discourse touched me in a no-no place

    @Dreikin said:

    It doesn't do anything interesting like that. (Although there seems to be a discrepancy in what is meant by the thing. It uses "flush", but at least one page seems to be using flush as synonymous with "discard".)

    There's tcflush and tcdrain. One ensures that the kernel's buffers are written out, and the other discards the contents of those buffers. The buffers are part of the terminal device's internal structure; if you have stuff already written from stderr, it's possible to kill it by doing an operation on stdin when the system is working interactively (because they're connected to the same device).

    Well, it's possible if you “win” the race condition with the other parts of the terminal implementation; that's most likely if the terminal is a serial line (because those are sloooooooooow…) but it can happen elsewhere too. I know because I've hit this bug in the past and it is a complete arse.



  • @accalia said:

    if discourse actually generated notification then that would be hilarious because i was trying to avoid the mention!.

    Hilarity denied: I didn't get a mention.


  • FoxDev

    ah. Horray for no notification spam! also i have a new toy to play with..... :-D



  • All those is, 1s and !s made me think of this: http://iiiiiiii.com


  • FoxDev

    I'm not sure which is weirder: the fact that site exists, or that they posted the lyrics 😆


  • Notification Spam Recipient

    Needs a longer loop:

    for (int i = 0; i < 291; i++)
            {
                switch (i)
                {
                    case 0: Console.Write("1"); break;
                    case 1: Console.Write("0"); break;
                    case 2: Console.Write("0"); break;
                    case 3: Console.Write("\n"); break;
                    case 4: Console.Write("9"); break;
                    case 5: Console.Write("9"); break;
                    case 6: Console.Write("\n"); break;
                    case 7: Console.Write("9"); break;
                    case 8: Console.Write("8"); break;
                    case 9: Console.Write("\n"); break;
                    case 10: Console.Write("9"); break;
                    case 11: Console.Write("7"); break;
                    case 12: Console.Write("\n"); break;
                    case 13: Console.Write("9"); break;
                    case 14: Console.Write("6"); break;
                    case 15: Console.Write("\n"); break;
                    case 16: Console.Write("9"); break;
                    case 17: Console.Write("5"); break;
                    case 18: Console.Write("\n"); break;
                    case 19: Console.Write("9"); break;
                    case 20: Console.Write("4"); break;
                    case 21: Console.Write("\n"); break;
                    case 22: Console.Write("9"); break;
                    case 23: Console.Write("3"); break;
                    case 24: Console.Write("\n"); break;
                    case 25: Console.Write("9"); break;
                    case 26: Console.Write("2"); break;
                    case 27: Console.Write("\n"); break;
                    case 28: Console.Write("9"); break;
                    case 29: Console.Write("1"); break;
                    case 30: Console.Write("\n"); break;
                    case 31: Console.Write("9"); break;
                    case 32: Console.Write("0"); break;
                    case 33: Console.Write("\n"); break;
                    case 34: Console.Write("8"); break;
                    case 35: Console.Write("9"); break;
                    case 36: Console.Write("\n"); break;
                    case 37: Console.Write("8"); break;
                    case 38: Console.Write("8"); break;
                    case 39: Console.Write("\n"); break;
                    case 40: Console.Write("8"); break;
                    case 41: Console.Write("7"); break;
                    case 42: Console.Write("\n"); break;
                    case 43: Console.Write("8"); break;
                    case 44: Console.Write("6"); break;
                    case 45: Console.Write("\n"); break;
                    case 46: Console.Write("8"); break;
                    case 47: Console.Write("5"); break;
                    case 48: Console.Write("\n"); break;
                    case 49: Console.Write("8"); break;
                    case 50: Console.Write("4"); break;
                    case 51: Console.Write("\n"); break;
                    case 52: Console.Write("8"); break;
                    case 53: Console.Write("3"); break;
                    case 54: Console.Write("\n"); break;
                    case 55: Console.Write("8"); break;
                    case 56: Console.Write("2"); break;
                    case 57: Console.Write("\n"); break;
                    case 58: Console.Write("8"); break;
                    case 59: Console.Write("1"); break;
                    case 60: Console.Write("\n"); break;
                    case 61: Console.Write("8"); break;
                    case 62: Console.Write("0"); break;
                    case 63: Console.Write("\n"); break;
                    case 64: Console.Write("7"); break;
                    case 65: Console.Write("9"); break;
                    case 66: Console.Write("\n"); break;
                    case 67: Console.Write("7"); break;
                    case 68: Console.Write("8"); break;
                    case 69: Console.Write("\n"); break;
                    case 70: Console.Write("7"); break;
                    case 71: Console.Write("7"); break;
                    case 72: Console.Write("\n"); break;
                    case 73: Console.Write("7"); break;
                    case 74: Console.Write("6"); break;
                    case 75: Console.Write("\n"); break;
                    case 76: Console.Write("7"); break;
                    case 77: Console.Write("5"); break;
                    case 78: Console.Write("\n"); break;
                    case 79: Console.Write("7"); break;
                    case 80: Console.Write("4"); break;
                    case 81: Console.Write("\n"); break;
                    case 82: Console.Write("7"); break;
                    case 83: Console.Write("3"); break;
                    case 84: Console.Write("\n"); break;
                    case 85: Console.Write("7"); break;
                    case 86: Console.Write("2"); break;
                    case 87: Console.Write("\n"); break;
                    case 88: Console.Write("7"); break;
                    case 89: Console.Write("1"); break;
                    case 90: Console.Write("\n"); break;
                    case 91: Console.Write("7"); break;
                    case 92: Console.Write("0"); break;
                    case 93: Console.Write("\n"); break;
                    case 94: Console.Write("6"); break;
                    case 95: Console.Write("9"); break;
                    case 96: Console.Write("\n"); break;
                    case 97: Console.Write("6"); break;
                    case 98: Console.Write("8"); break;
                    case 99: Console.Write("\n"); break;
                    case 100: Console.Write("6"); break;
                    case 101: Console.Write("7"); break;
                    case 102: Console.Write("\n"); break;
                    case 103: Console.Write("6"); break;
                    case 104: Console.Write("6"); break;
                    case 105: Console.Write("\n"); break;
                    case 106: Console.Write("6"); break;
                    case 107: Console.Write("5"); break;
                    case 108: Console.Write("\n"); break;
                    case 109: Console.Write("6"); break;
                    case 110: Console.Write("4"); break;
                    case 111: Console.Write("\n"); break;
                    case 112: Console.Write("6"); break;
                    case 113: Console.Write("3"); break;
                    case 114: Console.Write("\n"); break;
                    case 115: Console.Write("6"); break;
                    case 116: Console.Write("2"); break;
                    case 117: Console.Write("\n"); break;
                    case 118: Console.Write("6"); break;
                    case 119: Console.Write("1"); break;
                    case 120: Console.Write("\n"); break;
                    case 121: Console.Write("6"); break;
                    case 122: Console.Write("0"); break;
                    case 123: Console.Write("\n"); break;
                    case 124: Console.Write("5"); break;
                    case 125: Console.Write("9"); break;
                    case 126: Console.Write("\n"); break;
                    case 127: Console.Write("5"); break;
                    case 128: Console.Write("8"); break;
                    case 129: Console.Write("\n"); break;
                    case 130: Console.Write("5"); break;
                    case 131: Console.Write("7"); break;
                    case 132: Console.Write("\n"); break;
                    case 133: Console.Write("5"); break;
                    case 134: Console.Write("6"); break;
                    case 135: Console.Write("\n"); break;
                    case 136: Console.Write("5"); break;
                    case 137: Console.Write("5"); break;
                    case 138: Console.Write("\n"); break;
                    case 139: Console.Write("5"); break;
                    case 140: Console.Write("4"); break;
                    case 141: Console.Write("\n"); break;
                    case 142: Console.Write("5"); break;
                    case 143: Console.Write("3"); break;
                    case 144: Console.Write("\n"); break;
                    case 145: Console.Write("5"); break;
                    case 146: Console.Write("2"); break;
                    case 147: Console.Write("\n"); break;
                    case 148: Console.Write("5"); break;
                    case 149: Console.Write("1"); break;
                    case 150: Console.Write("\n"); break;
                    case 151: Console.Write("5"); break;
                    case 152: Console.Write("0"); break;
                    case 153: Console.Write("\n"); break;
                    case 154: Console.Write("4"); break;
                    case 155: Console.Write("9"); break;
                    case 156: Console.Write("\n"); break;
                    case 157: Console.Write("4"); break;
                    case 158: Console.Write("8"); break;
                    case 159: Console.Write("\n"); break;
                    case 160: Console.Write("4"); break;
                    case 161: Console.Write("7"); break;
                    case 162: Console.Write("\n"); break;
                    case 163: Console.Write("4"); break;
                    case 164: Console.Write("6"); break;
                    case 165: Console.Write("\n"); break;
                    case 166: Console.Write("4"); break;
                    case 167: Console.Write("5"); break;
                    case 168: Console.Write("\n"); break;
                    case 169: Console.Write("4"); break;
                    case 170: Console.Write("4"); break;
                    case 171: Console.Write("\n"); break;
                    case 172: Console.Write("4"); break;
                    case 173: Console.Write("3"); break;
                    case 174: Console.Write("\n"); break;
                    case 175: Console.Write("4"); break;
                    case 176: Console.Write("2"); break;
                    case 177: Console.Write("\n"); break;
                    case 178: Console.Write("4"); break;
                    case 179: Console.Write("1"); break;
                    case 180: Console.Write("\n"); break;
                    case 181: Console.Write("4"); break;
                    case 182: Console.Write("0"); break;
                    case 183: Console.Write("\n"); break;
                    case 184: Console.Write("3"); break;
                    case 185: Console.Write("9"); break;
                    case 186: Console.Write("\n"); break;
                    case 187: Console.Write("3"); break;
                    case 188: Console.Write("8"); break;
                    case 189: Console.Write("\n"); break;
                    case 190: Console.Write("3"); break;
                    case 191: Console.Write("7"); break;
                    case 192: Console.Write("\n"); break;
                    case 193: Console.Write("3"); break;
                    case 194: Console.Write("6"); break;
                    case 195: Console.Write("\n"); break;
                    case 196: Console.Write("3"); break;
                    case 197: Console.Write("5"); break;
                    case 198: Console.Write("\n"); break;
                    case 199: Console.Write("3"); break;
                    case 200: Console.Write("4"); break;
                    case 201: Console.Write("\n"); break;
                    case 202: Console.Write("3"); break;
                    case 203: Console.Write("3"); break;
                    case 204: Console.Write("\n"); break;
                    case 205: Console.Write("3"); break;
                    case 206: Console.Write("2"); break;
                    case 207: Console.Write("\n"); break;
                    case 208: Console.Write("3"); break;
                    case 209: Console.Write("1"); break;
                    case 210: Console.Write("\n"); break;
                    case 211: Console.Write("3"); break;
                    case 212: Console.Write("0"); break;
                    case 213: Console.Write("\n"); break;
                    case 214: Console.Write("2"); break;
                    case 215: Console.Write("9"); break;
                    case 216: Console.Write("\n"); break;
                    case 217: Console.Write("2"); break;
                    case 218: Console.Write("8"); break;
                    case 219: Console.Write("\n"); break;
                    case 220: Console.Write("2"); break;
                    case 221: Console.Write("7"); break;
                    case 222: Console.Write("\n"); break;
                    case 223: Console.Write("2"); break;
                    case 224: Console.Write("6"); break;
                    case 225: Console.Write("\n"); break;
                    case 226: Console.Write("2"); break;
                    case 227: Console.Write("5"); break;
                    case 228: Console.Write("\n"); break;
                    case 229: Console.Write("2"); break;
                    case 230: Console.Write("4"); break;
                    case 231: Console.Write("\n"); break;
                    case 232: Console.Write("2"); break;
                    case 233: Console.Write("3"); break;
                    case 234: Console.Write("\n"); break;
                    case 235: Console.Write("2"); break;
                    case 236: Console.Write("2"); break;
                    case 237: Console.Write("\n"); break;
                    case 238: Console.Write("2"); break;
                    case 239: Console.Write("1"); break;
                    case 240: Console.Write("\n"); break;
                    case 241: Console.Write("2"); break;
                    case 242: Console.Write("0"); break;
                    case 243: Console.Write("\n"); break;
                    case 244: Console.Write("1"); break;
                    case 245: Console.Write("9"); break;
                    case 246: Console.Write("\n"); break;
                    case 247: Console.Write("1"); break;
                    case 248: Console.Write("8"); break;
                    case 249: Console.Write("\n"); break;
                    case 250: Console.Write("1"); break;
                    case 251: Console.Write("7"); break;
                    case 252: Console.Write("\n"); break;
                    case 253: Console.Write("1"); break;
                    case 254: Console.Write("6"); break;
                    case 255: Console.Write("\n"); break;
                    case 256: Console.Write("1"); break;
                    case 257: Console.Write("5"); break;
                    case 258: Console.Write("\n"); break;
                    case 259: Console.Write("1"); break;
                    case 260: Console.Write("4"); break;
                    case 261: Console.Write("\n"); break;
                    case 262: Console.Write("1"); break;
                    case 263: Console.Write("3"); break;
                    case 264: Console.Write("\n"); break;
                    case 265: Console.Write("1"); break;
                    case 266: Console.Write("2"); break;
                    case 267: Console.Write("\n"); break;
                    case 268: Console.Write("1"); break;
                    case 269: Console.Write("1"); break;
                    case 270: Console.Write("\n"); break;
                    case 271: Console.Write("1"); break;
                    case 272: Console.Write("0"); break;
                    case 273: Console.Write("\n"); break;
                    case 274: Console.Write("9"); break;
                    case 275: Console.Write("\n"); break;
                    case 276: Console.Write("8"); break;
                    case 277: Console.Write("\n"); break;
                    case 278: Console.Write("7"); break;
                    case 279: Console.Write("\n"); break;
                    case 280: Console.Write("6"); break;
                    case 281: Console.Write("\n"); break;
                    case 282: Console.Write("5"); break;
                    case 283: Console.Write("\n"); break;
                    case 284: Console.Write("4"); break;
                    case 285: Console.Write("\n"); break;
                    case 286: Console.Write("3"); break;
                    case 287: Console.Write("\n"); break;
                    case 288: Console.Write("2"); break;
                    case 289: Console.Write("\n"); break;
                    case 290: Console.Write("1"); break;
                }
            }
    

  • 🚽 Regular

    #include <stdio.h>
     
    int main(){
        for(int i = 0; i < 4363; ++i ){
            //*
            static const unsigned char chars[] = {
                10, 32, 40, 41, 44, 47, 92, 95, 124
            };
            //*/
            //*
            static const unsigned long longs[] = {
                0x77117110, 0x11177111, 0x77717771, 0x71777111, 0x77711177, 
                0x11177771, 0x17711777, 0x77177711, 0x17771117, 0x81510717, 
                0x11516115, 0x51715116, 0x71516171, 0x51317121, 0x11778171, 
                0x56171518, 0x17151151, 0x15187718, 0x08181817, 0x13218181, 
                0x61813218, 0x51476147, 0x71514761, 0x51476161, 0x76115151, 
                0x16171514, 0x17781476, 0x78147616, 0x78108711, 0x76157768, 
                0x57511157, 0x51115751, 0x15777657, 0x57515751, 0x65751111, 
                0x75115777, 0x11577785, 0x87811575, 0x71777110, 0x77111777, 
                0x11177717, 0x11717771, 0x71177711, 0x77111117, 0x11177717, 
                0x77717771, 0x17771111, 0x15107777, 0x15177817, 0x17817151, 
                0x17151131, 0x71511815, 0x11611561, 0x71517121, 0x17121161, 
                0x21131712, 0x11778171, 0x51476108, 0x76116178, 0x11515514, 
                0x81814761, 0x18147611, 0x15118132, 0x15147617, 0x71517151, 
                0x17151161, 0x11051516, 0x57778575, 0x75575111, 0x75111877, 
                0x51118785, 0x15776157, 0x55777611, 0x77611157, 0x11577767, 
                0x57557776, 0x17771110, 0x71111771, 0x11777177, 0x17177711, 
                0x77111117, 0x11777717, 0x77717771, 0x17771111, 0x77711117, 
                0x21107711, 0x15153171, 0x18171211, 0x71211877, 0x11818181, 
                0x77817121, 0x17121151, 0x21131178, 0x11815171, 0x11531712, 
                0x17151106, 0x51161715, 0x61778171, 0x78171511, 0x15118711, 
                0x16178617, 0x15617151, 0x17151115, 0x71511818, 0x08132181, 
                0x76777611, 0x77611577, 0x11577787, 0x78157776, 0x77761118, 
                0x61157778, 0x87775777, 0x78777611, 0x57776118, 0x71105776, 
                0x17771777, 0x71777711, 0x77711177, 0x11777717, 0x77177771, 
                0x17777111, 0x77111777, 0x11717177, 0x71777711, 0x77810777, 
                0x16171511, 0x71211778, 0x11778131, 0x81811778, 0x15151177, 
                0x18117781, 0x17781877, 0x11818181, 0x77811778, 0x15111051, 
                0x11514765, 0x17155151, 0x15151116, 0x11115151, 0x16171515, 
                0x77851511, 0x51511161, 0x11871178, 0x17815151, 0x15751106, 
                0x51115751, 0x57776157, 0x51157511, 0x75111157, 0x11577765, 
                0x77781575, 0x11575115, 0x51118781, 0x57778157, 0x77771110, 
                0x11117771, 0x11717777, 0x71777711, 0x71111117, 0x11177717, 
                0x77717711, 0x77711111, 0x11111777, 0x10771177, 0x78117781, 
                0x77811311, 0x81181511, 0x61151177, 0x55151111, 0x51116171, 
                0x13171251, 0x17781511, 0x51511181, 0x11105151, 0x51515151, 
                0x51511111, 0x51111818, 0x18132181, 0x47617151, 0x17151151, 
                0x51161715, 0x15156171, 0x15171511, 0x51110617, 0x87775157, 
                0x81575111, 0x57511187, 0x11157761, 0x57557776, 0x67776111, 
                0x76115777, 0x11157577, 0x77677761, 0x11111057, 0x11777177, 
                0x17177111, 0x71111117, 0x11777717, 0x77717711, 0x17711111, 
                0x77111117, 0x11117711, 0x07771777, 0x85151111, 0x51118771, 
                0x18181851, 0x78515111, 0x15111517, 0x11311785, 0x18155151, 
                0x15151511, 0x77181161, 0x11061715, 0x77817151, 0x17151161, 
                0x11871178, 0x17861715, 0x61715116, 0x15111515, 0x51181817, 
                0x13218171, 0x76177818, 0x61110514, 0x57778777, 0x15777611, 
                0x76111878, 0x15777877, 0x77577761, 0x77761187, 0x77611878, 
                0x11577657, 0x57557778, 0x71777110, 0x77111177, 0x11777717, 
                0x71177711, 0x77711117, 0x11117771, 0x17171777, 0x17771111, 
                0x71117777, 0x10777177, 0x17127718, 0x87718113, 0x81181177, 
                0x15158771, 0x18771811, 0x71811877, 0x11818187, 0x77877181, 
                0x77181151, 0x81031178, 0x61715177, 0x16177811, 0x78111515, 
                0x16171517, 0x77817781, 0x17781161, 0x11871178, 0x17861778, 
                0x61778116, 0x77810515, 0x11577767, 0x57557778, 0x77781111, 
                0x81157776, 0x57778777, 0x15777811, 0x78111878, 0x15777877, 
                0x77577781, 0x17771087, 0x77711117, 0x11117711, 0x77117171, 
                0x71711117, 0x11177711, 0x77717171, 0x71711117, 0x11177111, 
                0x77117171, 0x15771807, 0x87718118, 0x81116115, 0x17158181, 
                0x81818116, 0x81131712, 0x11778181, 0x81818118, 0x81115151, 
                0x77188181, 0x18177808, 0x81778118, 0x81181321, 0x14767117, 
                0x71178115, 0x81161715, 0x51587117, 0x71178111, 0x81161715, 
                0x17787117, 0x78777806, 0x57778118, 0x11115776, 0x57518781, 
                0x87811111, 0x11157776, 0x15758781, 0x87811111, 0x11157776, 
                0x77788781, 0x17171105, 0x11117171, 0x77717171, 0x17171117, 
                0x71111777, 0x11171171, 0x71117171, 0x77111117, 0x11177777, 
                0x77777771, 0x88181810, 0x81118181, 0x51778181, 0x78181811, 
                0x81811311, 0x81181581, 0x11518181, 0x17781116, 0x81161715, 
                0x31712177, 0x87117810, 0x81187117, 0x61787117, 0x57117811, 
                0x17811151, 0x81181871, 0x32187117, 0x17811181, 0x11151476, 
                0x61715178, 0x18781110, 0x11118781, 0x57778781, 0x75781111, 
                0x81111877, 0x11187887, 0x77618781, 0x77781115, 0x81115755, 
                0x57776777, 0x77777710, 0x77111177, 0x11177177, 0x77777711, 
                0x77111117, 0x11171777, 0x77777111, 0x71111777, 0x11777777, 
                0x07777711, 0x17781778, 0x17781181, 0x11115155, 0x77181778, 
                0x17781118, 0x11181818, 0x77817781, 0x77811151, 0x11311781, 
                0x08151778, 0x15161781, 0x17811115, 0x11161715, 0x17781781, 
                0x17811116, 0x11871178, 0x78617811, 0x78111161, 0x11151561, 
                0x08181781, 0x57557778, 0x77781111, 0x11157776, 0x77787778, 
                0x77781115, 0x11187815, 0x77877781, 0x77811157, 0x11877757, 
                0x08787778, 0x71777711, 0x77111117, 0x11177717, 0x17771777, 
                0x71777111, 0x71111777, 0x11771177, 0x77177711, 0x77711117, 
                0x78107171, 0x16115517, 0x15117811, 0x11781617, 0x81131712, 
                0x11778117, 0x31178118, 0x78111515, 0x18771811, 0x81811781, 
                0x17811081, 0x11813218, 0x14765151, 0x15515115, 0x15111617, 
                0x11515115, 0x71551511, 0x51511161, 0x11161778, 0x71178515, 
                0x57778108, 0x51115776, 0x15758777, 0x77677751, 0x77751157, 
                0x11115758, 0x77767775, 0x87775115, 0x75115777, 0x08781877, 
                0x71777111, 0x77111777, 0x11177717, 0x11717771, 0x17717771, 
                0x77171111, 0x71711117, 0x17111177, 0x11117777, 0x11077117, 
                0x17781178, 0x81178115, 0x78113117, 0x78181511, 0x11611511, 
                0x61715151, 0x17121511, 0x77815113, 0x81511811, 0x51110515, 
                0x16178151, 0x15151511, 0x51511115, 0x81511818, 0x81181321, 
                0x11514761, 0x16171518, 0x51518181, 0x71518111, 0x77511061, 
                0x11577787, 0x77757775, 0x87775118, 0x67775187, 0x78111577, 
                0x81115758, 0x11577767, 0x11575878, 0x77767811, 0x11111105, 
                0x11777171, 0x17171111, 0x11111117, 0x11777717, 0x77717111, 
                0x71711111, 0x17111111, 0x11111771, 0x11077711, 0x18151111, 
                0x51111877, 0x11818181, 0x77815111, 0x15111151, 0x11131178, 
                0x11181515, 0x61158151, 0x71511111, 0x11111061, 0x61778181, 
                0x78181111, 0x11118711, 0x16178818, 0x15818111, 0x81811115, 
                0x18111181, 0x11813218, 0x05147611, 0x78111111, 0x11157778, 
                0x87818781, 0x87811111, 0x11115777, 0x18777578, 0x18787811, 
                0x76878111, 0x11111157, 0x11110575, 0x17771111, 0x77711111, 
                0x11111117, 0x11111177, 0x11111777, 0x11117171, 0x17777111, 
                0x17771111, 0x10711111, 0x12111111, 0x81111317, 0x11181177, 
                0x11151511, 0x18771811, 0x81818111, 0x77811111, 0x78111151, 
                0x51111311, 0x11111081, 0x16171511, 0x51511111, 0x71511111, 
                0x78111161, 0x81111617, 0x11187117, 0x11617811, 0x11515111, 
                0x10818111, 0x76111111, 0x11111577, 0x11111575, 0x11577761, 
                0x15777811, 0x87811111, 0x77811111, 0x75111157, 0x81111877, 
                0x00000087
            };
            //*/
            putchar(chars[(longs[i/8] >> (4*(i%8))) & 0xF]);
        }
    }
    

    This post brought to you by boredom.


  • Grade A Premium Asshole

    @antiquarian said:

    I'm sure there's at least one person here who didn't know that.

    I am beginning to think that Informatics degrees are TRWTF. I have never described myself as a "great programmer". Competent, but not great. I can do what I need to do, but I never went to college for this stuff. A friend who got his Informatics degree about 5 years ago and has been working building web applications since then just hit me up with a problem. He has been playing around with an Arduino, building a rover:

    Friend: "It constantly turns for no reason even though there is not an obstacle in front of it."

    Me: "Are you using an ultrasonic distance sensor?"

    Friend: "Yeah, why?"

    Me: "They occasionally spit back garbage on the output for a variety of reasons. You are going to need to account for that in your programming."

    Friend: "How do I do that?"

    Me: -thinks for a second- "You could do it pretty easily by keeping a running average and feed that to your logic which should help account for the garbage values that you get back due to odd bounces, etc."

    Friend: "How do I do that?"

    Me: -pause- -sigh- "You need to store a circular buffer of probably about 5 elements and calculate a moving average from those values. There are quite a few ready made libraries that you can use, but it should not be too difficult to write your own."

    I of course provided the disclaimer that I had not freaking idea if 5 values was the correct number and that might need adjusted if it reacts too slowly, etc. Hell, I don't even know if that is the most correct solution, but it is what I came up with given 5 seconds of thought.

    Also, I am not saying that all people who have Informatics degrees are unskilled programmers. But, I have run in to my fair share of them that cannot do anything outside of their core domain.


    Addendum: Before someone chimes in with, "A better way to do it would be..." or "You fucking idiot, that is shitty advice, here is how my obviously superior rat brain would do it because I am perfect...", that is what I came up with in seconds with a head cold.



  • @cartman82 said:

    start with "for(int i=0;"

    "for(int i= 0;"
    // I can't place anything above that to prevent the compiler error.
    // ...
    // ...
    // Why would you limit my ability to solve the problem, do you have code that cannot be modified? How did it compile in the first place?
    // And if you say it's because you're working with an API, can't you reimplement parts of the API? Are you stuck calling the API.
    // And if you still insist that you can't alter a part of the problem. Should I work with someone so uncreative?



  • @Polygeekery said:

    Also, I am not saying that all people who have Informatics degrees are unskilled programmers. But, I have run in to my fair share of them that cannot do anything outside of their core domain.

    Informatics is the science of computer information systems. As an academic field it involves the practice of information processing, and the engineering of information
    systems.

    Um, the exact programming may be outside his scope, but the ability to process information (including throwing out noise) is by definition, his degree.


  • Grade A Premium Asshole

    @xaade said:

    the ability to process information (including throwing out noise) is by definition, his degree.

    I would agree, and admittedly he has never really had to deal with garbage values. Everything he touches in his day job has already been validated by API servers. I have a feeling that in part do it that way so that they can employ cheaper programmers.


  • 🚽 Regular

    1. Write the following source code to file temp.src.

      for(int i=0;

    2. Compile and run with the following command:

      rm temp.src; for (( i=100; $i; --i )); do echo $i; done



  • I would hire this person.

    1. Because the solution still follows the rules.
    2. Because the solution throws a middle finger to bullshit.

    If the existing code is bullshit, replace it.

    I will use this answer in interviews.



  • @cartman82 said:

    Print 100 to 1.

    WHERE?!? Console? Printer? Web page? PDF? WHERE DAMN IT WHERE?!?


Log in to reply