Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Haskell, (削除) 67 (削除ここまで)(削除) 61 (削除ここまで)(削除) 60 (削除ここまで)(削除) 56 (削除ここまで)(削除) 55 (削除ここまで) 53 characters

Haskell, (削除) 67 (削除ここまで)(削除) 61 (削除ここまで)(削除) 60 (削除ここまで)(削除) 56 (削除ここまで)(削除) 55 (削除ここまで) 53 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++x#s
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]

#Haskell, (削除) 67 (削除ここまで)(削除) 61 (削除ここまで)(削除) 60 (削除ここまで)(削除) 56 (削除ここまで)(削除) 55 (削除ここまで) 53 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++x#s
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]

Haskell, (削除) 67 (削除ここまで)(削除) 61 (削除ここまで)(削除) 60 (削除ここまで)(削除) 56 (削除ここまで)(削除) 55 (削除ここまで) 53 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++x#s
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]
added 8 characters in body
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37

#Haskell, (削除) 67 (削除ここまで) (削除) 61 (削除ここまで) (削除) 60 (削除ここまで) (削除) 56 (削除ここまで) 55(削除) 55 (削除ここまで) 53 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++(x#s)2]++x#s
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]

#Haskell, (削除) 67 (削除ここまで) (削除) 61 (削除ここまで) (削除) 60 (削除ここまで) (削除) 56 (削除ここまで) 55 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++(x#s)
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]

#Haskell, (削除) 67 (削除ここまで) (削除) 61 (削除ここまで) (削除) 60 (削除ここまで) (削除) 56 (削除ここまで) (削除) 55 (削除ここまで) 53 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++x#s
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]
added 478 characters in body
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37

#Haskell, (削除) 67 (削除ここまで) (削除) 61 (削除ここまで) (削除) 60 (削除ここまで) 56(削除) 56 (削除ここまで) 55 characters

g n=take n2ドル:4:h
a#(x:s)=[a..a+xx-2]++((a+x)#sx#s)
h=5:6:8#hh=5#scanl(+)8h

newback to the first algorithm now.

this algorithm workssolution computes the complement sequence by realizingsumming the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is made up of sequential "runs"the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of sequential elements from h.

subtleties:

h is actually the figure figure sequence except for the first three runs2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason [2] [4 5 6] [8 9 10 11]scanl(+)8h, and that the runs are of (which is the length ofcode for the complement sequence numbers themselves minus one.(except for the first run's length is 1 = 2-1; the second 3 = 4-1; elements) with added 1's) has 8 in it. it is for the third 4 = 5-1 and so on.

soelement of the algorithm startscomplement sequence with 1 added to it.
the reason the starting elements and works outcomputation is not missing the rest by themfirst two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]

#Haskell, (削除) 67 (削除ここまで) (削除) 61 (削除ここまで) (削除) 60 (削除ここまで) 56 characters

g n=take n2ドル:4:h
a#(x:s)=[a..a+x-2]++((a+x)#s)
h=5:6:8#h

new algorithm now.

this algorithm works by realizing that the sequence is made up of sequential "runs" of sequential elements. the first three runs are [2] [4 5 6] [8 9 10 11], and that the runs are of the length of the sequence numbers themselves minus one. the first run's length is 1 = 2-1; the second 3 = 4-1; the third 4 = 5-1 and so on.

so the algorithm starts with the starting elements and works out the rest by them.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]

#Haskell, (削除) 67 (削除ここまで) (削除) 61 (削除ここまで) (削除) 60 (削除ここまで) (削除) 56 (削除ここまで) 55 characters

g n=take n2ドル:4:h
a#(x:s)=[a..x-2]++(x#s)
h=5#scanl(+)8h

back to the first algorithm.

this solution computes the complement sequence by summing the starting elements of the sequence. it then computes the sequence as all the numbers between the complement's sequence numbers.

(#) is the function that calculates the numbers between the complement sequence.
h is the sequence itself.
g is the function that answers the question.

the g function is defined to just take the needed amount of elements from h.

subtleties:

h is actually the figure figure sequence except for the first 2 elements.
not the complement sequence is computed, but the complement sequence with added 1 for each element.
these two subtleties are the reason scanl(+)8h (which is the code for the complement sequence (except for the first 2 elements) with added 1's) has 8 in it. it is for the third element of the complement sequence with 1 added to it.
the reason the computation is not missing the first two elements is because they are added in g in 2:4:h.

example:

>g 50
[2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,57,58,59]
new algorithm, golfed a bit more
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
better wording
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
code wasn't correct. now fixed.
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
a simple fix
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
deleted 9 characters in body
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
explanations!
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
new algorithm and shorter code
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37
Loading

AltStyle によって変換されたページ (->オリジナル) /