5 kyu

Basic DeNico

481 of 1,477dcieslak

Description:

Task

Write a function deNico/de_nico() that accepts two parameters:

  • key/$key - string consists of unique letters and digits
  • message/$message - string with encoded message

and decodes the message using the key.

First create a numeric key basing on the provided key by assigning each letter position in which it is located after setting the letters from key in an alphabetical order.

For example, for the key crazy we will get 23154 because of acryz (sorted letters from the key).
Let's decode cseerntiofarmit on using our crazy key.

1 2 3 4 5
---------
c s e e r
n t i o f
a r m i t
  o n   

After using the key:

2 3 1 5 4
---------
s e c r e
t i n f o
r m a t i
o n

Notes

  • The message is never shorter than the key.
  • Don't forget to remove trailing whitespace after decoding the message

Examples

deNico("crazy", "cseerntiofarmit on  ") => "secretinformation"
deNico("abc", "abcd") => "abcd"
deNico("ba", "2143658709") => "1234567890"
deNico("key", "eky") => "key" 
de_nico("crazy", "cseerntiofarmit on  "); // => "secretinformation"
de_nico("abc", "abcd"); // => "abcd"
de_nico("ba", "2143658709"); // => "1234567890"
de_nico("key", "eky"); // => "key"

Check the test cases for more examples.

Related Kata

Basic Nico - encode

Fundamentals

Stats:

CreatedJul 19, 2017
PublishedJul 19, 2017
Warriors Trained4875
Total Skips1518
Total Code Submissions19787
Total Times Completed1477
JavaScript Completions481
Clojure Completions50
PHP Completions96
Python Completions610
Ruby Completions83
Crystal Completions14
C# Completions161
D Completions2
Rust Completions26
Total Stars144
% of votes with a positive feedback rating90% of 314
Total "Very Satisfied" Votes262
Total "Somewhat Satisfied" Votes41
Total "Not Satisfied" Votes11
Total Rank Assessments9
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • dcieslak Avatar
  • GiacomoSorbi Avatar
  • donaldsebleung Avatar
  • jbristow Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • akar-0 Avatar
  • saudiGuy Avatar
Ad