Skip to main content
Commonmark migration
Source Link

#OIL, 134 106 103 102 bytes

OIL, 134 106 103 102 bytes

Takes the input from stdin, the two numbers seperated by a newline. Outputs the result of the integer division, then a newline, and then the remainder.

This is one of the most complicated OIL programs I've ever written, as OIL lacks builtins for division, remainder, addition, substraction, and so on. It works with the primitive way of doing division: repeated nested decrementation.

I present the code in an annotated format, with comments in the style of scripting languages. Before executing, the comments have to be removed.

5  # read input into lines 0 and 2

5
2
0  # the zero to compare to (nops)
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
4
2
24 # if so, jump to 24 (marked with §)
13 # else, go on
10 # check if the first input is zero &
4

31 # if so, jump to 31 (marked with $)
18 # else, go on
9  # decrement both numbers

9
2
6  # jump to line 8 (marked with %)
8
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 13 (marked with &)
13
10 # is the second number zero? $
4
2
42 # if so, jump to 42 (marked with +)
36 # else go on
9  # decrement both the second number and the backup
2
9
3
6  # jump to 31 (marked with $)
31
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)

edit: Shaved off 3 more bytes by moving a "constant" to a one-digit location (less bytes to reference), and then implicit-ing 2 zero-locations (By using an empty line instead. One of them I could have done before).

edit: And another byte by making the initial zero implicit. We really only need a single literal zero.

#OIL, 134 106 103 102 bytes

Takes the input from stdin, the two numbers seperated by a newline. Outputs the result of the integer division, then a newline, and then the remainder.

This is one of the most complicated OIL programs I've ever written, as OIL lacks builtins for division, remainder, addition, substraction, and so on. It works with the primitive way of doing division: repeated nested decrementation.

I present the code in an annotated format, with comments in the style of scripting languages. Before executing, the comments have to be removed.

5  # read input into lines 0 and 2

5
2
0  # the zero to compare to (nops)
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
4
2
24 # if so, jump to 24 (marked with §)
13 # else, go on
10 # check if the first input is zero &
4

31 # if so, jump to 31 (marked with $)
18 # else, go on
9  # decrement both numbers

9
2
6  # jump to line 8 (marked with %)
8
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 13 (marked with &)
13
10 # is the second number zero? $
4
2
42 # if so, jump to 42 (marked with +)
36 # else go on
9  # decrement both the second number and the backup
2
9
3
6  # jump to 31 (marked with $)
31
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)

edit: Shaved off 3 more bytes by moving a "constant" to a one-digit location (less bytes to reference), and then implicit-ing 2 zero-locations (By using an empty line instead. One of them I could have done before).

edit: And another byte by making the initial zero implicit. We really only need a single literal zero.

OIL, 134 106 103 102 bytes

Takes the input from stdin, the two numbers seperated by a newline. Outputs the result of the integer division, then a newline, and then the remainder.

This is one of the most complicated OIL programs I've ever written, as OIL lacks builtins for division, remainder, addition, substraction, and so on. It works with the primitive way of doing division: repeated nested decrementation.

I present the code in an annotated format, with comments in the style of scripting languages. Before executing, the comments have to be removed.

5  # read input into lines 0 and 2

5
2
0  # the zero to compare to (nops)
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
4
2
24 # if so, jump to 24 (marked with §)
13 # else, go on
10 # check if the first input is zero &
4

31 # if so, jump to 31 (marked with $)
18 # else, go on
9  # decrement both numbers

9
2
6  # jump to line 8 (marked with %)
8
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 13 (marked with &)
13
10 # is the second number zero? $
4
2
42 # if so, jump to 42 (marked with +)
36 # else go on
9  # decrement both the second number and the backup
2
9
3
6  # jump to 31 (marked with $)
31
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)

edit: Shaved off 3 more bytes by moving a "constant" to a one-digit location (less bytes to reference), and then implicit-ing 2 zero-locations (By using an empty line instead. One of them I could have done before).

edit: And another byte by making the initial zero implicit. We really only need a single literal zero.

added 345 characters in body
Source Link
L3viathan
  • 3.4k
  • 15
  • 25

#OIL, 134 106106 103 102 bytes

Takes the input from stdin, the two numbers seperated by a newline. Outputs the result of the integer division, then a newline, and then the remainder.

This is one of the most complicated OIL programs I've ever written, as OIL lacks builtins for division, remainder, addition, substraction, and so on. It works with the primitive way of doing division: repeated nested decrementation.

I present the code in an annotated format, with comments in the style of scripting languages. Before executing, the comments have to be removed.

5  # read input into lines 0 and 2
0
5
2
0  # the zero to compare to (nops)
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
184
2
2324 # if so, jump to 2324 (marked with §)
1213 # else, go on
10 # check if the first input is zero &
184
0
3031 # if so, jump to 3031 (marked with $)
1718 # else, go on
9  # decrement both numbers
0
9
2
6  # jump to line 78 (marked with %)
78
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 1213 (marked with &)
1213
10 # is the second number zero? $
184
2
4142 # if so, jump to 4142 (marked with +)
3536 # else go on
9  # decrement both the second number and the backup
2
9
3
6  # jump to 31 (marked with $)
3031
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)

edit: Shaved off 3 more bytes by moving a "constant" to a one-digit location (less bytes to reference), and then implicit-ing 2 zero-locations (By using an empty line instead. One of them I could have done before).

edit: And another byte by making the initial zero implicit. We really only need a single literal zero.

#OIL, 134 106 bytes

Takes the input from stdin, the two numbers seperated by a newline. Outputs the result of the integer division, then a newline, and then the remainder.

This is one of the most complicated OIL programs I've ever written, as OIL lacks builtins for division, remainder, addition, substraction, and so on. It works with the primitive way of doing division: repeated nested decrementation.

I present the code in an annotated format, with comments in the style of scripting languages. Before executing, the comments have to be removed.

5  # read input into lines 0 and 2
0
5
2
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
18
2
23 # if so, jump to 23 (marked with §)
12 # else, go on
10 # check if the first input is zero &
18
0
30 # if so, jump to 30 (marked with $)
17 # else, go on
9  # decrement both numbers
0
9
2
6  # jump to line 7 (marked with %)
7
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 12 (marked with &)
12
10 # is the second number zero? $
18
2
41 # if so, jump to 41 (marked with +)
35 # else go on
9
2
9
3
6
30
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)

#OIL, 134 106 103 102 bytes

Takes the input from stdin, the two numbers seperated by a newline. Outputs the result of the integer division, then a newline, and then the remainder.

This is one of the most complicated OIL programs I've ever written, as OIL lacks builtins for division, remainder, addition, substraction, and so on. It works with the primitive way of doing division: repeated nested decrementation.

I present the code in an annotated format, with comments in the style of scripting languages. Before executing, the comments have to be removed.

5  # read input into lines 0 and 2

5
2
0  # the zero to compare to (nops)
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
4
2
24 # if so, jump to 24 (marked with §)
13 # else, go on
10 # check if the first input is zero &
4

31 # if so, jump to 31 (marked with $)
18 # else, go on
9  # decrement both numbers

9
2
6  # jump to line 8 (marked with %)
8
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 13 (marked with &)
13
10 # is the second number zero? $
4
2
42 # if so, jump to 42 (marked with +)
36 # else go on
9  # decrement both the second number and the backup
2
9
3
6  # jump to 31 (marked with $)
31
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)

edit: Shaved off 3 more bytes by moving a "constant" to a one-digit location (less bytes to reference), and then implicit-ing 2 zero-locations (By using an empty line instead. One of them I could have done before).

edit: And another byte by making the initial zero implicit. We really only need a single literal zero.

minus 28 characters, thanks Leo
Source Link
L3viathan
  • 3.4k
  • 15
  • 25

#OIL, 134134 106 bytes

5  # reads the firstread input into linelines 0 (thisand one)2
0
5  # reads the second input into line 2 (this one)
2
10 # compares the divisor (2) with what's in line 191 (a zero)
2
19
52 # if equal, jump to line 52 (marked with *)
9  #make (otherwise,a jumpbackup toof the following line)
1  # copy thesecond divisorinput intoat line 3 (make a backup)
2
3
10 # check if what's inthe linesecond 23input (ais zero)0. &%
2318
2  # is identical to the divisor
2823 # if so, jump to line 2823 (marked with §)
1712 # (otherwiseelse, go on)
10 # comparecheck what'sif inthe linefirst 23input (ais zero) +&
2318
0  # to the first input
3530 # if identicalso, jump to line 3530 (marked with %$)
2217 # else, go on
9  # decrement line 0 and lineboth 2numbers
0
9
2
6  # jump to line 127 (marked with &%)
127
8  # increment what'sthe value in line 1 (initially a zero,) §
1  # counts how often we've substracted the second number from the first)
1  # copy from line 3 (our backup) into"restore linethe 2backup"
3
2
6  # jump to line 1712 (marked with +&)
17 # %12
10 # compare zerois tothe what'ssecond innumber linezero? 2$
2318
2
4641 # if so, jump to 4641 (marked with $+) if equal
4035 # (otherwise, to theelse nextgo line)on
9  # decrement line 2
2
9  # decrement line 3
3
6  # jump to line 35 (marked with %)
3530
4  # print what's left in line 1the (result)division $+
1
11 # print a newline
4  # print what's in line 3 (remainder)
3
3  # exit
4  # print what's in line 19 (result) *
19
11 # print newline
4  # print what's in lineand 0the (remainder)
0  # (divisionfrom bythe zerobackup)

#OIL, 134 bytes

5  # reads the first input into line 0 (this one)
0
5  # reads the second input into line 2 (this one)
2
10 # compares the divisor (2) with what's in line 19 (a zero)
2
19
52 # if equal, jump to line 52 (marked with *)
9  # (otherwise, jump to the following line)
1  # copy the divisor into line 3 (make a backup)
2
3
10 # check if what's in line 23 (a zero) &
23
2  # is identical to the divisor
28 # if so, jump to line 28 (marked with §)
17 # (otherwise, go on)
10 # compare what's in line 23 (a zero) +
23
0  # to the first input
35 # if identical, jump to line 35 (marked with %)
22 # else, go on
9  # decrement line 0 and line 2
0
9
2
6  # jump to line 12 (marked with &)
12
8  # increment what's in line 1 (initially a zero, §
1  # counts how often we've substracted the second number from the first)
1  # copy from line 3 (our backup) into line 2
3
2
6  # jump to line 17 (marked with +)
17 # %
10 # compare zero to what's in line 2
23
2
46 # jump to 46 (marked with $) if equal
40 # (otherwise, to the next line)
9  # decrement line 2
2
9  # decrement line 3
3
6  # jump to line 35 (marked with %)
35
4  # print what's left in line 1 (result) $
1
11 # print a newline
4  # print what's in line 3 (remainder)
3
3  # exit
4  # print what's in line 19 (result) *
19
11 # print newline
4  # print what's in line 0 (remainder)
0  # (division by zero)

#OIL, 134 106 bytes

5  # read input into lines 0 and 2
0
5
2
1  # make a backup of the second input at line 3
2
3
10 # check if the second input is 0. %
18
2
23 # if so, jump to 23 (marked with §)
12 # else, go on
10 # check if the first input is zero &
18
0
30 # if so, jump to 30 (marked with $)
17 # else, go on
9  # decrement both numbers
0
9
2
6  # jump to line 7 (marked with %)
7
8  # increment the value in line 1 (initially a zero) §
1
1  # "restore the backup"
3
2
6  # jump to line 12 (marked with &)
12
10 # is the second number zero? $
18
2
41 # if so, jump to 41 (marked with +)
35 # else go on
9
2
9
3
6
30
4  # print the division +
1
11 # a newline
4
3  # and the remainder (from the backup)
added 1368 characters in body
Source Link
L3viathan
  • 3.4k
  • 15
  • 25
Loading
Source Link
L3viathan
  • 3.4k
  • 15
  • 25
Loading