Lab2

Run Settings
LanguageRaku
Language Version
Run Command
my @tracks = ( "Bohemian Rhapsody", "Rhapsody Bohemian", "Bohemian Slut", "Bohemian Slut", "Dingle Berry", "Dingle Burry", "Dingle Dungle", "Stairway to Heaven", "Hotel California", "Imagine", "Smells Like Teen Spirit", "Smells Like Teen Spirit" ); my %counts = (); for @tracks -> $title { # Convert title into an array of words my @parsed_title = $title.words; my $index = 0; # While there is a succeeding word for the current word while $index < @parsed_title.end { %counts{@parsed_title[$index]}{@parsed_title[$index + 1]}++; $index++; } } say %counts;
my %counts = "word1" => { "word1.1" => 2, "word1.2" => 1, "word1.3" => 3 }, "word2" => { "word2.1" => 1, "word2.2" => 1, "word2.3" => 1 }; my %word_history = "word2" => ["word2.2"]; my $word = "word2"; my $best_word = ""; my @word_list = %counts{$word}.sort(*.values).reverse.map(*.keys); my $index = 0; while @word_list[$index] (elem) %word_history{$word}.values { $index++; } $best_word = @word_list[$index]; %word_history{$word}.push(@word_list[$index]); say @word_list; say $best_word[0];
my %counts = "word1" => { "word1.1" => 2, "word1.2" => 1, "word1.3" => 3 }, "word2" => { "word2.1" => 2, "word2.2" => 3, "word2.3" => 1 }; my %word_history = "word2" => ["word2.2"]; my $word = "word2"; my $best_word = ""; my @word_list = %counts{$word}.sort(*.values).reverse; my $index = 0; while @word_list[$index] (elem) %word_history{$word}.values { $index++; } $best_word = @word_list[$index]; %word_history{$word}.push(@word_list[$index]); say @word_list; say $best_word.WHAT; say %word_history.WHAT;
my @tracks = ( "Bohemian Rhapsody", "Stairway to Heaven", "Hotel California", "Imagine", "Smells Like Teen Spirit" ); my %counts = (); for @tracks -> $title { # Convert title into an array of words my @parsed_title = $title.words; my $index = 0; # If there is a proceeding word for the current word if @parsed_title[$index + 1] { %counts{@parsed_title[$index]}{@parsed_title[$index + 1]}++; $index++; } } say %counts; my %counts = ( "word1" => ("word1.1" => 2, "word1.2" => 1, "word1.3" => 3}), "word2" => ("word2.1" => 6, "word2.2" => 4, "word2.3" => 3), ); #%counts{"word2"}{"word2.4"}++; #my %highest = %counts{"word2"}.max(*.value); #say %counts{"word2"}{"word2.4"}; my @highest = %counts{"word2"}.sort(*.values).reverse; sub word_check($mcw_check, $index) { given $mcw_check { when 0 { if @word_list[index] (elem) %word_history{$word} { $index++; word_check(0, $index) }else { } } } }
my @tracks = ( "Bohemian Rhapsody", "Rhapsody Bohemian", "Test zeebra", "Test kiwi", "Test apple", "Stairway to Heaven", "Hotel California", "Imagine", "Smells Like Teen Spirit", "Smells Like Teen Spirit", "test2 bord", "test2 tord", "test2 word", "test2 zord", "test2 aord", ); # my %counts = # "Bohemian" => {"Rhapsody" => 1}, # "Hotel" => {"California" => 1}, # "Like" => {"Teen" => 2}, # "Rhapsody" => {"Bohemian" => 1}, # "Smells" => {"Like" => 2}, # "Stairway" => {"to" => 1}, # "Teen" => {"Spirit" => 2}, # "Test" => {"Bleep" => 1, "Blip" => 1, "Bloop" => 1}, # "to" => {"Heaven" => 1}; ###### # Birgram construction ###### my %counts = (); for @tracks -> $title { # Convert title into an array of words my @parsed_title = $title.words; my $index = 0; # While there is a succeeding word for the current word while $index < @parsed_title.end { %counts{@parsed_title[$index]}{@parsed_title[$index + 1]}++; $index++; } } ###### # MCW ###### # my %word_history = "test2" => ["aord", "bord", "tord", "word", "zord"]; my %word_history = (); my $word = "test2"; my $best_word = ""; my @word_list = (); my $index = 0; for %counts{$word}.kv -> $key, $value { @word_list.push: {$key => $value}; } @word_list = @word_list.sort: *.keys; # say @word_list.end; # say @word_list[1].keys[0]; # say @word_list[1].values[0]; # say @word_list; # say @word_list[$index]; # say @word_list[$index + 2]; #say @word_list[$index]; #say %word_history{$word}.values[0]; # say $index; if @word_list[$index].keys[0] !(elem) %word_history.keys { # Code to execute if the word is in word_history say "Word has already been used"; } while $index <= @word_list.end { if @word_list[$index].keys[0] (elem) %word_history{$word}.values { $index++; } elsif $best_word == "" { $best_word = @word_list[$index]; $index++; } else { if @word_list[$index].keys[0] (elem) %word_history{$word}.values { $index++; } else { if @word_list[$index].values[0] > $best_word.values[0] { $best_word = @word_list[$index]; } $index++; } } } my $history_word = "inList"; my $history_word2 = "another"; %word_history{$history_word} = 1; %word_history{$history_word2} = 1; if $best_word != "" { $best_word = $best_word.keys[0]; } say %counts; say @word_list; say $best_word; say %word_history;
my $title = "jumping dogs run"; my $new_word = "quickly"; $title = $title ~ " " ~ $new_word; say $title;
Editor Settings
Theme
Key bindings
Full width
Lines