| 1 |
# Soros Tutorial Three 🛠️ Hello, Real World! |
| 2 |
# |
| 3 |
# Using the simplest regex reference |
| 4 |
# we solve a typical Soros problem, converting |
| 5 |
# numbers to ordinal abbreviations. |
| 6 |
# |
| 7 |
# |
| 8 |
# INTRODUCTION |
| 9 |
# |
| 10 |
# Syntax of a Soros program line: |
| 11 |
# |
| 12 |
# regex_pattern regex replacement |
| 13 |
# |
| 14 |
# The \0 (backslash zero) in the regex replacement |
| 15 |
# is a reference for the input number. |
| 16 |
# |
| 17 |
# For example, the following program line match every |
| 18 |
# input number and replace it by ownself, i.e. we get |
| 19 |
# back the input number without any changes, as you can |
| 20 |
# see in the right output list window after removing |
| 21 |
# the # at the beginning of the line: |
| 22 |
|
| 23 |
#.* \0 |
| 24 |
|
| 25 |
# TASK 1 |
| 26 |
# |
| 27 |
# It’s possible to refer the input number multiple times |
| 28 |
# in the same regex_replacement, combined with arbitrary |
| 29 |
# text. |
| 30 |
# |
| 31 |
# Modify the *previous program line* to greet the input |
| 32 |
# number double, as follows! |
| 33 |
# |
| 34 |
# 1 -> Hello, 1! Hi, 1! |
| 35 |
# 2 -> Hello, 2! Hi, 2! |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
# TASK 2 |
| 40 |
# |
| 41 |
# Complete the program of Tutorial 1 to handle all |
| 42 |
# English ordinal abbreviations! |
| 43 |
# |
| 44 |
# Rules: |
| 45 |
# |
| 46 |
# I Every word ending with 1, 2, 3 has got an |
| 47 |
# abbreviation ending with 1st, 2nd, 3rd, |
| 48 |
# for example, 1 -> 1st (first), 22 -> 22nd |
| 49 |
# (twenty-second), 103 -> 103rd (one hundred third). |
| 50 |
# |
| 51 |
# Ib Exception: numbers ending with 11, 12 or 13. |
| 52 |
# Example: 11 -> 11th (eleventh), 112 -> 112th |
| 53 |
# (one hundred twelfth), 1013 -> 1013th |
| 54 |
# (one thousand and thirteenth). |
| 55 |
# |
| 56 |
# II Other numbers get “th”. Example: 4 -> 4th (fourth). |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
SCROLL DOWN FOR SOLUTIONS |
| 62 |
⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
# SOLUTION – TASK 1 |
| 72 |
# |
| 73 |
# .* HELLO, \0! HI, \0! |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
# SOLUTION – TASK 2 |
| 78 |
# |
| 79 |
# The trick is there in the first line, |
| 80 |
# a pattern to match all input |
| 81 |
# ending with 1., for example, 10, 11, .. 19, |
| 82 |
# 110, 111 etc.: |
| 83 |
# |
| 84 |
# .*1. \0th |
| 85 |
# .*1 \0st |
| 86 |
# .*2 \0nd |
| 87 |
# .*3 \0rd |
| 88 |
# .* \0th |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
######################################################## |
| 93 |
# CONGRATULATIONS – You have finished Tutorial Three! 🙂 |
| 94 |
######################################################## |