Mere lists and functions are boring! Instead, I bring up something the vast majority of the community (my intuition) doesn't pay much attention to: streams! I find streams to be a splendid data type, and it has only so much potential.
The project below are stream representations for some sequences in OEIS. Feel free to contribute anyway, whether construct a stream yourself, recommend me OEIS gems you discovered, suggest changes to this project, and more.
To simply see a sequence, grab a block representing a stream and snap it in (list (10 v) items of stream @list ::#a40000). For example, say A001477 is (stream with numbers from (0)::#a40000). (list (10 v) items of stream (stream with numbers from (0)::#a40000)::#a40000) gives you the first 10 items of A001477. Replace the number 10 with another number for a different number of items to output.
I added the first one, because why not? ^_^ I will add the second one too later, and it would be a good exercise to look for a way to write the generator.
Added! Thanks for your contribution. Though sorry for being fussy about this again, but I highly suggest you switch your language to English before posting script pics. It took me a while to figure out that this was a join block.
My code for A051352, where if the 0ndex is a prime, the term subtracts the 0ndex from the last term, otherwise, adds the 0ndex to the last term. Not the best or the most elegant code, so if you want to simplify it, feel free to.
Oh god, how did I not realize that trying to come up with a quick colloquial way to say "zero-based index"...? Guess it would be called an 1ndex...
By the way, I got inspiration from a topic for an alternative version of list blocks with zero-based indices, where the labels of those list blocks are something like this.
sub recaman(n) do
seq = []
for i in 1...n do
if i == 0 then
x = 0
else
x = seq[i - 1] - i
end if
if (x >= 0 & !(x.contains(seq))
seq.append(x)
else
seq.append(seq[i - 1] + i)
end if
end for
end sub
I didn’t implement the streams one but I have to go to the academy ;( Just wait for 3:15
Great choice. It is even the one in the OEIS logo.
I was going to do that too earlier, but I wasn't very sure how to, in generate stream () check if an item already appeared in the stream. @bh, may you help?
Sub Append(Arr, Item)
ReDim Preserve Arr(UBound(Arr) + 1)
Arr(UBound(Arr)) = Item
End Sub
Function Contains(Arr, Item)
Dim Index
For Index = LBound(Arr) To UBound(Arr)
If Arr(Index) = Item Then
Contains = True
Exit Function
End If
Next
Contains = False
End Function
Function Recaman(ListLength)
Dim Sequence()
ReDim Sequence(-1)
Dim Index
For Index = 0 To ListLength - 1
Dim CurrentValue
If Index = 0 Then
CurrentValue = 0
Else
CurrentValue = Sequence(Index - 1) - Index
End If
If CurrentValue < 0 Or Contains(Sequence, CurrentValue) Then
CurrentValue = Sequence(Index - 1) + Index
End If
WScript.Echo CurrentValue & " (" & Index + 1 & "/" & ListLength & ")"
Append Sequence, CurrentValue
Next
End Function
Recaman 14