How can I know the length of sublists in a code without running the code?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
1












I have a list called eaData which contains sublists of the form a,b, number, where each sublist gives the number of steps in the Euclidean algorithm for numbers $a$ and $b$.



I have the following code:



 eaSteps[a_, b_] :=
NestWhileList[
#[[2]], Mod[#[[1]], #[[2]]] &,
a, b,
#[[2]] != 0 &
]


So for example



eaSteps[1736, 1333] = 1736,1333,1333,403,403,124,124,31,31,0`


I also have



eaData = 
SortBy[
Flatten[
Table[
a, b, Length[eaSteps[a, b]] - 1,
a, 1, 100,
b, 1, a(* the b value cannot exceed the a value *)
],
1
],
Part[#,3] &
]


My question is that my eaData list contains 5050 sublists. How could I know there are 5050 subentries before I even run the code?



I know that for the EA, the maximum number of steps is at most 5 times the minimum number of digits of either a or b, how does that help me here?



And if $b leq a leq 1000$ then how can I find the a and b values that require the most steps in the EA?



I'm thinking that I know a has at most 4 digits, so there are at most 20, steps. But now I'm stuck. Any help? thank you!










share|improve this question









New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • shouldn't you change a, 1, 25 to a, 1, 100 to get 5050 sublists?
    – kglr
    4 hours ago










  • yes sorry, I meant a,1,100, i just mean, how do I know without running the code itself that I'd get 5050. what is the logic behind it?
    – user130306
    4 hours ago















up vote
4
down vote

favorite
1












I have a list called eaData which contains sublists of the form a,b, number, where each sublist gives the number of steps in the Euclidean algorithm for numbers $a$ and $b$.



I have the following code:



 eaSteps[a_, b_] :=
NestWhileList[
#[[2]], Mod[#[[1]], #[[2]]] &,
a, b,
#[[2]] != 0 &
]


So for example



eaSteps[1736, 1333] = 1736,1333,1333,403,403,124,124,31,31,0`


I also have



eaData = 
SortBy[
Flatten[
Table[
a, b, Length[eaSteps[a, b]] - 1,
a, 1, 100,
b, 1, a(* the b value cannot exceed the a value *)
],
1
],
Part[#,3] &
]


My question is that my eaData list contains 5050 sublists. How could I know there are 5050 subentries before I even run the code?



I know that for the EA, the maximum number of steps is at most 5 times the minimum number of digits of either a or b, how does that help me here?



And if $b leq a leq 1000$ then how can I find the a and b values that require the most steps in the EA?



I'm thinking that I know a has at most 4 digits, so there are at most 20, steps. But now I'm stuck. Any help? thank you!










share|improve this question









New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • shouldn't you change a, 1, 25 to a, 1, 100 to get 5050 sublists?
    – kglr
    4 hours ago










  • yes sorry, I meant a,1,100, i just mean, how do I know without running the code itself that I'd get 5050. what is the logic behind it?
    – user130306
    4 hours ago













up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I have a list called eaData which contains sublists of the form a,b, number, where each sublist gives the number of steps in the Euclidean algorithm for numbers $a$ and $b$.



I have the following code:



 eaSteps[a_, b_] :=
NestWhileList[
#[[2]], Mod[#[[1]], #[[2]]] &,
a, b,
#[[2]] != 0 &
]


So for example



eaSteps[1736, 1333] = 1736,1333,1333,403,403,124,124,31,31,0`


I also have



eaData = 
SortBy[
Flatten[
Table[
a, b, Length[eaSteps[a, b]] - 1,
a, 1, 100,
b, 1, a(* the b value cannot exceed the a value *)
],
1
],
Part[#,3] &
]


My question is that my eaData list contains 5050 sublists. How could I know there are 5050 subentries before I even run the code?



I know that for the EA, the maximum number of steps is at most 5 times the minimum number of digits of either a or b, how does that help me here?



And if $b leq a leq 1000$ then how can I find the a and b values that require the most steps in the EA?



I'm thinking that I know a has at most 4 digits, so there are at most 20, steps. But now I'm stuck. Any help? thank you!










share|improve this question









New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a list called eaData which contains sublists of the form a,b, number, where each sublist gives the number of steps in the Euclidean algorithm for numbers $a$ and $b$.



I have the following code:



 eaSteps[a_, b_] :=
NestWhileList[
#[[2]], Mod[#[[1]], #[[2]]] &,
a, b,
#[[2]] != 0 &
]


So for example



eaSteps[1736, 1333] = 1736,1333,1333,403,403,124,124,31,31,0`


I also have



eaData = 
SortBy[
Flatten[
Table[
a, b, Length[eaSteps[a, b]] - 1,
a, 1, 100,
b, 1, a(* the b value cannot exceed the a value *)
],
1
],
Part[#,3] &
]


My question is that my eaData list contains 5050 sublists. How could I know there are 5050 subentries before I even run the code?



I know that for the EA, the maximum number of steps is at most 5 times the minimum number of digits of either a or b, how does that help me here?



And if $b leq a leq 1000$ then how can I find the a and b values that require the most steps in the EA?



I'm thinking that I know a has at most 4 digits, so there are at most 20, steps. But now I'm stuck. Any help? thank you!







list-manipulation






share|improve this question









New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









kglr

167k8188390




167k8188390






New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









user130306

233




233




New contributor




user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user130306 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • shouldn't you change a, 1, 25 to a, 1, 100 to get 5050 sublists?
    – kglr
    4 hours ago










  • yes sorry, I meant a,1,100, i just mean, how do I know without running the code itself that I'd get 5050. what is the logic behind it?
    – user130306
    4 hours ago

















  • shouldn't you change a, 1, 25 to a, 1, 100 to get 5050 sublists?
    – kglr
    4 hours ago










  • yes sorry, I meant a,1,100, i just mean, how do I know without running the code itself that I'd get 5050. what is the logic behind it?
    – user130306
    4 hours ago
















shouldn't you change a, 1, 25 to a, 1, 100 to get 5050 sublists?
– kglr
4 hours ago




shouldn't you change a, 1, 25 to a, 1, 100 to get 5050 sublists?
– kglr
4 hours ago












yes sorry, I meant a,1,100, i just mean, how do I know without running the code itself that I'd get 5050. what is the logic behind it?
– user130306
4 hours ago





yes sorry, I meant a,1,100, i just mean, how do I know without running the code itself that I'd get 5050. what is the logic behind it?
– user130306
4 hours ago











1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Update: FWIW it is also possible to find a pair of numbers a, b less than n with maximum length for the sequence eaSteps[a,b] without "running the code". It seems that Fibonacci sequence can be used to identify the pairs with maximum eaSteps length (I have no idea why though):



ClearAll[maxEALengthPair]
maxEALengthPair[n_] := Module[i = 0, While[Fibonacci[++i] < n]; Fibonacci[i-1, i-2]];

TeXForm @ Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair",
#, maxEALengthPair /@ # &@50, 100, 500, 1000, 10000, 100000, 1000000, 10^7],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 & 10000 & 100000 & 1000000 & 10000000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 & 6765,4181 & 75025,46368 & 832040,514229 &
9227465,5702887 \
hline
endarray$




Brute-force approach gives the same results for n ∈ 50, 100, 500, 1000:



nl = 50, 100, 500, 1000 ;
#, MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ #&@nl
Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair", #,
MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ # &@nl],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 \
hline
endarray$




Note: For some n, there are multiple pairs with maximum eaSteps length. For example, for n=50 there are 7 pairs that give a length 7 list:



MaximalBy[Reverse /@ Subsets[Range[50], 2], Length[eaSteps[#]] &] 



34, 21, 47, 29, 50, 29, 49, 30, 49, 31, 50, 31, 47,
34




 Length[eaSteps @ #] - 1 &/@ %



7, 7, 7, 7, 7, 7, 7




The table above gives only the first of multiple pairs.



Original answer:



You can get the length of Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1] using



n (n + 1)/2 


(which is Sum[1, i, 1, n, j, 1, i])



or



Length[Subsets[Range[n], 1, 2]]


For n = 100:



100 101 /2 



5050




Length[Subsets[Range[100], 1, 2]]



5050




table[n_Integer] := Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1];
Length[table[100]]



5050




For the second part of the question, using a brute force approach



MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&]



987, 610




Length[Length[eaSteps[987, 610]]] -1



14







share|improve this answer






















  • thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
    – user130306
    3 hours ago










  • @user130306, that's correct.
    – kglr
    3 hours ago










  • great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
    – user130306
    3 hours ago










  • using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
    – kglr
    2 hours ago











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






user130306 is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184366%2fhow-can-i-know-the-length-of-sublists-in-a-code-without-running-the-code%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Update: FWIW it is also possible to find a pair of numbers a, b less than n with maximum length for the sequence eaSteps[a,b] without "running the code". It seems that Fibonacci sequence can be used to identify the pairs with maximum eaSteps length (I have no idea why though):



ClearAll[maxEALengthPair]
maxEALengthPair[n_] := Module[i = 0, While[Fibonacci[++i] < n]; Fibonacci[i-1, i-2]];

TeXForm @ Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair",
#, maxEALengthPair /@ # &@50, 100, 500, 1000, 10000, 100000, 1000000, 10^7],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 & 10000 & 100000 & 1000000 & 10000000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 & 6765,4181 & 75025,46368 & 832040,514229 &
9227465,5702887 \
hline
endarray$




Brute-force approach gives the same results for n ∈ 50, 100, 500, 1000:



nl = 50, 100, 500, 1000 ;
#, MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ #&@nl
Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair", #,
MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ # &@nl],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 \
hline
endarray$




Note: For some n, there are multiple pairs with maximum eaSteps length. For example, for n=50 there are 7 pairs that give a length 7 list:



MaximalBy[Reverse /@ Subsets[Range[50], 2], Length[eaSteps[#]] &] 



34, 21, 47, 29, 50, 29, 49, 30, 49, 31, 50, 31, 47,
34




 Length[eaSteps @ #] - 1 &/@ %



7, 7, 7, 7, 7, 7, 7




The table above gives only the first of multiple pairs.



Original answer:



You can get the length of Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1] using



n (n + 1)/2 


(which is Sum[1, i, 1, n, j, 1, i])



or



Length[Subsets[Range[n], 1, 2]]


For n = 100:



100 101 /2 



5050




Length[Subsets[Range[100], 1, 2]]



5050




table[n_Integer] := Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1];
Length[table[100]]



5050




For the second part of the question, using a brute force approach



MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&]



987, 610




Length[Length[eaSteps[987, 610]]] -1



14







share|improve this answer






















  • thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
    – user130306
    3 hours ago










  • @user130306, that's correct.
    – kglr
    3 hours ago










  • great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
    – user130306
    3 hours ago










  • using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
    – kglr
    2 hours ago















up vote
2
down vote



accepted










Update: FWIW it is also possible to find a pair of numbers a, b less than n with maximum length for the sequence eaSteps[a,b] without "running the code". It seems that Fibonacci sequence can be used to identify the pairs with maximum eaSteps length (I have no idea why though):



ClearAll[maxEALengthPair]
maxEALengthPair[n_] := Module[i = 0, While[Fibonacci[++i] < n]; Fibonacci[i-1, i-2]];

TeXForm @ Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair",
#, maxEALengthPair /@ # &@50, 100, 500, 1000, 10000, 100000, 1000000, 10^7],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 & 10000 & 100000 & 1000000 & 10000000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 & 6765,4181 & 75025,46368 & 832040,514229 &
9227465,5702887 \
hline
endarray$




Brute-force approach gives the same results for n ∈ 50, 100, 500, 1000:



nl = 50, 100, 500, 1000 ;
#, MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ #&@nl
Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair", #,
MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ # &@nl],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 \
hline
endarray$




Note: For some n, there are multiple pairs with maximum eaSteps length. For example, for n=50 there are 7 pairs that give a length 7 list:



MaximalBy[Reverse /@ Subsets[Range[50], 2], Length[eaSteps[#]] &] 



34, 21, 47, 29, 50, 29, 49, 30, 49, 31, 50, 31, 47,
34




 Length[eaSteps @ #] - 1 &/@ %



7, 7, 7, 7, 7, 7, 7




The table above gives only the first of multiple pairs.



Original answer:



You can get the length of Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1] using



n (n + 1)/2 


(which is Sum[1, i, 1, n, j, 1, i])



or



Length[Subsets[Range[n], 1, 2]]


For n = 100:



100 101 /2 



5050




Length[Subsets[Range[100], 1, 2]]



5050




table[n_Integer] := Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1];
Length[table[100]]



5050




For the second part of the question, using a brute force approach



MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&]



987, 610




Length[Length[eaSteps[987, 610]]] -1



14







share|improve this answer






















  • thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
    – user130306
    3 hours ago










  • @user130306, that's correct.
    – kglr
    3 hours ago










  • great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
    – user130306
    3 hours ago










  • using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
    – kglr
    2 hours ago













up vote
2
down vote



accepted







up vote
2
down vote



accepted






Update: FWIW it is also possible to find a pair of numbers a, b less than n with maximum length for the sequence eaSteps[a,b] without "running the code". It seems that Fibonacci sequence can be used to identify the pairs with maximum eaSteps length (I have no idea why though):



ClearAll[maxEALengthPair]
maxEALengthPair[n_] := Module[i = 0, While[Fibonacci[++i] < n]; Fibonacci[i-1, i-2]];

TeXForm @ Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair",
#, maxEALengthPair /@ # &@50, 100, 500, 1000, 10000, 100000, 1000000, 10^7],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 & 10000 & 100000 & 1000000 & 10000000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 & 6765,4181 & 75025,46368 & 832040,514229 &
9227465,5702887 \
hline
endarray$




Brute-force approach gives the same results for n ∈ 50, 100, 500, 1000:



nl = 50, 100, 500, 1000 ;
#, MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ #&@nl
Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair", #,
MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ # &@nl],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 \
hline
endarray$




Note: For some n, there are multiple pairs with maximum eaSteps length. For example, for n=50 there are 7 pairs that give a length 7 list:



MaximalBy[Reverse /@ Subsets[Range[50], 2], Length[eaSteps[#]] &] 



34, 21, 47, 29, 50, 29, 49, 30, 49, 31, 50, 31, 47,
34




 Length[eaSteps @ #] - 1 &/@ %



7, 7, 7, 7, 7, 7, 7




The table above gives only the first of multiple pairs.



Original answer:



You can get the length of Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1] using



n (n + 1)/2 


(which is Sum[1, i, 1, n, j, 1, i])



or



Length[Subsets[Range[n], 1, 2]]


For n = 100:



100 101 /2 



5050




Length[Subsets[Range[100], 1, 2]]



5050




table[n_Integer] := Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1];
Length[table[100]]



5050




For the second part of the question, using a brute force approach



MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&]



987, 610




Length[Length[eaSteps[987, 610]]] -1



14







share|improve this answer














Update: FWIW it is also possible to find a pair of numbers a, b less than n with maximum length for the sequence eaSteps[a,b] without "running the code". It seems that Fibonacci sequence can be used to identify the pairs with maximum eaSteps length (I have no idea why though):



ClearAll[maxEALengthPair]
maxEALengthPair[n_] := Module[i = 0, While[Fibonacci[++i] < n]; Fibonacci[i-1, i-2]];

TeXForm @ Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair",
#, maxEALengthPair /@ # &@50, 100, 500, 1000, 10000, 100000, 1000000, 10^7],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 & 10000 & 100000 & 1000000 & 10000000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 & 6765,4181 & 75025,46368 & 832040,514229 &
9227465,5702887 \
hline
endarray$




Brute-force approach gives the same results for n ∈ 50, 100, 500, 1000:



nl = 50, 100, 500, 1000 ;
#, MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ #&@nl
Grid[#, ## & @@ #2 & @@@ Transpose["n", "pair", #,
MaximalBy[Reverse /@ Subsets[Range[#], 2], Length[eaSteps[#]] &][[1]] & /@ # &@nl],
Dividers -> All]



$tinybeginarrayc
hline
textn & 50 & 100 & 500 & 1000 \
hline
textpair & 34,21 & 89,55 & 377,233 & 987,610 \
hline
endarray$




Note: For some n, there are multiple pairs with maximum eaSteps length. For example, for n=50 there are 7 pairs that give a length 7 list:



MaximalBy[Reverse /@ Subsets[Range[50], 2], Length[eaSteps[#]] &] 



34, 21, 47, 29, 50, 29, 49, 30, 49, 31, 50, 31, 47,
34




 Length[eaSteps @ #] - 1 &/@ %



7, 7, 7, 7, 7, 7, 7




The table above gives only the first of multiple pairs.



Original answer:



You can get the length of Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1] using



n (n + 1)/2 


(which is Sum[1, i, 1, n, j, 1, i])



or



Length[Subsets[Range[n], 1, 2]]


For n = 100:



100 101 /2 



5050




Length[Subsets[Range[100], 1, 2]]



5050




table[n_Integer] := Flatten[Table[a, b, foo, a, 1, n, b, 1, a], 1];
Length[table[100]]



5050




For the second part of the question, using a brute force approach



MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&]



987, 610




Length[Length[eaSteps[987, 610]]] -1



14








share|improve this answer














share|improve this answer



share|improve this answer








edited 29 mins ago

























answered 3 hours ago









kglr

167k8188390




167k8188390











  • thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
    – user130306
    3 hours ago










  • @user130306, that's correct.
    – kglr
    3 hours ago










  • great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
    – user130306
    3 hours ago










  • using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
    – kglr
    2 hours ago

















  • thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
    – user130306
    3 hours ago










  • @user130306, that's correct.
    – kglr
    3 hours ago










  • great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
    – user130306
    3 hours ago










  • using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
    – kglr
    2 hours ago
















thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
– user130306
3 hours ago




thank you! so basically the reason I would know its 5050 before I even run the code is if I use Subsets right?
– user130306
3 hours ago












@user130306, that's correct.
– kglr
3 hours ago




@user130306, that's correct.
– kglr
3 hours ago












great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
– user130306
3 hours ago




great, thank you again. and for the second part of the question, do the values a = 987, b = 610, n = 14 work and is that the right answer?
– user130306
3 hours ago












using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
– kglr
2 hours ago





using a brute force approach MaximalBy[Reverse/@Subsets[Range[1000],2], Length[eaSteps[#]]&] does give 987, 610 and Length[eaSteps[987, 610]] gives 15.
– kglr
2 hours ago











user130306 is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















user130306 is a new contributor. Be nice, and check out our Code of Conduct.












user130306 is a new contributor. Be nice, and check out our Code of Conduct.











user130306 is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184366%2fhow-can-i-know-the-length-of-sublists-in-a-code-without-running-the-code%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke