13
\$\begingroup\$

This challenge is officially over, resulting in the win of Wheat Wizard, with a total of 7 answers. Any other answer is welcome, but it won't influence the accepted answer for this challenge, nor the winner.


Task:

Print all the positive divisors of a number x taken as input.

Input:

A single number x which is the number (in base 10) whose positive divisors should be computed.

Output:

All the positive divisors of x. Any format is allowed, including \n,,,; and whitespace as separators, as long as it's understandable. The output can be an array of Integers or Strings, too (e.g: [1, 2, 3, 5, 30]). You may output the divisors to stdout, console or the equivalent in your language or they can be returned from a function.


Rules

  • A user may not answer twice in a row
  • Your answer may remove, add or replace at most 15 characters from the previous answer (whitespace does not count), besides for Answer 2 which can "transform" up to 20 characters to get things started
  • You are not allowed to post an answer in a programming language that already has an answer, the exception being a completely different version of that language (e.g: If I post an answer in Python 2.7, you can submit one in Python 3, but not in Python 2.6)
  • Standard loopholes are not allowed
  • You are not allowed to use built-ins for getting divisors, for the sake of this challenge
  • You must include the answer's number and the language name in the question's title and the number of characters changed from the previous answer

Scoring

The user with the most submissions once the things settle out wins. In case of a tie, the user with the highest score on one of their answer wins. If there is a tie at the score as well, then the user with the oldest submission(oldest highest-scored answer) will be declared the winner.

Note: "settle out" <=> 7 3 days have passed since the last answer was submitted


Examples:

Input, Output:

14 => [1, 2, 7, 14]
25 => [1, 5, 25]
65 => [1, 5, 13, 65]
114 => [1, 2, 3, 6, 19, 38, 57, 114]

Or any other equivalent output satisfying the mentioned conditions.


Final Note: This question is better if you sort the answers by the oldest. I'll post the first answer in Python 2.7, so you should post the second answer depending on that one. Good luck and have fun!


Leaderboard:

This list may be outdated, fell free to edit it:

1) Wheat Wizard [Current Leader 🏆]: 7 answers - Python 1.6, 05AB1E, Actually, Del|m|t, WSF, Brain-Flak, Lenguage

2) Riley: 3 answers - Seriously, CJam, 2sable

3) Jonathan Allan: 2 answers - Python 3, Jelly

3) ETHproductions: 2 answers - Japt, Pyth

3) Mistah Figgins: 2 answers - Befunge-98, Brain-Flak Classic

6) Riker: 1 answer - MATL

6) dzaima: 1 answer - SOGL 0.8.2

6) LegionMammal978: 1 answer - Whitespace

6) Nick Clifford: 1 answer - Ohm

6) Lynn: 1 answer - GolfScript

6) MickyT: 1 answer - Cubix

Distance calculator

You can use this snippet to calculate the distance between two entries:

function L(s,t){if(s===t)return 0;var S=s.length,T=t.length;if(S*T===0)return S+T;for(var i=0,v0=[],v1=[];i<=T;i++)v0[i]=i;for(i=0;i<S;i++){v1[0]=i+1;for(var j=0;j<T;j++)v1[j+1]=Math.min(v1[j]+1,v0[j+1]+1,v0[j]+(s[i]!=t[j]));for(j=0;j<=T;j++)v0[j]=v1[j]}return v1[T]}
<textarea id=A rows=10></textarea><textarea id=B rows=10></textarea><br>
Distance: <span id=O>0</span> <button onclick="O.innerHTML=L(A.value.replace(/\s/g,''),B.value.replace(/\s/g,''))">Run</button>

\$\endgroup\$
  • \$\begingroup\$ 15 will work, 10 is standard though. I'd say keep it at 15 though, because this is harder than most. \$\endgroup\$ – Rɪᴋᴇʀ Mar 9 '17 at 19:52
  • 2
    \$\begingroup\$ I hope you don't mind, but I added a distance calculator snippet to the bottom of the post :-) \$\endgroup\$ – ETHproductions Mar 9 '17 at 20:37
  • 2
    \$\begingroup\$ That collaborative work to go toward brainfuck is beautiful :) \$\endgroup\$ – Walfrat Mar 10 '17 at 12:59
  • 6
    \$\begingroup\$ IMPORTANT: Please edit the leaderboard when you make a submission, so it's easier to maintain.. \$\endgroup\$ – Mr. Xcoder Mar 10 '17 at 16:10
  • 2
    \$\begingroup\$ It is awesome to see people bring the answers from Python to Brain-Flak, with a great collaborative work, from a widely spread language to one of the most obscure programming language ever created. Thanks to all who made it happen! Now I'm really interested to see what happens with this challenge, since DjMcMayhem has put a bounty on it. \$\endgroup\$ – Mr. Xcoder Mar 15 '17 at 5:52

23 Answers 23

12
+250
\$\begingroup\$

Answer 20, Brain-Flak, 11

I would like to just take the time to thank everyone that has helped contribute to this goal:

  • Riley, 20 bytes

  • LegionMammal, 15 bytes

  • ETHproductions, 11 bytes

  • Lynn, 1 byte

The following users were not able to contribute bytes directly but did help in other ways:

  • Mistah Figgins

  • DJMcMayhem

  • feersum

Thanks everyone for making this possible!

"qd:A(),(;{A\%!},pe#&f!0pv'%QTS|Q@░┼_¥f::+!vUGw
)((({})<>)){((({}[()]<n=int(input({})(<>))><>)<{i=1div=wvhile(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{ifn%i==g00div.append(<{}<>{}<>>i)i=i+1}{}printdiv)}
#R
{}T:.eX╜R;j`;╜0%Y*`M∩\"ILD¹s%_Ï,

Try it online!

\$\endgroup\$
  • 6
    \$\begingroup\$ Finally, Brain Flak! Thanks to all who helped achieving this goal! Congratulations to Wheat Wizard for being the user with the most answers so far and for the great work and time spent around this challenge! \$\endgroup\$ – Mr. Xcoder Mar 14 '17 at 18:56
7
\$\begingroup\$

Answer 3: MATL, Distance 15

:tGw\~)
%n=int(input())
%i=1
%div=[]
%while (i<=n):
%    if n % i == 0:
%        div.append(i)
%    i+=1
%print(div)
\$\endgroup\$
  • 2
    \$\begingroup\$ MATL's % make it really hard to continue. Good luck to others and I really hope that this challenge won't "die" here! \$\endgroup\$ – Mr. Xcoder Mar 9 '17 at 20:20
  • \$\begingroup\$ Isn't this using a built in? \$\endgroup\$ – Jonathan Allan Mar 9 '17 at 20:29
  • \$\begingroup\$ @JonathanAllan No, definitely not. The builtin for divisors is Z\. The relevant code here is the :tGw\~) (which I wrote in chat, not a builtin) \$\endgroup\$ – DJMcMayhem Mar 9 '17 at 20:31
  • \$\begingroup\$ Indeed, there is no built-in \$\endgroup\$ – Mr. Xcoder Mar 9 '17 at 20:32
  • 1
    \$\begingroup\$ @JonathanAllan The table can be a little confusing. Z\, not \, is "divisors". The heading in the last three columns indicates the prefix (X, Y, or Z). \ by itself is the first column, i.e. "mod" \$\endgroup\$ – Luis Mendo Mar 9 '17 at 21:11
7
\$\begingroup\$

Answer 7, Japt, 15

ò f!vU"Gw\((()<>))
n=int(input())
i=1
div=[]
while (i<=n):
    if n % i == 0:
        div.append(i)
    i=i+1
print(div)#Rḍ⁸T”

Try it online!

Changed #b∫I:b;\?t to ò f!vU (10 points) and added some more Brain-Flak code by changing ~(() to ((()<>)) (5 points). I believe the code we're working toward is

((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}

Explanation

ò           Generate the range [0...input].
  f         Filter to only items Z where
   !vU        U.v(Z) returns truthily. (`fvU` would be Z.v(U))
              This returns true if U is divisible by Z, false otherwise.
      "...  The rest of the program is enclosed in this string, which is passed as an extra
            argument to `f`. Fortunately, `f` ignores it.
            Implicit: output result of last expression
\$\endgroup\$
6
\$\begingroup\$

Answer 8, 05AB1E, 14

"'ò f!vUGw\((()<>)){((({'
n=int(input())
i=1
div=[]
while (i<=n):
    if n % i == 0:
        div.append(i)
    i=i+1
print(div)
'#Rḍ⁸T”'".e

Try it online!

Explanation

Luckily 05AB1E has a builtin Python interpreter (of sorts). In order to make this run we push

'ò f!vUGw\((()<>)){((({'
n=int(input())
i=1
div=[]
while (i<=n):
    if n % i == 0:
        div.append(i)
    i=i+1
print(div)
'#Rḍ⁸T”'

as a string to the top of the stack. We have to use string literals instead of comments here because 05AB1E really doesn't like comments in its Python code. We also have to get rid of the " in the original code because it causes the string to end prematurely.

Once the string has been pushed we use .e to execute it as python code.

Work towards Brain-Flak

I was able to add 5 extra characters towards the goal of making a Brain-Flak answer. I would have been able to add 6 but alas I forgot whitespace doesn't count towards the point score.

So far we have:

((({})<>)){((({}     ((  )   )       (              <              )           (          )   )
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
6
\$\begingroup\$

Answer 13, Pyth, 15

f!%QTS|Q"@░┼_¥
f!vUGw((({})<>)){((({}[()]n=int(input({})(<>))i=1div=while((<>)){ifn%i==0div.append(i)i=i+1}printdiv)}#R{}T.eX
╜R;`;╜%Y*`M∩

Try it online!

Explanation

So I don't know much Pyth, but what I do know is that the source code is in the form of a tree, each command taking a specific number of arguments to its right. The tree of the divisor program I wrote looks like this:

     f
    / \
   !   S
   |   |
   %   Q
  / \
 Q   T

Q is the input. f takes two arguments, F and A, and returns the items T in A where F(T) returns a truthy value. In this case, F is a function which returns the logical NOT of Q%T, and A is SQ, which creates the range [1...Q]. This has the effect of filtering to only the integers T in [1...Q] where Q%T == 0.

In order to avoid parsing the rest of the code, the entire thing is wrapped in a string, then |Q"... returns the logical OR of Q and the string. Since Q is always positive, it's always truthy, and thus always gets returned from the logical OR.


Work toward Brain-Flak

((({})<>)){((({}[()] (({})(<>))      ((             <>                 )   )  {(          )  })}{}
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
  • \$\begingroup\$ Really curious to see who will submit the Brain-Flak answer, if it ever happens.. \$\endgroup\$ – Mr. Xcoder Mar 10 '17 at 16:12
  • \$\begingroup\$ We're getting closer. We should be there by answer 20 (if not earlier) \$\endgroup\$ – CalculatorFeline Mar 10 '17 at 16:14
  • \$\begingroup\$ Well, we've got 54 chars to go... \$\endgroup\$ – ETHproductions Mar 10 '17 at 16:16
  • \$\begingroup\$ Well, we're about halfway there, and this stated around answer 8, so we should finish around 18. \$\endgroup\$ – CalculatorFeline Mar 10 '17 at 16:19
6
\$\begingroup\$

Answer 16, GolfScript, 15

~:
),(;{
\%!},p#&f!0pv'%QTS|Q"@░┼_¥f::+!vUGw((({})<>)){((({}[()]<n=int(input({})(<>))><>)<{i=1div=wvhile(({})){({}<>)){ifn%i==g00div.append(i)i=i+1{}printdiv)}#R{}T:.eX╜R;j`;╜0%Y*`M∩\

Try it online!

I added ~:␤),(;{␤\%!},p#, using newline as a variable name to fit the size constraint, and squished the entire program back onto one line to comment it out. This was distance 14. Then, I added { before }printdiv for Brain-Flak.

~:␤                    Read input, store as NL
   ),(;                Range [1, 2... NL]
       {␤\%!},         Filter elements that divide NL
              p#       Print and comment everything else out

Work towards Brain-Flak

((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}     <>                 )   )  {(          ) {})}{}
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
6
\$\begingroup\$

Answer 17, CJam, 15

qd:A
),(;
{A\%!},p
e#&f!0pv'%QTS|Q"@░┼_¥f::+!vUGw((({})<>)){((({}[()]<n=int(input({})(<>))><>)<{i=1div=wvhile(({})){({}[()])<>}{}}{)){ifn%i==g00div.append(i)i=i+1{}printdiv)}#R{}T:.eX╜R;j`;╜0%Y*`M∩\

Try it online!

qd:A     # Get input as decimal and store it in A
),(;     # range [0..A]
{    },  # Filter where
 A\%!    # A mod this value == 0
       p # print 
e#...    # comment

Work towards Brain-Flak (30 to go)

)({}((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{            )   )  {(          ) {})}{}
 (  (( {})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
  • \$\begingroup\$ We are actually only 30 away. instead of omitting the extra 4 characters you can transform )({}((( to ()({})(( at the cost of only two, this is not the exact program we had in mind but () and ({}) are both no-ops in this context. \$\endgroup\$ – Wheat Wizard Mar 13 '17 at 16:30
  • \$\begingroup\$ @WheatWizard Nice! I didn't look at the actual code, just ran it through the distance checker in the question. \$\endgroup\$ – Riley Mar 13 '17 at 16:32
5
\$\begingroup\$

Answer 4 - Jelly, 4

:tGw\~)
%n=int(input())
%i=1
%div=[]
%while (i<=n):
%    if n % i == 0:
%        div.append(i)
%    i+=1
%print(div)Rḍ⁸T

Try it online!

Relevant code:

Rḍ⁸T

The ) acts as a break between links as far as the parser is concerned (I believe).

The built-in would be ÆD, instead this creates a range from 1 to the input with R, checks for divisibility by the input with ḍ⁸, then returns a list of the truthy one-based indexes with T.

\$\endgroup\$
5
\$\begingroup\$

Answer 9, Whitespace, 15

f!vUGw((({})<>)){((({}n=int(input())i=1div=while(i<=n):ifn%i==0:div.append(i)i=i+1printdiv)}#R{}T”.e<SPACES>

Where <SPACES> is replaced by the following string, where T is 0x09, L is 0x0A, and S is 0x20:

SSSLSLSTLTTTTTSSSLLSSSLSTSSTLSTSSTLTSSTLTSSSLSSSTLTSSSSTSSTLSTSSTLTSTTLTSTLLSLSL
LSSTLSLSTLSTSSSTSTSLTLSSLSLSLLSSSSLLLL

Literal newline added for clarity. Noticed that the rules only specify non-whitespace characters. Nope, couldn't help myself.

Work towards Brain-Flak

I have no idea what was going on earlier, so we now have:

((({})<>)){((({}     ((  )   )       (              <              )           (          )   )}{}
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
5
\$\begingroup\$

Answer 18, WSF, 15

q   

































































    d:A(),(;{A\%!},pe#&f!0pv'%QTS|Q"@░┼_¥f::+!vUGw)(({})<>)){((({}[()]<n=int(input({})(<>))><>)<{i=1div=wvhile(({})){({}[()])<>}{}}{}<>([{}()]{})><>){ifn%i==g00div.append(i)i=i+1{}printdiv)}#R{}T:.eX╜R;j`;╜0%Y*`M∩\

(This takes input and output via character code)

Explanation

WSF is essentially brainfuck except it uses whitespace instead of brainfuck's usual set of operators. Here is the code decompiled into brainfuck:

,
[->+>>>>+<<<<<]>

[
[-<+>>>>+<<<]<[->+<]
>>>>>[-<<+>>]<[->+<]<
[>+>->+<[>]>[<+>-]<<[<]>-]
>>[-]+>[<->[-]]
<
[<<<<.>>>>-]<[->+<]<<<
-
]

Progress towards Brain-Flak

Since WSF is only whitespace I was able to add 15 more characters onto the Brain-Flak code. This puts us at 15 away from the answer, so feel free to post it.

()({})(({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})>  )  {(          ) {})}{}
()({})(({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}

Since I am not going to get to post the Brain-flak answer myself, I thought I would just take the time to thank everyone that has helped contribute to this goal:

  • Riley, 16 bytes

  • LegionMammal, 15 bytes

  • ETHproductions, 11 bytes

  • Lynn, 1 byte

The following users were not able to contribute bytes directly but did help in other ways:

  • Mistah Figgins

Thanks everyone for making this possible!

\$\endgroup\$
5
\$\begingroup\$

Answer 19, 2sable, 15

"qd:A(),(;{A\%!},pe#&f!0pv'%QTS|Q@░┼_¥f::+!vUGw)(({})<>)){((({}[()]<n=int(input({})(<>))><>)<{i=1div=wvhile(({})){({}[()])<>}{}}{}<>([{}()]{})><>){ifn%i==g00div.append(>>i)i=i+1}{}printdiv)}#R{}T:.eX╜R;j`;╜0%Y*`M∩\"
ILD¹s%_Ï,

Try it online!

I removed the extra whitespace, wrapped everything that existed before into a string, then:

IL        # Push [1 .. input]
  D       # Duplicate
   ¹s%    # For each element: input % element
      _   # Logical not
       Ï  # Keep the values from [1 .. input] where this is 1
        , # print
\$\endgroup\$
5
\$\begingroup\$

Answer 21, Cubix, 15

Finally managed to fit this in :) Thankfully it is after the Brain-Flak answer got done, because I think I would have hindered. Needed the full 15 to implement.

"qd:A(),(;{A\%!},pe#&f!0pv'%QTS|Q@░┼_¥f::+!vUGw
)(Is{})%?;ONou{((({}[()]<n=int(inpu;<@!-;<>))><>)<{i=1div=wvhile(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{ifn%i==g00div.append(<{}<>{}<>>i)i=i+1}{}printdiv)}
#R
{}T:.eX╜R;j`;╜0%Y*`M∩\"ILD¹s%_Ï,

This maps to the following cube

              " q d : A ( )
              , ( ; { A \ %
              ! } , p e # &
              f ! 0 p v ' %
              Q T S | Q @ ░
              ┼ _ ¥ f : : +
              ! v U G w ) (
I s { } ) % ? ; O N o u { ( ( ( { } [ ( ) ] < n = i n t
( i n p u ; < @ ! - ; < > ) ) > < > ) < { i = 1 d i v =
w v h i l e ( ( { } ) ) { ( { } [ ( ) ] ) < > } { } } {
} < > ( [ { } ( ) ] { } ) > < > ) < > { i f n % i = = g
0 0 d i v . a p p e n d ( < { } < > { } < > > i ) i = i
+ 1 } { } p r i n t d i v ) } # R { } T : . e X ╜ R ; j
` ; ╜ 0 % Y * ` M ∩ \ " I L D ¹ s % _ Ï , . . . . . . .
              . . . . . . .
              . . . . . . .
              . . . . . . .
              . . . . . . .
              . . . . . . .
              . . . . . . .
              . . . . . . .

You can try it here, but you will need to paste it in. I suspect some of the specials are causing problems for the permalink.

The code is essentially over 2 lines. The important parts are:

I s     ) % ? ; O N o u 
        u ; < @ ! - ; 

I s ) This gets the input, swaps the top of the stack (0 would have worked as well) and increments
% ? Get the mod and test. If 0 carry on forward or drop down to the redirect
; O N o Drop the mod results and output the number followed by a newline
u U turn onto the line below
Following is in order executed
; - ! @ Remove the 10 from stack, subtract number from input, test and terminate if zero
< ; u Redirect target for first test. Remove top of stack (either mod or subtract result) and u-turn back up to increment

\$\endgroup\$
4
\$\begingroup\$

Answer 6, Python 1.6, 15

#b∫I:b;\?t"Gw\~(()
n=int(input())
i=1
div=[]
while (i<=n):
    if n % i == 0:
        div.append(i)
    i=i+1
print(div)#Rḍ⁸T”

I removed the % symbols and commented out the first line and a bit of the last line. This alone cost me 10 of my 15 points. However I was not yet done; since Python 1 doesn't have += I had to replace i+=1 with i=i+1 costing me an extra 3 points. Since I had 2 left over I also added (( to the beginning. I am planning to make a submission in Brain-Flak later and I need parens.

\$\endgroup\$
  • 1
    \$\begingroup\$ +1 even after OP said that Python was done with, apparently not.... \$\endgroup\$ – HyperNeutrino Mar 10 '17 at 21:24
4
\$\begingroup\$

Answer 10, Ohm, distance 5

@░┼_¥
f!vUGw((({})<>)){((({}n=int(input())i=1div=while(i<=n):ifn%i==0:div.append(i)i=i+1printdiv)}#R{}T”.e<SPACES>

...where <SPACES> is replaced by that monstrous string from the Whitespace answer.

A bit of a cheeky answer, since everything else is just a wire that lays unexecuted.

\$\endgroup\$
  • \$\begingroup\$ Any work towards Brain-Flak here? \$\endgroup\$ – CalculatorFeline Mar 10 '17 at 2:18
  • \$\begingroup\$ @CalculatorFeline Afraid not. \$\endgroup\$ – Nick Clifford Mar 10 '17 at 2:18
  • \$\begingroup\$ Too bad. 10 chars towards Brainflak! If only. \$\endgroup\$ – CalculatorFeline Mar 10 '17 at 2:20
4
\$\begingroup\$

Answer 12, Seriously, 15

╩"@░┼_¥
f!vUGw((({})<>)){((({}[()]n=int(input())i=1div=while((<>)){ifn%i==0div.append(i)i=i+1}printdiv)}#R{}T.e"X
╜R;`;╜%Y*`M∩

Try it online!

The only difference from the Actually answer is that Seriously uses backticks to mark a function where Actually uses and and we just make the extra characters into a string then pop and discard it.


Work Towards Brain-Flak

((({})<>)){((({}[()] ((  )   )       ((             <>                 )   )  {(          )  })}{}
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
  • \$\begingroup\$ +1 bringing the contest one step closer to Brain-Flak. Just 1 question: Do you know any programming language very similar to Seriously? \$\endgroup\$ – Mr. Xcoder Mar 10 '17 at 15:58
  • \$\begingroup\$ Other than actually. \$\endgroup\$ – Mr. Xcoder Mar 10 '17 at 15:59
  • \$\begingroup\$ @Mr.Xcoder I haven't used any. I only knew Seriously was this similar because Actually is just Seriously version 2.0 \$\endgroup\$ – Riley Mar 10 '17 at 16:00
4
\$\begingroup\$

Answer 14, Del|m|t, 15

                                                f!%QTS|Q"@░┼_¥f!vUGw((({})<>)){((({}[()]<n=int(input({})(<>))><>)<{i=1div=while(({})){({}<>)){ifn%i==0div.append(i)i=i+1}printdiv)}#R{}T.eX╜R;`;╜%Y*`M∩

Try it online!

Explanation

I am really starting to abuse the fact that whitespace is not counted towards the difference here. Del|m|t doesn't really care all that much what characters you you so the vast majority of the code is a sequence of spaces and carriage returns at the beginning of the program. The actual visible parts of the code are not executed at all.

Here is the code transcribed into a more "reasonable" fashion:

O R ^ V O @ A K T A J O @ A K U N R O @ B K U @ A K T Q ^ X @ B K T R ^ P O @ A K T K R ^ _ @ ^ @

Try it online!

How it works at the low level

To start we have O R ^ V this serves to take input on the first loop and works as a no-op all other times.

We then use O to make a copy of the input for later.

@ A K T recalls the variable stored in memory position -1 (at the beginning of the program this is 0) and A J increments it. O @ A K U Stores the now incremented value back in memory position -1 for our next loop around.

N calculates the mod of the copy of the input we made a while back and the value just recalled from memory and R negates it.

Together N R create a boolean that indicates whether or not the our input is divisible by the TOS.

We store a copy of this boolean to memory space -2 using O @ B K U and recall the value from memory space -2 using @ A K T.

We swap the top two elements with Q to ensure that the boolean is on top and output the value if the boolean is true using ^ X.

If the boolean was false we have an extra value that needs to be eradicated so we recall the boolean we stored in space -2 with @ B K T and pop a value if it is false R ^ P.

We duplicate the input value with O and subtract the value at memory -1 with @ A K T K. If this is zero we exit R ^ _.

Lastly we have @ ^ this skips whatever the next value is. We need this because there is a bunch of junk (actually only a @ symbol) generated by the visible portion of the code.

Once it reaches the end it loops back to the beginnning.

How it works at the high level

The basic idea is that we have a value primarily stored at memory location -1 that is incremented each time we loop. If that value divides our input we output it and when the two are equal we end execution.

Progress Towards Brain-Flak

Because whitespace does not count towards the difference I was able to change the code without spending any of my 15 points and thus all of them were invested into the Brain-Flak code.

Here is our current standing.

((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}     <>                 )   )  {(          )  })}{}
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
  • \$\begingroup\$ Please update the leaderboard everytime you submit an answer. \$\endgroup\$ – Mr. Xcoder Mar 10 '17 at 20:54
  • \$\begingroup\$ Only 39 characters left for the Brain-Flak answer! :) That means we still need at least 3 answers... \$\endgroup\$ – HyperNeutrino Mar 10 '17 at 21:48
4
\$\begingroup\$

Answer 15, Befunge-98, 15

&f!0pv
'         %QTS|Q" @ ░┼_¥f
:
:      
+      
!         vUGw(((   {})<>)){((({}[()
]    <    n=int(i   nput({})(<>))><>)
<      {i=1di     v
  =
w    v  
       hile(({      })){({}<>)){ifn%i==
g
0
0    div.app   en   d(i)i=i+1}printdiv)}#R{}T
:      
.    eX╜R;
j      
`      ;╜
0      
%  Y*`M∩
\

Try it Online!

(There is probably a lot of unnecessary whitespace, but I can't be bother to golf it out right now)

I used all 15 for the Befunge program, so no changes to the Brain-flak this time.

My main strategy for this was to send the IP going vertically, and using whitespace to execute certain characters from the preexisting code.

Explanation:

The code that matters to the Befunge program is this:

&f!0pv
'                 @
:
:
+
!
]    <
<                 v
w    v
g
0
0    d
:
.    e
j
`
0
%    `
\

Which is equivalent to:

&f!0pv   Gets input, and stores it at (0, 0) (where the & is)
         The v goes down, hits the < and ], which turns the IP up along the first line

!+::'&   There is a 0 at the bottom of the stack, so ! changes it to a 1 and + increments
         :: duplicates twice, and '& gets the input value

\%       swaps the input and iterator mods them
  0`j.   Checks if input mod iterator is 0 - if it is, print iterator

:00gw    gets the input again, and compares it to the iterator.
         If they are different, the IP travels right to the v
         Otherwise, it continues straight, and hits arrows leading to the end (@)

de`      pushes 0, to be used in the increment line
\$\endgroup\$
3
\$\begingroup\$

Answer 2 - Python 3, 5

n=int(input())
i=1
div=[]
while (i<=n):
    if n % i == 0:
        div.append(i)
    i+=1
print(div)

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Now you have closed the answer list in Python. Good! \$\endgroup\$ – Mr. Xcoder Mar 9 '17 at 20:07
  • \$\begingroup\$ @Mr.Xcoder What if someone uses Python 3.5 and uses the async or await built-ins? Would that count as a completely different language? \$\endgroup\$ – HyperNeutrino Mar 10 '17 at 21:23
3
\$\begingroup\$

Answer 5 - SOGL 0.8.2, 9

b∫I:b;\?t"Gw\~)
%n=int(input())
%i=1
%div=[]
%while (i<=n):
%    if n % i == 0:
%        div.append(i)
%    i+=1
%print(div)Rḍ⁸T”

Explanation:

b∫              repeat input times                [0]
  I             increment (the loop is 0-based)   [1]
   :b           duplicate                         [1, 1]
     ;          put the input one under the stack [1, 114, 1]
      \?        if divides                        [1, 1]
        t        output                           [1, 1]
         "...”   push that long string            [1, 1, "Gw\~...Rḍ⁸T"]

Note: the interpreter currently needs the \ns be replaced with in order to not count it as input, but the parser itself considers both interchangable.

\$\endgroup\$
3
\$\begingroup\$

Answer 11, Actually, 15

╩@░┼_¥
f!vUGw((({})<>)){((({}]n=int(input())i=1div=while(i<=n):ifn%i==0:div.append(i)i=i+1printdiv)}#R{}T”.e
╜R;⌠;╜%Y*⌡M∩

Try it online!

Explanation

Actually has a nice builtin ÷ for finding the factors of a number, however we are not allowed to use such builtins.

I begin by storing the input to the registers so that it will be unharmed by what is to come. I do this using but I could have just as easily used one of the other commands available.

Then I paste the code we already had (I removed all the whitespace because it was annoying to work with, I can do this because "whitespace does not count"). Luckily this does a whole lot of nothing when the stack is empty.

Then we have the rest of the program

╜   Pull our input from the register
R   Create the range of n
;   Duplicate the range
⌠   Declare a function
 ;  Duplicate n
 ╜  Pull from register
 %  Mod
 Y  Logical not
 *  Multiply by n
⌡   End Function
M   Map the function across the range
∩   Remove the zeros with a Intersection

Work Towards Brain-Flak

All that work and I was only able to get one extra paren in.

((({})<>)){((({}   ] ((  )   )       (              <              )           (          )   )}{}
((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>([{}()]{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
  • \$\begingroup\$ You know, if we enclose the Brain-Flak code in [] we can have Brainfcuk code after it. Might open up possibilities. \$\endgroup\$ – CalculatorFeline Mar 10 '17 at 2:58
  • \$\begingroup\$ @CalculatorFeline I don't think we do. Brain-Flak on its own does next to nothing in brainfuck. Making a submission in brainfuck would be very hard but I don't think Brain-Flak is going to harm it any. \$\endgroup\$ – Wheat Wizard Mar 10 '17 at 3:06
  • \$\begingroup\$ Well, Brainfuck planning would be a good idea at this stage. Bytes that can't go towards Flak can be placed in other planning (like BF, Syms, or conventional languages). \$\endgroup\$ – CalculatorFeline Mar 10 '17 at 4:25
  • \$\begingroup\$ @CalculatorFeline The thing is there is pretty much no such thing as bytes that can't go towards Brain-Flak. Unless a language has some pretty weird rules about parens (in which case it is probably already unusable) we can use extra bytes to insert parens. \$\endgroup\$ – Wheat Wizard Mar 10 '17 at 5:14
  • \$\begingroup\$ Why does your code output an extra 0 before the array?? \$\endgroup\$ – Mr. Xcoder Mar 10 '17 at 5:47
3
\$\begingroup\$

23, Brain-Flak Classic, 13

"qd:A(),(;{A\%!},pe#&f!0pv'%QTS|Q@░┼_¥f::+!vUGw)(Is(({})<>))%?;ONou{((({}[]<n=int(inpu;({})(@!-;<>))><>)<{i=1div=wvhile(({})){({}[])<>}{}}{}<>({<({}[])>[]}[]{}{})><>)<>{ifn%i==g00div.append(<{}<>{}<>>i)i=i+1}{}printdiv)}#R{}T:.eX╜R;j`;╜0%Y*`M∩\"ILD¹s%_Ï,

Originally, @Wheat Wizard had posted the brain-flak-classic code as it was on answer 22:

()({})((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>({<({}[]{})           ><>)<>{(<{}<>{}<>>)}{})}{}
()({})((({})<>)){((({}[  ]<(({})(<>))><>)<{(({})){({}[  ])<>}{}}{}<>({<({}[]  )>[]}[]{}{})><>)<>{(<{}<>{}<>>)}{})}{}

This is 17 characters off. However, I was able to compress this by simply moving the {}) further right in the proposed code to get

()({})((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>({<({}[]         {})><>)<>{(<{}<>{}<>>)}{})}{}
()({})((({})<>)){((({}[  ]<(({})(<>))><>)<{(({})){({}[  ])<>}{}}{}<>({<({}[])>[]}[]{}{})><>)<>{(<{}<>{}<>>)}{})}{}

Which is only 13 characters off! So all I did was add/remove brackets to get the proposed code.


The original code I posted had a typo, it's fixed now. (Thanks @WheatWizard!)

\$\endgroup\$
3
\$\begingroup\$

Answer 1 - Python 2.7

n=input()
i=1
div=[]
while (i<=n):
    if n % i == 0:
        div.append(i)
    i+=1
print(div)

Distance: NA - First answer

Try it online!

\$\endgroup\$
1
\$\begingroup\$

22, Lenguage, 15

Lenguage is a esolang that cares only about how long the program is not about its content. So we can create any lenguage program we want by padding the last program with the proper amount of whitespace. Lenguage is compiled into brainfuck so we will reuse the brainfuck program I wrote a while ago

,[->+>>>>+<<<<<]>[[-<+>>>>+<<<]<[->+<]>>>>>[-<<+>>]<[->+<]<[>+>->+<[>]>[<+>-]<<[<]>-]>>[-]+>[<->[-]]<[<<<<.>>>>-]<[->+<]<<<-]

I made a few changes to the main program to facilitate later answers, but the end result looks like:

<SPACES>"qd:A(),(;{A\%!},pe#&f!0pv'%QTS|Q@░┼_¥f::+!vUGw)(Is(({})<>))%?;ONou{((({}[()]<n=int(inpu;({})(@!-;<>))><>)<{i=1div=wvhile(({})){({}[()])<>}{}}{}<>({<[{}[]{})><>)<>{ifn%i==g00div.append(<{}<>{}<>>i)i=i+1}{}printdiv)}#R{}T:.eX╜R;j`;╜0%Y*`M∩\"ILD¹s%_Ï,

where <SPACES> represents 55501429195173976989402130752788553046280971902194531020486729504671367937656404963353269263683332162717880399306 space characters.

Am I abusing the whitespace doesn't count rule? Perhaps.

Work towards Brain-Flak Classic

We had all of those parens already there so I thought I would start us along the way towards Brain-Flak Classic.

()({})((({})<>)){((({}[()]<(({})(<>))><>)<{(({})){({}[()])<>}{}}{}<>({<({}[]         {})><>)<>{(<{}<>{}<>>)}{})}{}
()({})((({})<>)){((({}[  ]<(({})(<>))><>)<{(({})){({}[  ])<>}{}}{}<>({<({}[])>[]}[]{}{})><>)<>{(<{}<>{}<>>)}{})}{}
\$\endgroup\$
  • \$\begingroup\$ Another target... That's madness. I like it! \$\endgroup\$ – Mr. Xcoder Mar 17 '17 at 19:48
  • \$\begingroup\$ So the top row of Brain-flak Classic is what we have, and the bottom is what we need? \$\endgroup\$ – MildlyMilquetoast Mar 18 '17 at 18:38
  • \$\begingroup\$ @MistahFiggins yes \$\endgroup\$ – Wheat Wizard Mar 18 '17 at 18:39
  • 1
    \$\begingroup\$ Tada! Brain-Flak Classic is closer because I moved some parens around \$\endgroup\$ – MildlyMilquetoast Mar 18 '17 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.