Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 18, 2021 02:47 pm GMT

Weekly Challenge 108

Tasks, My solutions

TASK #1 Locate Memory

Task

Write a script to declare a variable or constant and print its[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.pl1251552203877414021147115975

Original Link: https://dev.to/simongreennet/weekly-challenge-108-3di2

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To