Brainfuck - 169 bytes
-[+>+[+<]>+]>+>>,[>,]<[<]<[->>[->]<[<]<]>>>[[<[-<+<+<+>>>]+++++++++[<[-<+>]<<[-<+>>>+<<]<[->+<]>>>>-]]<[-]<<[-]>[->>>+<<<]>>>---------->]<-[[->+>+<<]>>[-<<+>>]<-]<[-.+<]
Requires 8#brainfuck -bit wrapping cells and EOF = 0 169 146 bytes
-[+>+[+<]>+]>+>>,[>,]<[<]<[->>[->]<[<]<]>>>[[<[-<+<+<+>>>]+++++++++[<[-<+>]<<[-<+>>>+<<]<[->+<]>>>>-]]<[-]<<[-]>[->>>+<<<]>>>---------->]<-[->.+<]
Limitations:
- EOF must be 0
- Requires 8-bit wrapping cells
- Because of ^, mods input by 256
Not the shortest answer here, but hey, brainfuck! This was fun. Surewould be a really, it's long. Surereally good brainfuck challenge, it's incredibly slowexcept for large inputsthe fact that it requires human readable input without guaranteeing the number of digits. Sure,I could have required input to have leading zeroes to make it probably chokes on large inputs (always chokes on 2563 characters long, will probably chokebut what fun is that? :D One major problem with taking input this way is that brainfuck's only branching or looping structure checks if youthe current cell is zero or not. When the input something closecan contain zeroes, it can cause your code to the tape size)take branches it shouldn't be taking. But give me a break: It'sTo solve this problem, I store each digit of input brainfuckplus 1, then subtract the excess at the last possible second. That way, I did it in brainfuckalways know where my zeroes are. :P
I'm notI did say that this would have been a master at golfing ingreat brainfuck so there are probably some byteschallenge without having to be saved in here somewhereparse input. In fact, over 80% of this programWhy is simply interpretingthat? Well, let's pretend that we don't take a numeric input. We'll say the challenge is "Given a byte of input, which is very hard when you don't know how many digits t's going tooutput all ASCII characters below that byte". Here's what my answer would be and don't want the:
#brainfuck - 8 bytes
,[->.+<]
It's quite a difference! The real program uses 139 instructions to die if one ofcollect the digits is 0. There are a lotinput (over 95% of values in thisthe program stored 1 greater than their actual value!), with 1 subtracted atjust because it's a human typing it. Store the very last second,number as a byte and give that to get around theme, and it only branch/loop structure being "is this cell 0?"takes one.
(This is why it chokes on 256Fun fact: If you understood the hypothetical program, actuallythen congratulations! You understand brainfuck in its entirety. 255 + 1 = 0The whole language has only eight commands, and that program happens to use each one exactly once.)
ExplainedExplanation (to the best of my ability)
-[+>+[+<]>+]>+ the ascii representation of 0 is 48
abuse 8 bit thiswrapping codeto putsput 47 in a cell
4
>>,[>,] it's very slow. if you're testing this i'd recommend replacing it with
starting in cell 6; get each character of input
<[<]<[->>[->]<[<]<] 47 plus signs
>>,[>,]<[<]< getsubtract allthe charactersvalue of input, then move thecell cursor4 backfrom toeach theinput 47character
in hindsight i should probably have done this first
'0' has an ascii value of maybe47 i'llso fixsubtracting it47 laterfrom buteach
right now i am not touching this code
[->>[->]<[<]<] subtract 47 from character digit of input
digit gives you sincethat thedigit's asciivalue ofplus 01
>>>[ is 48; 1 is 49; 2 is 50; etc
weif havethe eachnumber digitis plusin onemore inthan aone rowcell
the first digit is two cells to our right
>>>[[<[-<+<+<+>>>]
+++++++++[<[-<+>]
<<[-<+>>>+<<]<[->+<]>>>>-]]
<[-]<<[-]>[->>>+<<<]
>>>---------->]<- (when the program first woooahstarts this one's ameans doozy
"if the input has
check that there ismore athan digitone threedigit")
[<[-<+<+<+>>>] cells to our right
copy first input cell to 3 new cells
+++++++++[<[-<+>]<< do (thatsome is;fancy checkaddition ifmagic thereto ismultiply morethat thanvalue oneby digit)10
[-<+>>>+<<]<[->+<]>>>>-]]
<[-]<<[-]> clean up a bit
[->>>+<<<]>>> if so; multiply the first digit by 10
add the value to the next cell of input
---------- then subtract 10 (because we were storingmultiplied (the digit plus 1) higher
by 10; the answer
than it actually was)
is 10 too high; so subtract 10
>] add the result to theif cellthe containinginput theis secondstill digit
in multiple cells; do the song and
align ourselves so that cell is twodance toagain our(multiply right
by 10; add to next cell; subtract 10)
<- repeat until the whole number iswe containednever ingot onea cell
chance to fix the final digit; so it's still 1
subtract 1 (because the final digit was also 1 too high)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; we are now done interpreting the input;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;a string was read from stdin and;; converted to an integer;
; we have now finished processing input ;;
huzzah ;; the tape is empty except for the current cell ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
[[->+>+<<]>>[-<<+>>]<-] copy the number to the next cell; leaving it intact
;; the current cell contains the number that was input ;;
subtract 1 from the copy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[ do this until itwhile hitsthe cell containing input != 0
- tape now looks like
subtract 1 from it
>.+ (n)(n minus 1)(n minus 2)go alla thecell wayto downthe toright; (2)(1)(0)
<[-.+<]output that startingcell; atthen theadd 1
<] on the tape; subtract 1; output; add one; move left
repeat until you run out of numbers
done! repeat