task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#sed
sed
  /^$/ b :start /^[0-9]/ b s/^/1/ :loop h /^9+([^0-9])\1+/ { s/^(9+).*/0\1/ y/09/10/ G s/^(.+)\n[0-9]+.(.*)/\1\2/ b loop } /^[0-9]*[0-8]([^0-9])\1+/ { s/^[0-9]*([0-8]).*/\1/ y/012345678/123456789/ G s/^(.)\n([0-9]*)[0-8].(.*)/\2\1\3/ b loop } /^[0-9]+9+([^0-9])\1+/ { s/^[0-9]*([0-8]9+).*/\...
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#6502_Assembly
6502 Assembly
UnpackNibbles: ; Takes accumulator as input. ; Separates a two-digit hex number into its component "nibbles." Left nibble in X, right nibble in Y.   pha  ;backup the input. and #$0F  ;chop off the left nibble. What remains is our Y. tay pla  ;restore input and #$F0  ;chop off the right nibble. Wh...
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#68000_Assembly
68000 Assembly
foo: MOVE.L D2,D0 MOVE.L D3,D1 ADD.L D1,D0 SUB.L D2,D3 MOVE.L D3,D1 RTS
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Julia
Julia
using Nettle   labels = ["\"\" (empty string)", "\"a\"", "\"abc\"", "\"message digest\"", "\"a...z\"", "\"abcdbcde...nopq\"", "\"A...Za...z0...9\"", "8 times \"1234567890\"", "1 million times \"a\""] texts = ["", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", "abcdbcdecdefde...
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"ARRAYLIB" *FLOAT 64 @% = &F0F   PRINT "Resistance = "; FNresistormesh(10, 10, 1, 1, 7, 6) " ohms" END   DEF FNresistormesh(ni%, nj%, ai%, aj%, bi%, bj%) LOCAL c%, i%, j%, k%, n%, A(), B() n% = ni% * nj% DIM A(n%-1, n%-1), B(n%-1, 0) FOR i% = 0 T...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Go
Go
package main   import ( "fmt" "reflect" )   type example struct{}   func (example) Foo() int { return 42 }   // a method to call another method by name func (e example) CallMethod(n string) int { if m := reflect.ValueOf(e).MethodByName(n); m.IsValid() { // it's known. call it. return in...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Groovy
Groovy
class MyObject { def foo() { println 'Invoked foo' } def methodMissing(String name, args) { println "Invoked missing method $name$args" } }
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#AppleScript
AppleScript
on run   unlines(map(reverseWords, |lines|("---------- Ice and Fire ------------   fire, in end will world the say Some ice. in say Some desire of tasted I've what From fire. favor who those with hold I   ... elided paragraph last ...   Frost Robert -----------------------")))   end run     -- GENERIC FUNCTIONS ---...
http://rosettacode.org/wiki/Repunit_primes
Repunit primes
Repunit is a portmanteau of the words "repetition" and "unit", with unit being "unit value"... or in laymans terms, 1. So 1, 11, 111, 1111 & 11111 are all repunits. Every standard integer base has repunits since every base has the digit 1. This task involves finding the repunits in different bases that are prime. In ...
#Sidef
Sidef
var limit = 1000   say "Repunit prime digits (up to #{limit}) in:"   for n in (2..20) { printf("Base %2d: %s\n", n, {|k| is_prime((n**k - 1) / (n-1)) }.grep(1..limit)) }
http://rosettacode.org/wiki/Repunit_primes
Repunit primes
Repunit is a portmanteau of the words "repetition" and "unit", with unit being "unit value"... or in laymans terms, 1. So 1, 11, 111, 1111 & 11111 are all repunits. Every standard integer base has repunits since every base has the digit 1. This task involves finding the repunits in different bases that are prime. In ...
#Wren
Wren
/* repunit_primes.wren */   import "./gmp" for Mpz import "./math" for Int import "./fmt" for Fmt import "./str" for Str   var limit = 2700 var primes = Int.primeSieve(limit)   for (b in 2..36) { var rPrimes = [] for (p in primes) { var s = Mpz.fromStr(Str.repeat("1", p), b) if (s.probPrime(15) ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#MUMPS
MUMPS
Rot13(in) New low,rot,up Set up="ABCDEFGHIJKLMNOPQRSTUVWXYZ" Set low="abcdefghijklmnopqrstuvwxyz" Set rot=$Extract(up,14,26)_$Extract(up,1,13) Set rot=rot_$Extract(low,14,26)_$Extract(low,1,13) Quit $Translate(in,up_low,rot)   Write $$Rot13("Hello World!") ; Uryyb Jbeyq! Write $$Rot13("ABCDEFGHIJKLMNOPQRSTUVWXYZ")...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#LOLCODE
LOLCODE
HAI 1.2 I HAS A Romunz ITZ A BUKKIT Romunz HAS A SRS 0 ITZ "M" Romunz HAS A SRS 1 ITZ "CM" Romunz HAS A SRS 2 ITZ "D" Romunz HAS A SRS 3 ITZ "CD" Romunz HAS A SRS 4 ITZ "C" Romunz HAS A SRS 5 ITZ "XC" Romunz HAS A SRS 6 ITZ "L" Romunz HAS A SRS 7 ITZ "XL" Romunz HAS A SRS 8 ITZ "X" Romunz HAS A SRS 9 ITZ "IX"...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#OCaml
OCaml
let decimal_of_roman roman = let arabic = ref 0 in let lastval = ref 0 in for i = (String.length roman) - 1 downto 0 do let n = match roman.[i] with | 'M' | 'm' -> 1000 | 'D' | 'd' -> 500 | 'C' | 'c' -> 100 | 'L' | 'l' -> 50 | 'X' | 'x' -> 10 | 'V' | 'v' -> 5 | ...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "scanstri.s7i";   const func string: letterRleEncode (in string: data) is func result var string: result is ""; local var char: code is ' '; var integer: index is 1; begin if length(data) <> 0 then code := data[1]; repeat incr(index); u...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#11l
11l
print(‘ha’ * 5)
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#8086_Assembly
8086 Assembly
mov ax,cx mov bx,dx add ax,bx sub cx,dx mov bx,cx ret
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Kotlin
Kotlin
import org.bouncycastle.crypto.digests.RIPEMD160Digest import org.bouncycastle.util.encoders.Hex import kotlin.text.Charsets.US_ASCII   fun RIPEMD160Digest.inOneGo(input : ByteArray) : ByteArray { val output = ByteArray(digestSize)   update(input, 0, input.size) doFinal(output, 0)   return output }   fu...
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#C
C
#include <stdio.h> #include <stdlib.h>   #define S 10 typedef struct { double v; int fixed; } node;   #define each(i, x) for(i = 0; i < x; i++) node **alloc2(int w, int h) { int i; node **a = calloc(1, sizeof(node*)*h + sizeof(node)*w*h); each(i, h) a[i] = i ? a[i-1] + w : (node*)(a + h); return a; }   void set_bou...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Icon_and_Unicon
Icon and Unicon
procedure DynMethod(obj,meth,arglist[]) local m   if not (type(obj) ? ( tab(find("__")), ="__state", pos(0))) then runerr(205,obj) # invalid value - not an object   if meth == ("initially"|"UndefinedMethod") then fail # avoid protected   m := obj.__m ...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Io
Io
Example := Object clone do( foo := method(writeln("this is foo")) bar := method(writeln("this is bar")) forward := method( writeln("tried to handle unknown method ",call message name) if( call hasArgs, writeln("it had arguments: ",call evalArgs) ) ) )   example := Exa...
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#Applesoft_BASIC
Applesoft BASIC
100 DATA"---------- ICE AND FIRE ------------" 110 DATA" " 120 DATA"FIRE, IN END WILL WORLD THE SAY SOME" 130 DATA"ICE. IN SAY SOME " 140 DATA"DESIRE OF TASTED I'VE WHAT FROM " 150 DATA"FIRE. FAVOR WHO THOSE WITH HOLD I " 160 DATA" ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Nanoquery
Nanoquery
def rot13(plaintext) uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" lowercase = "abcdefghijklmnopqrstuvwxyz"   cypher = "" for char in plaintext if uppercase .contains. char cypher += uppercase[uppercase[char] - 13] else if lowercase .contains. char cypher += lowercase[lowercase[char] - 13] else cypher += ...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#LotusScript
LotusScript
  Function toRoman(value) As String Dim arabic(12) As Integer Dim roman(12) As String   arabic(0) = 1000 arabic(1) = 900 arabic(2) = 500 arabic(3) = 400 arabic(4) = 100 arabic(5) = 90 arabic(6) = 50 arabic(7) = 40 arabic(8) = 10 arabic(9) = 9 arabic(10) = 5 arabic(11) = 4 arabic(12) = 1   roman(0) = "M"...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#PARI.2FGP
PARI/GP
fromRoman(s)={ my(v=Vecsmall(s),key=vector(88),cur,t=0,tmp); key[73]=1;key[86]=5;key[88]=10;key[76]=50;key[67]=100;key[68]=500;key[77]=1000; cur=key[v[1]]; for(i=2,#v, tmp=key[v[i]]; if(!cur, cur=tmp; next); if(tmp>cur, t+=tmp-cur; cur=0 , t+=cur; cur=tmp ) ); t+c...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Sidef
Sidef
func encode(str) { str.gsub(/((.)(\2*))/, {|a,b| "#{a.len}#{b}" }); }   func decode(str) { str.gsub(/(\d+)(.)/, {|a,b| b * a.to_i }); }
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#360_Assembly
360 Assembly
* Repeat a string - 19/04/2020 REPEATS CSECT USING REPEATS,R13 base register B 72(R15) skip savearea DC 17F'0' savearea SAVE (14,12) save previous context ST R13,4(R15) link backward ...
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#ACL2
ACL2
;; To return multiple values: (defun multiple-values (a b) (mv a b))   ;; To extract the values: (mv-let (x y) (multiple-values 1 2) (+ x y))
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Lasso
Lasso
  cipher_digest("Rosetta Code", -digest='RIPEMD160', -hex)  
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#C.23
C#
using System; using System.Collections.Generic;   namespace ResistorMesh { class Node { public Node(double v, int fixed_) { V = v; Fixed = fixed_; }   public double V { get; set; } public int Fixed { get; set; } }   class Program { static void ...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#J
J
example=:3 :0 doSomething_z_=: assert&0 bind 'doSomething was not implemented' doSomething__y '' )   doSomething_adhoc1_=: smoutput bind 'hello world' dSomethingElse_adhoc2_=: smoutput bind 'hello world'
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#JavaScript
JavaScript
  obj = new Proxy({}, { get : function(target, prop) { if(target[prop] === undefined) return function() { console.log('an otherwise undefined function!!'); }; else return target...
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#Arturo
Arturo
text: { ---------- Ice and Fire ------------   fire, in end will world the say Some ice. in say Some desire of tasted I've what From fire. favor who those with hold I   ... elided paragraph last ...   Frost Robert -----------------------}   reversed: map split.lines text => [join.with:" " reverse split.words &]   p...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Neko
Neko
/* ROT-13 in Neko */   /* Assume ASCII encoding */ var rotate13 = function(c) { if (c >= 65 && c <= 77) || (c >= 97 && c <= 109) c += 13 else if (c >= 78 && c <= 90) || (c >= 110 && c <= 122) c -= 13 return c }   var rot13 = function(s) { var r = $scopy(s) var len = $ssi...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Lua
Lua
romans = { {1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"}, {90, "XC"}, {50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, {5, "V"}, {4, "IV"}, {1, "I"} }   k = io.read() + 0 for _, v in ipairs(romans) do --note that this is -not- ipairs. val, let = unpack(v) while k >= val do k = k - val io.write(let)...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Perl
Perl
use 5.10.0;   { my @trans = ( [M => 1000], [CM => 900], [D => 500], [CD => 400], [C => 100], [XC => 90], [L => 50], [XL => 40], [X => 10], [IX => 9], [V => 5], [IV => 4], ...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Smalltalk
Smalltalk
|compress decompress| compress := [:string | String streamContents:[:out | |count prev|   count := 0. (string,'*') "trick to avoid final run handling in loop" inject:nil into:[:prevChar :ch | ch ~= prevChar ifTrue:[ count = 0 ifFalse:[ ...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#4DOS_Batch
4DOS Batch
gosub repeat ha 5 echo %@repeat[*,5] quit   :Repeat [String Times] do %Times% echos %String% enddo echo. return
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#Action.21
Action!
SET EndProg=*
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#Ada
Ada
  with Ada.Text_IO; use Ada.Text_IO; procedure MultiReturn is procedure SumAndDiff (x, y : Integer; sum, diff : out Integer) is begin sum := x + y; diff := x - y; end SumAndDiff; inta : Integer := 5; intb : Integer := 3; thesum, thediff : Integer; begin SumAndDiff (inta, intb, thesum, thed...
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Lua
Lua
#!/usr/bin/lua   require "crypto"   print(crypto.digest("ripemd160", "Rosetta Code"))
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#C.2B.2B
C++
#include <iomanip> #include <iostream> #include <vector>   class Node { private: double v; int fixed;   public: Node() : v(0.0), fixed(0) { // empty }   Node(double v, int fixed) : v(v), fixed(fixed) { // empty }   double getV() const { return v; }   void setV...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Julia
Julia
  function add(a, b) try a + b catch println("caught exception") a * b end end     println(add(2, 6)) println(add(1//2, 1//2)) println(add("Hello ", "world"))  
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Kotlin
Kotlin
// Kotlin JS version 1.2.0 (Firefox 43)   class C { // this method prevents a TypeError being thrown if an unknown method is called fun __noSuchMethod__(id: String, args: Array<Any>) { println("Class C does not have a method called $id") if (args.size > 0) println("which takes arguments: ${args....
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#AutoHotkey
AutoHotkey
Data := " (Join`r`n ---------- Ice and Fire ------------   fire, in end will world the say Some ice. in say Some desire of tasted I've what From fire. favor who those with hold I   ... elided paragraph last ...   Frost Robert ----------------------- )"   Loop, Parse, Data, `n, `r { Loop, Parse, A_LoopField, % A_Space...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols nobinary   parse arg fileNames   rdr = BufferedReader   do if fileNames.length > 0 then do loop n_ = 1 for fileNames.words fileName = fileNames.word(n_) rdr = BufferedReader(FileReader(File(fileName))) encipher(rdr) ...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#M4
M4
define(`roman',`ifelse(eval($1>=1000),1,`M`'roman(eval($1-1000))', `ifelse(eval($1>=900),1,`CM`'roman(eval($1-900))', `ifelse(eval($1>=500),1,`D`'roman(eval($1-500))', `ifelse(eval($1>=100),1,`C`'roman(eval($1-100))', `ifelse(eval($1>=90),1,`XC`'roman(eval($1-90))', `ifelse(eval($1>=50),1,`L`'roman(eval($1-50))', `ifel...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Phix
Phix
function romanDec(string s) constant romans = "MDCLXVI", decmls = {1000,500,100,50,10,5,1} integer n, prev = 0, res = 0 for i=length(s) to 1 by -1 do n = decmls[find(s[i],romans)] if n<prev then n = 0-n end if res += n prev = n end for -- return res ret...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#SNOBOL4
SNOBOL4
* # Encode RLE define('rle(str)c,n') :(rle_end) rle str len(1) . c :f(return) str span(c) @n = rle = rle n c :(rle) rle_end   * # Decode RLE define('elr(str)c,n') :(elr_end) elr str span('0123456789') . n len(1) . c = :f(return) elr = elr dupl(c,n) :(elr) elr_...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#6502_Assembly
6502 Assembly
CHROUT equ $FFD2  ;KERNAL call, prints the accumulator to the screen as an ascii value.   org $0801     db $0E,$08,$0A,$00,$9E,$20,$28,$32,$30,$36,$34,$29,$00,$00,$00         lda #>TestStr sta $11   lda #<TestStr sta $10     ldx #5 ;number of times to repeat   loop: jsr PrintString dex bne loop    ...
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#Agena
Agena
# define a function returning three values mv := proc() is return 1, 2, "three" end ; # mv   scope # test the mv() proc local a, b, c := mv(); print( c, b, a ) epocs
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#ALGOL_68
ALGOL 68
# example mode for returning multiple values from a procedure # MODE PAIR = STRUCT( STRING name, INT value );   # procedure returning multiple values via a structure # PROC get pair = ( INT a )PAIR: CASE a IN #1# ( "H", 0 ) , #2# ( "He", 1 ) , #3# ( "Li", 3 ) OUT ( "?", a ) ES...
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Function Prepare_RiPeMd_160 { Dim Base 0, K(5), K1(5) K(0)=0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E K1(0)=0x50A28BE6,0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000 Dim Base 0,r(80), r1(80), s(80), s1(80) r(0)=0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 r(16)=7...
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Hash["Rosetta code","RIPEMD160","HexString"]
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#D
D
import std.stdio, std.traits;   enum Node.FP differenceThreshold = 1e-40;   struct Node { alias FP = real; enum Kind : size_t { free, A, B }   FP voltage = 0.0;   /*const*/ private Kind kind = Kind.free; // Remove kindGet once kind is const. @property Kind kindGet() const pure nothrow @nogc {ret...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Lasso
Lasso
define exampletype => type { public foo() => { return 'this is foo\r' } public bar() => { return 'this is bar\r' } public _unknownTag(...) => { local(n = method_name->asString) return 'tried to handle unknown method called "'+#n+'"'+ (#rest->size ? ' with args: "'+#rest->join(',')+'"')+'\r' } }   local...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Logtalk
Logtalk
  :- object(foo).   :- public(try/0). try :- catch(bar::message, Error, handler(Error)).   handler(error(existence_error(predicate_declaration,message/0),_)) :- % handle the unknown message ...   :- end_object.  
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Lua
Lua
  local object={print=print} setmetatable(object,{__index=function(t,k)return function() print("You called the method",k)end end}) object.print("Hi") -->Hi object.hello() -->You called the method hello  
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#AWK
AWK
  # syntax: GAWK -f REVERSE_WORDS_IN_A_STRING.AWK BEGIN { text[++i] = "---------- Ice and Fire ------------" text[++i] = "" text[++i] = "fire, in end will world the say Some" text[++i] = "ice. in say Some" text[++i] = "desire of tasted I've what From" text[++i] = "fire. favor who those with hold...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#NewLISP
NewLISP
(define (rot13 str) (join (map (fn(c) (cond ((<= "A" (upper-case c) "M") (char (+ (char c) 13))) ((<= "N" (upper-case c) "Z") (char (- (char c) 13))) (true c))) (explode str))))
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Maple
Maple
> for n in [ 1666, 1990, 2008 ] do printf( "%d\t%s\n", n, convert( n, 'roman' ) ) end: 1666 MDCLXVI 1990 MCMXC 2008 MMVIII
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Phixmonti
Phixmonti
def romanDec /# s -- n #/ 0 >ps 0 >ps ( ( "M" 1000 ) ( "D" 500 ) ( "C" 100 ) ( "L" 50 ) ( "X" 10 ) ( "V" 5 ) ( "I" 1 ) )   swap upper reverse len while pop rot rot tochar getd if dup ps> < if 0 swap - endif dup ps> + >ps >ps swap ...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#SQL
SQL
  -- variable table DROP TABLE IF EXISTS var; CREATE temp TABLE var ( VALUE VARCHAR(1000) ); INSERT INTO var(VALUE) SELECT 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW';   -- select WITH recursive ints(num) AS ( SELECT 1 UNION ALL SELECT num+1 FROM ints WHERE num+1 <= LENGTH((SELECT VALUE ...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#68000_Assembly
68000 Assembly
MOVE.W #5-1,D1 RepString: LEA A3, MyString MOVE.L A3,-(SP) ;PUSH A3 JSR PrintString ;unimplemented hardware-dependent printing routine, assumed to not clobber D1 MOVE.L (SP)+,A3 ;POP A3 DBRA D1,RepString RTS ;return to basic or whatever   MyString: DC.B "ha",0 even
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#ALGOL_W
ALGOL W
begin  % example using a record type to return multiple values from a procedure % record Element ( string(2) symbol; integer atomicNumber ); reference(Element) procedure getElement( integer value n ) ; begin Element( if n < 1 then "?<" else if n > 3 then "?>" ...
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#ANSI_Standard_BASIC
ANSI Standard BASIC
100 DECLARE EXTERNAL SUB sumdiff 110 ! 120 CALL sumdiff(5, 3, sum, diff) 130 PRINT "Sum is "; sum 140 PRINT "Difference is "; diff 150 END 160 ! 170 EXTERNAL SUB sumdiff(a, b, c, d) 180 LET c = a + b 190 LET d = a - b 200 END SUB
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Nim
Nim
import nimcrypto / [ripemd, hash]   echo ripemd160.digest("Rosetta Code")
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Objeck
Objeck
  class Hash { function : Main(args : String[]) ~ Nil { in := "Rosetta Code"->ToByteArray(); hash := Encryption.Hash->RIPEMD160(in); hash->ToHexString()->PrintLine(); } }  
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#ERRE
ERRE
  PROGRAM RESISTENCE_MESH    !$BASE=1    !$DYNAMIC DIM A[0,0]   BEGIN   N=10 NN=N*N  !$DIM A[NN,NN+1]   PRINT(CHR$(12);) !CLS  ! generate matrix data NODE=0 FOR ROW=1 TO N DO FOR COL=1 TO N DO NODE=NODE+1 IF ROW>1 THEN A[NODE,NODE]=A[NODE,NODE]+1 A[NODE,NODE-N]...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#M2000_Interpreter
M2000 Interpreter
  module checkit {   Class Alfa { k=1000 module a (x, y) { Print x, y } module NoParam { Print "ok" } Function Sqr(x) { =Sqrt(x) } Function NoParam { ...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
obj[foo] = "This is foo."; obj[bar] = "This is bar."; obj[f_Symbol] := "What is " <> SymbolName[f] <> "?"; Print[obj@foo]; Print[obj@bar]; Print[obj@baz];
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#BaCon
BaCon
  PRINT REV$("---------- Ice and Fire ------------") PRINT PRINT REV$("fire, in end will world the say Some") PRINT REV$("ice. in say Some ") PRINT REV$("desire of tasted I've what From ") PRINT REV$("fire. favor who those with hold I ") PRINT PRINT REV$("... elided paragraph last ... ") ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Nim
Nim
import strutils   proc rot13(c: char): char = case toLowerAscii(c) of 'a'..'m': chr(ord(c) + 13) of 'n'..'z': chr(ord(c) - 13) else: c   for line in stdin.lines: for c in line: stdout.write rot13(c) stdout.write "\n"
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
RomanNumeral[4] RomanNumeral[99] RomanNumeral[1337] RomanNumeral[1666] RomanNumeral[6889]
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#PHP
PHP
<?php /** * @author Elad Yosifon */ $roman_to_decimal = array( 'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000, );   /** * @param $number * @return int */ function roman2decimal($number) { global $roman_to_decimal;   // breaks the string into an array of chars $digits = str_...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Standard_ML
Standard ML
fun encode str = let fun aux (sub, acc) = case Substring.getc sub of NONE => rev acc | SOME (x, sub') => let val (y, z) = Substring.splitl (fn c => c = x) sub' in aux (z, (x, Substring.size y + 1) :: acc) end in a...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#8th
8th
"ha" 5 s:* . cr
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#ARM_Assembly
ARM Assembly
foo: MOV R2,R0 MOV R3,R1 ADD R0,R2,R3 SUB R1,R2,R3 BX LR
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#Arturo
Arturo
addsub: function [x y]-> @[x+y x-y]   a: 33 b: 12   result: addsub a b   print [a "+" b "=" result\0] print [a "-" b "=" result\1]
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#PARI.2FGP
PARI/GP
#include <pari/pari.h> #include <openssl/ripemd.h>   #define HEX(x) (((x) < 10)? (x)+'0': (x)-10+'a')   GEN plug_ripemd160(char *text) { char md[RIPEMD160_DIGEST_LENGTH]; char hash[sizeof(md) * 2 + 1]; int i;   RIPEMD160((unsigned char*)text, strlen(text), (unsigned char*)md);   for (i = 0; i < sizeof(md); i...
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#Euler_Math_Toolbox
Euler Math Toolbox
  >load incidence; >{u,r}=solvePotentialX(makeRectangleX(10,10),12,68); r, 1.60899124173  
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Nim
Nim
{.experimental:"dotOperators".} from strutils import join   type Foo = object   proc qux(f:Foo) = echo "called qux"   #for nicer output func quoteStrings[T](x:T):string = (when T is string: "\"" & x & "\"" else: $x)   #dot operator catches all unmatched calls on Foo template `.()`(f:Foo,field:untyped,args:varargs[strin...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Object_Pascal
Object Pascal
  type Tanimal = class public procedure bark(); virtual; abstract; end;   implementation   var animal: Tanimal;   initialization   animal := Tanimal.Create; animal.bark(); // abstract method call exception at runtime here animal.Free;   end.  
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#Batch_File
Batch File
@echo off ::The Main Thing... cls echo. call :reverse "---------- Ice and Fire ------------" call :reverse call :reverse "fire, in end will world the say Some" call :reverse "ice. in say Some" call :reverse "desire of tasted I've what From" call :reverse "fire. favor who those with hold I" call :reverse call :reverse ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Objeck
Objeck
  bundle Default { class Rot13 { function : Main(args : String[]) ~ Nil { Rot13("nowhere ABJURER")->PrintLine(); }   function : native : Rot13(text : String) ~ String { rot := ""; each(i : text) { c := text->Get(i); if(c >= 'a' & c <= 'm' | c >= 'A' & c <= 'M') { ...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Mercury
Mercury
  :- module roman.   :- interface.   :- import_module io.   :- pred main(io::di, io::uo) is det.   :- implementation.   :- import_module char, int, list, string.   main(!IO) :- command_line_arguments(Args, !IO), filter(is_all_digits, Args, CleanArgs), foldl((pred(Arg::in, !.IO::di, !:IO::uo) is det :- ...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Picat
Picat
go => List = ["IV", "XLII", "M", "MCXI", "CMXI", "MCM", "MCMXC", "MMVIII", "MMIX", "MCDXLIV", "MDCLXVI", "MMXII"], foreach(R in List) printf("%-8s: %w\n", R, roman_decode(R)) end, ...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Swift
Swift
import Foundation   // "WWWBWW" -> [(3, W), (1, B), (2, W)] func encode(input: String) -> [(Int, Character)] { return input.characters.reduce([(Int, Character)]()) { if $0.last?.1 == $1 { var r = $0; r[r.count - 1].0++; return r } return $0 + [(1, $1)] } }   // [(3, W), (1, B), (2, W)] -> "WWWBW...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#ABAP
ABAP
  report z_repeat_string.   write repeat( val = `ha` occ = 5 ).  
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Action.21
Action!
Proc Main() byte REPEAT   REPEAT=5 Do Print("ha") REPEAT==-1 Until REPEAT=0 Do   Return
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#ATS
ATS
// #include "share/atspre_staload.hats" // (* ****** ****** *)   fun addsub ( x: int, y: int ) : (int, int) = (x+y, x-y)   (* ****** ****** *)   implement main0 () = let val (sum, diff) = addsub (33, 12) in println! ("33 + 12 = ", sum); println! ("33 - 12 = ", diff); end (* end of [main0] *)
http://rosettacode.org/wiki/Return_multiple_values
Return multiple values
Task Show how to return more than one value from a function.
#AutoHotkey
AutoHotkey
addsub(x, y) { return [x + y, x - y] }
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Perl
Perl
use Crypt::RIPEMD160; say unpack "H*", Crypt::RIPEMD160->hash("Rosetta Code");
http://rosettacode.org/wiki/RIPEMD-160
RIPEMD-160
RIPEMD-160 is another hash function; it computes a 160-bit message digest. There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160. For padding the message, RIPEMD-160 acts like MD4 (RFC 1320). Find the RIPEMD-160 message digest of a string of octets. Use the ASCII encoded string “Rosetta Cod...
#Phix
Phix
include builtins\ripemd160.e constant test = "Rosetta Code" printf(1,"\n%s => %s\n",{test,ripemd160(test)})
http://rosettacode.org/wiki/Resistor_mesh
Resistor mesh
Task Given   10×10   grid nodes   (as shown in the image)   interconnected by   1Ω   resistors as shown, find the resistance between points   A   and   B. See also   (humor, nerd sniping)   xkcd.com cartoon
#FreeBASIC
FreeBASIC
' version 01-07-2018 ' compile with: fbc -s console   #Define n 10   Dim As UInteger nn = n * n Dim As Double g(-nn To nn +1, -nn To nn +1) Dim As UInteger node, row, col   For row = 1 To n For col = 1 To n node += 1 If row > 1 Then g(node, node) += 1 g(node, node - n) = -1 ...
http://rosettacode.org/wiki/Respond_to_an_unknown_method_call
Respond to an unknown method call
Task Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions. Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defin...
#Objective-C
Objective-C
#include <Foundation/Foundation.h>   // The methods need to be declared somewhere @interface Dummy : NSObject - (void)grill; - (void)ding:(NSString *)s; @end   @interface Example : NSObject - (void)foo; - (void)bar; @end   @implementation Example - (void)foo { NSLog(@"this is foo"); }   - (void)bar { NSLog(@"this i...
http://rosettacode.org/wiki/Reverse_words_in_a_string
Reverse words in a string
Task Reverse the order of all tokens in each of a number of strings and display the result;   the order of characters within a token should not be modified. Example Hey you, Bub!   would be shown reversed as:   Bub! you, Hey Tokens are any non-space characters separated by spaces (formally, white-space);   t...
#BASIC256
BASIC256
source = freefile open (source, "m:\text.txt") textEnt$ = "" dim textSal$(size(source)*8) linea = 0   while not eof(source) textEnt$ = readline(source) linea += 1 textSal$[linea] = textEnt$ end while   for n = size(source) to 1 step -1 print textSal$[n]; next n close source
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#OCaml
OCaml
let rot13 c = match c with | 'A'..'M' | 'a'..'m' -> char_of_int (int_of_char c + 13) | 'N'..'Z' | 'n'..'z' -> char_of_int (int_of_char c - 13) | _ -> c
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Microsoft_Small_Basic
Microsoft Small Basic
  arabicNumeral = 1990 ConvertToRoman() TextWindow.WriteLine(romanNumeral) 'MCMXC arabicNumeral = 2018 ConvertToRoman() TextWindow.WriteLine(romanNumeral) 'MMXVIII arabicNumeral = 3888 ConvertToRoman() TextWindow.WriteLine(romanNumeral) 'MMMDCCCLXXXVIII   Sub ConvertToRoman weights[0] = 1000 weights[1] = 900 ...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#PicoLisp
PicoLisp
(de roman2decimal (Rom) (let L (replace (chop Rom) 'M 1000 'D 500 'C 100 'L 50 'X 10 'V 5 'I 1) (sum '((A B) (if (>= A B) A (- A))) L (cdr L)) ) )
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Tcl
Tcl
proc encode {string} { set encoding {} # use a regular expression to match runs of one character foreach {run -} [regexp -all -inline {(.)\1+|.} $string] { lappend encoding [string length $run] [string index $run 0] } return $encoding }   proc decode {encoding} { foreach {count char} $en...