OEIS Streams (get an idea of what streams are)

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.

What does OEIS mean?

I think showing some real world uses of streams would be a good introduction for those who’ve never come across them before

Online Encyclopedia of Integer Sequences

Yes, this is a great sample project for streams. The main thing it’s missing is a Notes box that explains and links to the OEIS.

I think it should also include some of my (or your!) favorite silly sequences, such as A000053 or A005150.

A082215

Drag this code into the editor.

Python code
class A082215:
    def __init__(self):
        self.current = "1"
        self.index = 2
    def __iter__(self):
        return self
    def __next__(self):
        current = self.current
        self.current = self.current + str(self.index) + self.current
        self.index += 1
        return current

stream_like = A082215()
for i in range(5):
    print(next(stream_like))

Added!

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.

Added:

  • A000040 (primes)
  • A000079 (powers of 2)
  • A000290 (squares)
  • A000330 (square pyramids)
  • A001057 (interleaved positive and negative integers)
  • A123456 (Für Elise)

Sorry that I haven't got to adding the legendary look-and-say sequence yet!

Wait, what’s A123456 (Für Elise)?

Added:

  • A000142 (factorial numbers)
  • A000292 (tetrahedral numbers)
  • A000522 (too lazy to explain, but I found this by playing with random operators)
  • A002942 (squares written backwards)
  • A005150 (the legendary look-and-say sequence; might not be the best implementation)
  • A053541 (n(10n-1))

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.

index*
Wait, it starts from 0. So “0ndex” is right.

So does that mean a regular index starts from \sqrt{-1}?

Off-topic

The indices that starts from \sqrt{-1} is an imaginary indices appearing in your head

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.

A005132 in AverageStudentBASIC:

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

I think I can’t do it by my own

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?

A000037


i might try to make one that actually checks if its a square tho

How about this implementation of A005132?

Windows Visual Basic Syntax:

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