Weekly Challenge 108

Tasks, My solutions

TASK #1 › Locate Memory

Task

Write a script to declare a variable or constant and print it’s[sic] location in the memory.

My solution

One good thing about Perl (and most modern languages) is that y…


This content originally appeared on DEV Community and was authored by Simon Green

Tasks, My solutions

TASK #1 › Locate Memory

Task

Write a script to declare a variable or constant and print it’s[sic] location in the memory.

My solution

One good thing about Perl (and most modern languages) is that you don't really need to worry about memory management. Perl will automatically reclaim memory when a variable is no longer used.

For this task, I take the reference to the variable (for example SCALAR(0x559184ba5890) and use regular expression to display the location (the bit between the parenthesis).

Minified

In 22 characters, this can be minified to the below example.

» perl -E 'say\$a=~/(0x[0-9a-f]+)/'
0x555668d2a3f8

Example

» ./ch-1.pl 
0x555668d2a3f8

TASK #2 › Bell Numbers

Task

Write a script to display top 10 Bell Numbers.

My solution

In tackling this task, the animated gif is very helpful. I use the @bell array to reproduce this. I start by seeding the table with a single value, and then use the copy and add functions to generate the subsequent values. Finally I use a foreach loop to display the last number in each row to display the list of bell numbers.

Example

» ./ch-2.pl
1
2
5
15
52
203
877
4140
21147
115975


This content originally appeared on DEV Community and was authored by Simon Green


Print Share Comment Cite Upload Translate Updates
APA

Simon Green | Sciencx (2021-04-18T14:47:53+00:00) Weekly Challenge 108. Retrieved from https://www.scien.cx/2021/04/18/weekly-challenge-108/

MLA
" » Weekly Challenge 108." Simon Green | Sciencx - Sunday April 18, 2021, https://www.scien.cx/2021/04/18/weekly-challenge-108/
HARVARD
Simon Green | Sciencx Sunday April 18, 2021 » Weekly Challenge 108., viewed ,<https://www.scien.cx/2021/04/18/weekly-challenge-108/>
VANCOUVER
Simon Green | Sciencx - » Weekly Challenge 108. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/18/weekly-challenge-108/
CHICAGO
" » Weekly Challenge 108." Simon Green | Sciencx - Accessed . https://www.scien.cx/2021/04/18/weekly-challenge-108/
IEEE
" » Weekly Challenge 108." Simon Green | Sciencx [Online]. Available: https://www.scien.cx/2021/04/18/weekly-challenge-108/. [Accessed: ]
rf:citation
» Weekly Challenge 108 | Simon Green | Sciencx | https://www.scien.cx/2021/04/18/weekly-challenge-108/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.