# Eternity Async Tutoring

**URL:** <https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932>\
**Category:** Tutoring\
**Created:** [April 17, 2024, 11:22pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932 "2024-04-17T23:22:52Z")\
**Posts on this page:** 20\
**Page:** 37

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 13, 2025, 7:44pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/722 "2025-01-13T19:44:37Z")

</div>

I tried converting between hashes and arrays. I guess because hashes are key-value _pairs_ that it can only convert arrays that consist of two things into hashes? I tried converting my larger arrays into hashes. Didn’t work. When I googled it, I didn’t find an explanation on converting between hashes and arrays. I just found example code where the arrays only had two values. Something like this:

 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/3/3919b8db453e8d60617d1acea94f68b79b63c6de.png)

I noticed it didn’t work if I just did [3,4]. It needed double square brackets. So the array has to have stuff already in pairs to make it into a hash?

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 13, 2025, 9:30pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/723 "2025-01-13T21:30:39Z")

</div>

> [@Eternity](#):
>
> Do you have any tips for tracking assignments?

I’d suggest trying the forum’s built-in bookmarking feature.

If that doesn’t work well for you, try a todo list.

---

<div class="post-metadata">

**Author:** ![LMD](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/lmd/32/3213_2.png) [@LMD](https://discuss.criticalfallibilism.com/u/LMD)\
**Post date:** [January 13, 2025, 11:32pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/724 "2025-01-13T23:32:28Z")

</div>

> [@Eternity](#):
>
> @LMD how do you keep track of assignments and stuff?

I just keep it in my head mostly. Sometimes it goes in the to do list for that day if I can sense it’s getting to much to hold in my head. Recently I’ve been doing that more because I’ve got like 4 active threads going on.

I’m going to look into the bookmark feature that Elliot mentioned.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 14, 2025, 12:55am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/725 "2025-01-14T00:55:52Z")

</div>

> [@Eternity](#):
>
> - As far as programming goes, the latest stuff you wanted me to was to work with hashes and arrays. I did some stuff with hashes previously and now I’m going to post some stuff on arrays and I should be fine for programming I think?

Do you want to do more programming stuff?

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 14, 2025, 12:56am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/726 "2025-01-14T00:56:30Z")

</div>

> [@Eternity](#):
>
> Before I share some work I have done, I decided to make a list of the assignments I said I would work on/am working on:

Did you want to do something related to fraud laws?

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 14, 2025, 3:04am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/727 "2025-01-14T03:04:36Z")

</div>

> [@Elliot](#):
>
> Do you want to do more programming stuff?

Yes. I’ve been enjoying it.

> [@Elliot](#):
>
> Did you want to do something related to fraud laws?

That sounds interesting.

If we can work on both at once thats fine. If not, I’d prefer programming for now.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 14, 2025, 3:08am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/728 "2025-01-14T03:08:45Z")

</div>

> [@Eternity](#):
>
> If we can work on both at once thats fine. If not, I’d prefer programming for now.

it’s up to you what activities you can manage at once. if you want to pick something that has been posted on the forum recently with some connection to fraud, and post about it, you can.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 14, 2025, 3:10am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/729 "2025-01-14T03:10:34Z")

</div>

`5.times {|n| puts n * 2 if n != 3}`

See if you can predict the output of this ruby code before running it.

You may want to look things up. FYI, the curly braces and their contents are called a “block”, which is a way of providing an anonymous function as an input to a function. A function being anonymous means it hasn’t been saved anywhere permanent with a name, so you give a chunk of code right there instead of naming some pre-existing function.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 14, 2025, 3:42am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/730 "2025-01-14T03:42:58Z")

</div>

Without looking anything up:

1.) It runs that block 5 times. What does that block do? Hmm. I don’t know what | | is doing. Hmm. puts n \* 2 is multiplying whatever n is by 2 and then outputting it. If n != 3 is saying it will only do it if n does not equal 3. I think != is not equal.

or

2.) That whole blocks result is multiplied by 5.

Let me go through the rest of what you said:

> [@Elliot](#):
>
> FYI, the curly braces and their contents are called a “block”, which is a way of providing an anonymous function as an input to a function.

So in

> [@Elliot](#):
>
> 5.times {|n| puts n \* 2 if n != 3}

```auto
{|n| puts n * 2 if n != 3}

```

is a block. Ok.

> [@Elliot](#):
>
> which is a way of providing an anonymous function as an input to a function.

So that block is an input to a function. That block helps put this thing called an anonymous function as an input to a function. An anonymous function is a function that hasn’t been saved, is not permanent, and doesn’t have a name. I assume that if we didn’t have that block anonymous function thing going on there you would need a pre-existing function. So is 5.times a function. Hmm.

After looking things up:

The times function: [Ruby Integer times function with example - GeeksforGeeks](https://www.geeksforgeeks.org/ruby-integer-times-function-with-example/) :

> The **times** function in [Ruby](https://www.geeksforgeeks.org/ruby-programming-language/) returns all the numbers from 0 to one less than the number itself.

Looking at the output examples they gave. I think it gives one less than the number itself because it starts from 0. Seems like | | is necessary for the code but not sure. Googling again got me this: [Better Know A Ruby Thing #5: Block Arguments – Noel Rappin Writes Here](https://noelrappin.com/blog/2024/03/better-know-block-arguments/) :

> Syntactically, Ruby allows you to define a block at the end of any method call. That is the only place you can define a block. Ruby has two different syntaxes for delimiting a block: `do/end` and curly braces `{ }` . In both cases you can define arguments to the block and local variables by putting them between pipe characters `| var |` at the beginning of the block.

So the variable n needs to be in between pipes in the block for it to work. Ok.

I’m pretty sure I know what puts n \* 2 is doing. So just checking on n !=3. From [Ruby - Operators](https://www.tutorialspoint.com/ruby/ruby_operators.htm) :

> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true.

So yeah does not equal is right then.

Putting it all together:

```auto
5.times {|n| puts n * 2 if n != 3}

```

n will have the values 0, 1, 2, 3, 4  
it will output a value n\*2 _if_ n does not equal 3.  
so it outputs:  
0, 2, 4, 8

Looks like I was right:

 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/b/b0e4b51ec66acce05d903eef92611518d536a06f.png)

Why’d it output the 5 at the end?

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 14, 2025, 3:51am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/731 "2025-01-14T03:51:30Z")

</div>

> [@Eternity](#):
>
> Looks like I was right:

great

> [@Eternity](#):
>
> Why’d it output the 5 at the end?

Everything in ruby has a value (which can be `nil`).

Functions like times can say `return stuff` to specify their output value. If they don’t, the value of the last line of code in the function is the output value. It’s often set to something that could potentially be useful (in this case the number of times) rather than to `nil`.

In irb, when you enter some code, it evaluates it and prints its value. It still does this even if the code contains instructions to print other stuff. On the other hand, if you put the code in a text file and run it with ruby, it won’t print anything out unless you specifically say to. When code runs in general, lots of outputs just get ignored. But irb prints outputs to help you see what’s going on.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 14, 2025, 4:26pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/732 "2025-01-14T16:26:02Z")

</div>

Ruby is an object oriented programming language. That’s a design pattern which is commonly used throughout. An “object” is a complex data type that groups together variables and functions. This helps organize functions in two ways. First, it separates functions into groups instead of there being a single list of all functions that exist. Second, it groups functions together with relevant data.

A “class” is the name for a type or category of object. Then one or more objects of that type can be made. E.g. Integer and String are classes in Ruby, and you can have multiple “instances” of them: 1, 2, 3, “hi”, “bye”, “string”, etc.

Every object instance has some data (in this case, what number it is, or what characters are in the string) and some functions. In object oriented programming, functions are commonly called “methods” and are called with a dot syntax.

Objects also help with reusing code. If you’re writing chess software, you’ll deal with 32 pieces and 64 squares. Instead of defining each one individually, you can make a piece class and a square class and use each class multiple times. You can also have sub-classes (like a knight or queen) which have the code for pieces plus additional customizations. If you’re making poker software, you can have a card class with variables for the suit and the number instead of writing separate code for all 52 cards.

Here’s an example of the dot syntax for calling methods:

`3.zero?`

“zero?” is a function in the Integer class which can be used with any Integer instance.

Object functions can take inputs. For example:

`3.+(4)`

Addition in ruby is an object-oriented method call. “+” is a function in the integer class (the same name “+” is also defined separately for some other classes – reusing function names can be confusing but can also be convenient and useful if done well).

You can write `3 + 4` and that works too, but that’s actually just an abbreviation, a convenience shortcut. For certain function names (none of which begin with a letter, I think) you can leave out the dot and ruby knows what you means. Similarly, for lots of function calls you can leave out parentheses and ruby figures it out anyway. Similarly, `3 < 4` works and is a short version equivalent to `3.<(4)`. “\<” is a function defined for integers.

Function calls can be chained together. `3.-(4).+(5)` Guess what this will output then run it and see.

All function calls in ruby are actually method calls. `puts 3` is actually the same as `self.puts(3)`. Ruby always has a current context with a default object (named “self” if you need to refer to it explicitly) which is used when you don’t specify. All ruby functions are grouped in some object. The “puts” method is defined in the “Kernel” class. When you define a function with “def”, it goes in the current default context unless you specify otherwise.

In irb, run `3.class`, `3.class.ancestors`, `3.methods` and `3.class.methods`.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 18, 2025, 1:52am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/733 "2025-01-18T01:52:55Z")

</div>

Feeling a tad sick. Still wanted to do something before going to bed. Read over the post, understood most of it I think?

> [@Elliot](#):
>
> In irb, run `3.class`, `3.class.ancestors`, `3.methods` and `3.class.methods`.

 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/f/f8d2a1cab9b3cfd1d57f400cab20d88e9889ba89.jpeg)

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 18, 2025, 2:21am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/734 "2025-01-18T02:21:13Z")

</div>

Try writing code to create a deck of cards: an array with 52 2-character strings, one for each card. Don’t get stuck for a long time if you don’t know how.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 18, 2025, 2:48am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/735 "2025-01-18T02:48:12Z")

</div>

> [@Elliot](#):
>
> Try writing code to create a deck of cards: an array with 52 2-character strings, one for each card. Don’t get stuck for a long time if you don’t know how.

Am I writing an array with 52 2-character strings? Or am I writing code that creates an array with 52 2-character strings? I don’t know if the second is possible.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 18, 2025, 3:01am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/736 "2025-01-18T03:01:04Z")

</div>

> [@Eternity](#):
>
> Am I writing an array with 52 2-character strings?

This?:

```auto
cards = Array [["A","Heart"],[2,"Heart"],[3,"Heart"],[4, "Heart"],[5, "Heart"],[6, "Heart"],[7, "Heart"],[8, "Heart"],[9, "Heart"],[10, "Heart"],["J", "Heart"],["Q", "Heart"],["K", "Heart"],
["A","Spade"],[2,"Spade"],[3,"Spade"],[4, "Spade"],[5, "Spade"],[6, "Spade"],[7, "Spade"],[8, "Spade"],[9, "Spade"],[10, "Spade"],["J", "Spade"],["Q", "Spade"],["K", "Spade"],
["A","Clubs"],[2,"Clubs"],[3,"Clubs"],[4, "Clubs"],[5, "Clubs"],[6, "Clubs"],[7, "Clubs"],[8, "Clubs"],[9, "Clubs"],[10, "Clubs"],["J", "Clubs"],["Q", "Clubs"],["K", "Clubs"],
["A","Diamonds"],[2,"Diamonds"],[3,"Diamonds"],[4, "Diamonds"],[5, "Diamonds"],[6, "Diamonds"],[7, "Diamonds"],[8, "Diamonds"],[9, "Diamonds"],[10, "Diamonds"],["J", "Diamonds"],["Q", "Diamonds"],["K", "Diamonds"]]

```

* * *

Oh. Character. So if I have the right idea then I should have used H,S,C,D. Ok. If my idea is right I will fix to just 2-characters.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 18, 2025, 5:15pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/737 "2025-01-18T17:15:21Z")

</div>

The idea is to get the computer to do repetitive tasks. That way, even if there were a million cards, it would scale up with about the same amount of work for the programmer.

2-character card strings are like “4D” or “KH”.

To simplify, let’s start with only the cards from 2-9, so it’ll be a 32 card deck.

Breaking the problem down into smaller parts can help a lot. For example, you might want to start with just one suit before adding the other suits.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 18, 2025, 5:24pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/738 "2025-01-18T17:24:23Z")

</div>

> [@Elliot](#):
>
> To simplify, let’s start with only the cards from 2-9, so it’ll be a 32 card deck.

This?:  
`cards = Array[["2H"],["3H"],["4H"],["5H"],["6H"],["7H"],["8H"],["9H"], ["2S"],["3S"],["4S"],["5S"],["6S"],["7S"],["8S"],["9S"], ["2C"],["3C"],["4C"],["5C"],["6C"],["7C"],["8C"],["9C"], ["2D"],["3D"],["4D"],["5D"],["6D"],["7D"],["8D"],["9D"]]`

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 18, 2025, 5:26pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/739 "2025-01-18T17:26:22Z")

</div>

No, you’re making the cards yourself, one by one. Use a loop.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [January 19, 2025, 4:18am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/740 "2025-01-19T04:18:15Z")

</div>

Haven’t started/put much thought into it yet but the thought occurred me: is it fine to look stuff up for this task? or should I try and just do it from what I know? (I’m assuming what we’ve gone over already/what I know is sufficient but I don’t know.)

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [January 19, 2025, 4:30am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/741 "2025-01-19T04:30:49Z")

</div>

yes you can look stuff up. you’ll probably need to look up at least a couple small things.

[Previous page](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932.md?page=36)

[Next page](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932.md?page=38)
