create account

Suesa's Adventures in Programming (Part 1 of ?) by suesa-random

View this thread on: hive.blogpeakd.comecency.com
· @suesa-random ·
$16.13
Suesa's Adventures in Programming (Part 1 of ?)
![](https://cdn.pixabay.com/photo/2016/04/04/14/12/monitor-1307227_960_720.jpg)<sub>By geralt on pixabay.com</sub>

---

As some of you know, I recently finished my B.Sc. in biology. As fewer of you know, I will start my Master's not this, but next year. This leaves me some time for other things (like working part-time in a biopharmaceutical lab, being the COO of Utopian, you know, mundane stuff).

For my biopharmaceutical lab job, I needed to be enrolled as a student, because else they'd have to pay me more, and thus not hire me. Capitalism in action.

This left me with the question what I should enroll in. Of course, I wouldn't need to actually pass the class, but the thought of not accomplishing anything useful frustrated me, which led to the decision of enrolling as a computer science student and taking programming classes.

Now, the classes use [SML](https://en.wikipedia.org/wiki/Standard_ML), a functional programming language that I won't really use in my life.

*But*

SML is a good basis to get a general *understanding* for how programming works. It's very mathematical and will (hopefully) teach me how to think in code.

And because nothing is really accomplished if it hasn't been told to anyone, I've decided to share some of the things I'm doing for those classes. On this blog, because I don't think it's high quality enough for my main blog.

Still, I'll write this with the assumption that those reading it can't code, because why would you want to read this otherwise?

---
---
---

* *Task 1: Write a function that gives you the highest of three numbers. Use conditionals.*

A "conditional" is the "if - then - else" construct, and one of the things that are easiest to understand (in my opinion), because it's basically "normal" language. But be careful, in case you're dating a programmer because the conditional might get you some unwanted results.

"Go to the supermarket. ```If``` they have eggs ```then``` bring 10 ```else``` try another supermarket." Will get you the 10 eggs.

"Go to the supermarket. Buy milk, ```if``` they have eggs ```then``` bring 10, ```else``` try another supermarket." Will get you 10 cartons of milk, if the supermarket had eggs.

For my "give me the highest number" function, I chose ```x,y,z``` as variables, then checked if x is bigger than both y and z. If it was not, I compared y and z to see which of those is higher. Easy.

![Ü1A9 mit 2 konditionalen.JPG](https://cdn.steemitimages.com/DQmQaPFvHT6QgeauQLpM46ZSvpUxgucpFakBJ8fi27B1iyK/%C3%9C1A9%20mit%202%20konditionalen.JPG)

---
---

* *Task 2: Calculate the cross sum of a number, once using a recursion and once using a tail recursion."*

What's a recursion? Basically, you calculate something, take the result, put it in your original statement, and do the whole process all over again, until you reach a specific result.

A tail recursion is similar, but you don't have to "remember" the result you got before, which uses up fewer resources.


![Ü1A14.JPG](https://cdn.steemitimages.com/DQmW8GU1cZ722Yg3SNb9HhoTsrqfSmJRVsUmLGxRQeXZNQB/%C3%9C1A14.JPG)

What I did here first is the recursion. ```x div 10``` means I divide x by 10, and all I get is the number with the decimals shaved off. For example, ```21 div 10``` would give me a ```2```.

```x mod 10``` is similar, just the other way around: It gives me what's left after the divison. ```21 mod 10``` would give me ```1```.

So, ```quer``` (for "Quersumme", which is German for "cross sum") first checks if ```x div 10``` is smaller than ```1``` (which would be the case for all (positive) numbers between 1 and 9). If that's the case, it gives back exactly this number.

If not, the function uses itself again, but changes ```x``` to ```x div 10``` (example: ```12``` becomes ```1```) and adds ```x mod 10``` (in this example, creating the formula ```quer (1) + 2```).

Then it starts over. Now, ```1 div 10``` is smaller than ```1```, so we keep the ```1```. We now have ```1+2```. The result? ```3```. We successfully calculated the cross sum!

The tail recursion ```quer2``` does something similar, with one small difference: We don't add a ```+ something``` to the function, which allows us to throw everything that happened before out.

In the first step, it again tests if ```x mod 10``` is smaller than ```1``` and gives out ```x```if that's the case. So far, so good. 

But if ```x mod 10```isn't smaller than ```1```, the"help function" ```quer' ```comes into play.

What does ```quer'``` do? In contrary to ```quer```and ```quer2```it has two variables, ```x```and ```y```.

If you take a peek at the examples that come after, you'll see that I set the value of ```y``` to ```0```.

Now, let's take an x for which ```x div 10 >= 1``` and see what ```quer'``` does with that.

```
quer'(12,0)
12 mod 10 < 1 ?
-> 12 mod 10 = 2, false!
-> change quer'(12,0) to quer'(12 div 10, 0 + 12 mod 10)
(repeat from the beginning with new values)
quer'(1,2)
-> 1 mod 10 < 1 ?
-> 1 mod 10 = 1, false!
-> change quer'(1,2) to quer'(1 div 10, 2 + 1 mod 10)
(repeat from the beginning with new values)
quer'(0,3)
-> 0 mod 10 < 1?
-> 0 mod 10 = 0, true!
-> 3 + 0 mod 10
-> 3

```
<br> 
Aaaaand we have our result!

There's a couple more exercises I already did, but I think I should split it up in more posts, as it might get a bit overloaded.

Feel free to ask questions in the comments.



👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 13 others
properties (23)
authorsuesa-random
permlinksuesa-s-adventures-in-programming-part-1-of
categoryprogramming
json_metadata{"community":"steempeak","app":"steempeak","format":"markdown","tags":["programming","tutorial","technology","code","computerstuff"],"links":["https://en.wikipedia.org/wiki/Standard_ML"],"image":["https://cdn.pixabay.com/photo/2016/04/04/14/12/monitor-1307227_960_720.jpg","https://cdn.steemitimages.com/DQmQaPFvHT6QgeauQLpM46ZSvpUxgucpFakBJ8fi27B1iyK/%C3%9C1A9%20mit%202%20konditionalen.JPG","https://cdn.steemitimages.com/DQmW8GU1cZ722Yg3SNb9HhoTsrqfSmJRVsUmLGxRQeXZNQB/%C3%9C1A14.JPG"]}
created2018-10-28 10:19:12
last_update2018-10-28 10:19:12
depth0
children20
last_payout2018-11-04 10:19:12
cashout_time1969-12-31 23:59:59
total_payout_value12.345 HBD
curator_payout_value3.786 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,370
author_reputation29,768,903,867,487
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,203,233
net_rshares13,779,756,136,174
author_curate_reward""
vote details (77)
@drsensor ·
$0.04
*SME* (subject-matter expert) that has hands-on experience about software development and programming is pretty rare but really needed in most industries. Keep it up because the industries that aim to make a big impact (not sure if I could say the world 😂) needs that.
👍  
properties (23)
authordrsensor
permlinkre-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t105250709z
categoryprogramming
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["programming"],"users":[],"links":[],"image":[]}
created2018-10-28 10:52:51
last_update2018-10-28 10:52:51
depth1
children4
last_payout2018-11-04 10:52:51
cashout_time1969-12-31 23:59:59
total_payout_value0.032 HBD
curator_payout_value0.010 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length268
author_reputation17,679,210,755,117
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,204,653
net_rshares36,604,753,006
author_curate_reward""
vote details (1)
@suesa ·
$0.02
That's what I thought, too many people focus only on their field of expertise, and neglect everything else. Especially in our time, programming is something that one should at least know some basics of, imo.
👍  ,
properties (23)
authorsuesa
permlinkre-drsensor-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t113614367z
categoryprogramming
json_metadata{"tags":["programming"],"community":"steempeak","app":"steempeak"}
created2018-10-28 11:36:18
last_update2018-10-28 11:36:18
depth2
children3
last_payout2018-11-04 11:36:18
cashout_time1969-12-31 23:59:59
total_payout_value0.016 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length207
author_reputation218,686,954,260,455
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,206,677
net_rshares19,559,522,867
author_curate_reward""
vote details (2)
@drsensor ·
$0.04
Also, try to learn low-level architecture a little bit like "how the program gets run", "what's the magic behind that", etc. Sometimes it really helps a lot when facing strange cases.
👍  
properties (23)
authordrsensor
permlinkre-suesa-re-drsensor-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t124325479z
categoryprogramming
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["programming"],"users":[],"links":[],"image":[]}
created2018-10-28 12:43:30
last_update2018-10-28 12:43:30
depth3
children2
last_payout2018-11-04 12:43:30
cashout_time1969-12-31 23:59:59
total_payout_value0.032 HBD
curator_payout_value0.003 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length183
author_reputation17,679,210,755,117
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,209,808
net_rshares36,479,537,690
author_curate_reward""
vote details (1)
@ilovecoding ·
Hello! Your post has been resteemed and upvoted by @ilovecoding because **we love coding**! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On! 
 ![](https://codingforspeed.com/images/i-love-coding.jpg) 
*Reply !stop to disable the comment. Thanks!*
👍  
properties (23)
authorilovecoding
permlink20181028t101923761z
categoryprogramming
json_metadata{"tags":["ilovecoding"],"app":"ilovecoding"}
created2018-10-28 10:19:24
last_update2018-10-28 10:19:24
depth1
children0
last_payout2018-11-04 10:19:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length323
author_reputation40,845,997,808
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,203,242
net_rshares376,978,695
author_curate_reward""
vote details (1)
@juanmanuellopez1 ·
$0.03
<div class="text-justify">
<p>Well, I only have one question. Can this programming language be used for anything, and in any type of project?</p></div
👍  
properties (23)
authorjuanmanuellopez1
permlinkre-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t123642494z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-28 12:37:27
last_update2018-10-28 12:37:27
depth1
children6
last_payout2018-11-04 12:37:27
cashout_time1969-12-31 23:59:59
total_payout_value0.032 HBD
curator_payout_value0.002 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length150
author_reputation17,245,207,026,261
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,209,521
net_rshares36,511,847,682
author_curate_reward""
vote details (1)
@reggaemuffin ·
$0.04
SML is a relatively pure language, so it is with less clutter, great for teaching but nit good for real world problems. It can be used but it would be a poor choice.
👍  , , , , ,
properties (23)
authorreggaemuffin
permlinkre-juanmanuellopez1-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t210300559z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-28 21:03:00
last_update2018-10-28 21:03:00
depth2
children2
last_payout2018-11-04 21:03:00
cashout_time1969-12-31 23:59:59
total_payout_value0.031 HBD
curator_payout_value0.007 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length165
author_reputation37,964,839,695,531
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,233,679
net_rshares36,656,906,281
author_curate_reward""
vote details (6)
@juanmanuellopez1 ·
<div class="text-justify">
<p>But I suppose then that the one who learns the SML language can program whatever, given the difficulty that it presents.</p></div>
properties (22)
authorjuanmanuellopez1
permlinkre-reggaemuffin-re-juanmanuellopez1-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181029t101502456z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-29 10:15:48
last_update2018-10-29 10:15:48
depth3
children1
last_payout2018-11-05 10:15:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length160
author_reputation17,245,207,026,261
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,266,067
net_rshares0
@suesa ·
Well, all serious computer science students I've talked to so far (you know, those who don't just take the programming courses but also all the other stuff attached to the degree) think that SML is horrible to actually work with. I haven't really met many people who've used. I guess it's a bit impractical for actual projects and more suitable to understand the concepts of programming.
properties (22)
authorsuesa
permlinkre-juanmanuellopez1-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t124117776z
categoryprogramming
json_metadata{"tags":["programming"],"community":"steempeak","app":"steempeak"}
created2018-10-28 12:41:21
last_update2018-10-28 12:41:21
depth2
children2
last_payout2018-11-04 12:41:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length387
author_reputation218,686,954,260,455
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,209,705
net_rshares0
@juanmanuellopez1 ·
$0.03
<div class="text-justify">
<p>That is, it is more advisable to use SML more to practice programming. It shows that it is very complicated to do.</p></div
👍  
properties (23)
authorjuanmanuellopez1
permlinkre-suesa-re-juanmanuellopez1-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t124846179z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-28 12:49:36
last_update2018-10-28 12:49:36
depth3
children1
last_payout2018-11-04 12:49:36
cashout_time1969-12-31 23:59:59
total_payout_value0.032 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length153
author_reputation17,245,207,026,261
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,210,096
net_rshares36,412,614,008
author_curate_reward""
vote details (1)
@kristves ·
Hey, that's interesting! I started to learn some coding myself, too, recently, just some basic HTML, CSS, JS, and now C++.
Just gotta buy a notebook to write stuff up and through to remember better and practice, practice, practice.
properties (22)
authorkristves
permlinkre-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181030t134640910z
categoryprogramming
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["programming"],"users":[],"links":[],"image":[]}
created2018-10-30 13:46:42
last_update2018-10-30 13:46:42
depth1
children0
last_payout2018-11-06 13:46:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length231
author_reputation22,552,191,872,154
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,341,778
net_rshares0
@lemony-cricket ·
$0.06
Very cool to see that you've taken up programming! Interesting choice of language to start with. I've never actually seen this one, but it seems that it is popular in the theoretical realm of things :) 

Good luck on your adventures!
👍  ,
properties (23)
authorlemony-cricket
permlinkre-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t170501792z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-28 17:05:06
last_update2018-10-28 17:05:06
depth1
children4
last_payout2018-11-04 17:05:06
cashout_time1969-12-31 23:59:59
total_payout_value0.042 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length233
author_reputation15,797,102,626,770
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,223,039
net_rshares49,059,443,716
author_curate_reward""
vote details (2)
@reggaemuffin ·
$0.05
The choice of SML is to have a pure functional language where it is rather unlikely that any students have previous experience with it. Thus giving everyone some fair ground to learn together.

Languages like python, haskell or scheme might be popular enough to be known by many people. Whereas scheme is still pretty nice for teaching.
👍  , , , , , ,
properties (23)
authorreggaemuffin
permlinkre-lemony-cricket-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t210523091z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-28 21:05:21
last_update2018-10-28 21:05:21
depth2
children0
last_payout2018-11-04 21:05:21
cashout_time1969-12-31 23:59:59
total_payout_value0.037 HBD
curator_payout_value0.010 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length336
author_reputation37,964,839,695,531
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,233,792
net_rshares42,220,594,276
author_curate_reward""
vote details (7)
@suesa ·
Apparently next year we'll learn C and Java. Mostly Java. We'll see :D
properties (22)
authorsuesa
permlinkre-lemony-cricket-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181028t184328165z
categoryprogramming
json_metadata{"tags":["programming"],"community":"steempeak","app":"steempeak"}
created2018-10-28 18:43:30
last_update2018-10-28 18:43:30
depth2
children2
last_payout2018-11-04 18:43:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length70
author_reputation218,686,954,260,455
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,227,713
net_rshares0
@terrylovejoy ·
$0.04
My 2c worth.  Python is a useful language to learn as it is so widely used as an automation tool for so many applications.  You could use it in your masters, as well as automation with the Steem based platform and many other applications you might not think of just yet.  Once you learn SML, the other languages should be relatively easy to learn.
👍  
properties (23)
authorterrylovejoy
permlinkre-suesa-re-lemony-cricket-re-suesa-random-suesa-s-adventures-in-programming-part-1-of-20181029t005346841z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2018-10-29 00:53:48
last_update2018-10-29 00:53:48
depth3
children1
last_payout2018-11-05 00:53:48
cashout_time1969-12-31 23:59:59
total_payout_value0.030 HBD
curator_payout_value0.010 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length347
author_reputation15,797,973,031,321
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,243,109
net_rshares36,003,455,808
author_curate_reward""
vote details (1)
@tts ·
To listen to the audio version of this article click on the play image.
[![](https://s18.postimg.org/51o0kpijd/play200x46.png)](http://ec2-52-72-169-104.compute-1.amazonaws.com/suesa-random__suesa-s-adventures-in-programming-part-1-of.mp3)
Brought to you by [@tts](https://steemit.com/tts/@tts/introduction). If you find it useful please consider upvoting this reply.
👎  
properties (23)
authortts
permlinkre-suesa-s-adventures-in-programming-part-1-of-20181028t104127
categoryprogramming
json_metadata""
created2018-10-28 10:41:27
last_update2018-10-28 10:41:27
depth1
children0
last_payout2018-11-04 10:41:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length367
author_reputation-4,535,154,553,995
root_title"Suesa's Adventures in Programming (Part 1 of ?)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,204,195
net_rshares-36,389,007,994
author_curate_reward""
vote details (1)