Live data from Hacker News

What is the coolest thing you can do in ten lines of code?

stackoverflow.com

21–30 of 40 posts

Re: What is the coolest thing you can do in ten lines of code?

#21
post #5

Less than 10 bytes of code on an Apple II: ] CALL -151 * 300: AD 30 CO 20 ED FD 4C 00 03 * 300G Enjoy! For bonus points, get this down to 8 bytes.

I used to do that kind of hacking in the 80's. I recognized the CALL-151. I have an old Apple II+ in the other room I'm tempted to try firing up just to solve this mystery.

  NEW
  1HOME:A=9200:B=13168:C=100:FORI=768TO796:READN:POKEI,N:NEXT:HGR:POKE-16302,0:HCOLOR=4:HPLOT0,0:CALL62454:HCOLOR=2:HPLOT0,63TO279,63:HPLOT0,62TO279,62:HCOLOR=6:HPLOT0,61TO279,61:HPLOT0,60TO279,60:HCOLOR=1:HPLOT0,59TO279,59:HPLOT0,58TO279,58
  2HCOLOR=5:HPLOT0,55TO279,55:HPLOT0,54TO279,54:HCOLOR=0:HPLOT0,123TOC,123:HPLOT0,122TOC,122:HPLOT0,119TOC,119:HPLOT0,118TOC,118:COLOR=0:FORI=0TO39:VLIN0,39ATI:NEXT:COLOR=13:HLIN0,39AT14:FORI=0TO7:POKEA+I,0:POKEB+I,0:NEXT:COLOR=1
  3HLIN0,39AT13:VTAB21:PRINTTAB(16)"RAINBOW":PRINT:PRINT"MIXED GRAPHICS (HI-RES/COLOR)":CALL768:DATA173,87,192,173,83,192,173,84,192,173,80,192,208,251,173,86,192,160,22,136,208,253,234,173,87,192,76,9,3
  RUN

Re: What is the coolest thing you can do in ten lines of code?

#22

Earlier quoted context omitted.

I used to do that kind of hacking in the 80's. I recognized the CALL-151. I have an old Apple II+ in the other room I'm tempted to try firing up just to solve this mystery.

For people who didn't hack apple IIs, can you expand on what's going on there?

; enter the machine language monitor

  CALL -151
; toggle the speaker and load the accumulator with the "floating bus" value--the byte last read by the video refresh controlled by the video scanner.

  0300-   AD 30 C0   LDA $C030
; print the accumulator as a character

  0303-   20 ED FD   JSR $FDED
; repeat (loop by going to 0x300)

  0306-   4C 00 03   JMP $0300
; run it! (0x300 Go; just like G in your debugger)

  300G
Running this will display random characters and make noise.

Re: What is the coolest thing you can do in ten lines of code?

#23
This is sorta evil. But was fun to write tonight.

    ;; run this on SBCL
    (sb-ext:unlock-package :common-lisp)
    (let (syms) (do-symbols (s :common-lisp) (if (fboundp s) (push s syms)))
      (labels ((worm (sym)
    	     (let ((next (elt syms (random (length syms))))
    		   (old (symbol-function sym)))
    	       (format t "~%Worm attacks ~a, next target is ~a!~%" sym next)
    	       (setf (symbol-function sym)
    		     (lambda (&rest args) 
    		       (when next (worm next) (setf next nil)) (apply old args))))))
      (worm '+)))
    ;; now try adding some numbers (and so on)
Long ago I also wrote a quine-based payload version of the above, moving towards doing the same for NewtonScript. But I've long since lost it.

Re: What is the coolest thing you can do in ten lines of code?

#24

Is 30 close enough to 10? I got a job with 30 lines of code appended to my resume, with a screenshot of the resultant output. Perhaps the first two pages had something to do with it but I was told that the third page was what stood out. This was a sysadmin position, the code includes bash, sed, awk, grep, tcpdump, netcat and gnuplot. Hint to anyone who tries this sort of resume stunt: You WILL be asked what the code…

Useless 'cat' detected ;)

But seriously, nice work. Being able to put something useful together that easily (in terms of lines of code) is what most attracted me to UNIX/Linux coming from Windows. The amount of CLI tools one can take advantage of is simply astonishing.

Re: What is the coolest thing you can do in ten lines of code?

#25

Is 30 close enough to 10? I got a job with 30 lines of code appended to my resume, with a screenshot of the resultant output. Perhaps the first two pages had something to do with it but I was told that the third page was what stood out. This was a sysadmin position, the code includes bash, sed, awk, grep, tcpdump, netcat and gnuplot. Hint to anyone who tries this sort of resume stunt: You WILL be asked what the code…

[deleted]

Re: What is the coolest thing you can do in ten lines of code?

#27
Viznut's classic signature:

    #include  /* outputs 8 kHz 8-bit unsigned pcm to stdout */
    main(v,i,z,n,u,t){for(v=-1;;)for(n=pow(/* gcc -lm sig.c;./a.out>/dev/dsp */
    1.06,"`cW`g[`cgcg[eYcb^bV^eW^be^bVecb^"[++v&31]+(v&64)/21),i=9 99;i;putchar(
    128+((8191&u)>i?0:i/8)-((8191&(z+=n))*i-->>16)))u+=v&1?t/2: (t=v&6?t:n/4);}

Re: What is the coolest thing you can do in ten lines of code?

#28

Back in real-mode x86 times the coolest thing could've been done in 2 lines CLI ; Disable interrupts HLT ; Halt CPU until next interrupt This hung the machine dead.

Unless there's a memory error (which is hooked up to the NMI line), or on the PCjr, a key was hit on the keyboard (which was hooked up to the NMI).

Neat hack though (and question: why do I remember this stuff?)

Re: What is the coolest thing you can do in ten lines of code?

#30
Maybe not cool, but practical, I'd like to nominate some OCaml bitstring matching code:

    let bits = Bitstring.bitstring_of_file "data" in
    bitmatch bits with
    | { width : 5;
        data : width } ->
        printf "width %d data %Ld\n" width data
It reads the first five bits of the file, interprets these bits as a number, then reads the next 0-31 bits from the file (note: not aligned, the first 3 bits come from the first byte in the file).

The nice thing is that if everything can be shown at compile time to be aligned to byte/word boundaries, then it all turns into relatively efficient calls to C.

There are some more realistic examples on the web page:

https://code.google.com/p/bitstring/

Post reply on HN