DEV Community

Cover image for The Weekly Challenge Advent Calendar 2022
Mohammad S Anwar
Mohammad S Anwar

Posted on • Updated on

The Weekly Challenge Advent Calendar 2022


|   2019   |   2020   |   2021   |   2022   |


Welcome to our 4th Advent Calendar. I promise to present interesting topic every day contributed by esteemed members of Team PWC.


MON
TUE
WED
THU
FRI
SAT
SUN









Day 1
1
Day 2
2
Day 3
3
Day 4
4
Day 5
5
Day 6
6
Day 7
7
Day 8
8
Day 9
9
Day 10
10
Day 11
11
Day 12
12
Day 13
13
Day 14
14
Day 15
15
Day 16
16
Day 17
17
Day 18
18
Day 19
19
Day 20
20
Day 21
21
Day 22
22
Day 23
23
Day 24
24

25


26


27


28


29


30


31




Top comments (4)

Collapse
 
yukikimoto profile image
Yuki Kimoto

Could I join the the weekly challenge using SPVM in this comment?

Collapse
 
manwar profile image
Mohammad S Anwar

Certainly, feel free.

Collapse
 
yukikimoto profile image
Yuki Kimoto • Edited

I tried Day 5 Farey Sequence using SPVM.

theweeklychallenge.org/blog/advent...

# SPVM/FareySequence.spvm
class FareySequence {
  use DoubleList;
  use Fn;
  use Sort;

  static method farey_sequence : void ($n : int) {
    my $fs_list = DoubleList->new([(double)0/1, 1/1]);

    for (my $numerator = 1; $numerator < $n; $numerator++) {
      for (my $denominator = $numerator + 1; $denominator < $n + 1; $denominator++) {
        $fs_list->push((double)$numerator / $denominator);
      }
    }

    my $fs = $fs_list->to_array;
    Sort->sort_double_asc($fs);

    say dump $fs;
  }
}
Enter fullscreen mode Exit fullscreen mode
# farey_sequence.pl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin";

use SPVM 'FareySequence';

SPVM::FareySequence->farey_sequence(5);
Enter fullscreen mode Exit fullscreen mode

Output:

[
  0,
  0.2,
  0.25,
  0.333333,
  0.4,
  0.5,
  0.5,
  0.6,
  0.666667,
  0.75,
  0.8,
  1
] : double[](0x5652e2536340)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
yukikimoto profile image
Yuki Kimoto

Thanks. I will try an example.