Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Write the same algorithm in C++ as shown in this Tcl implementation.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Generate an equivalent C++ version of this Tcl code.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Transform the following Tcl implementation into Python, maintaining the same output and logic.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Change the programming language of this snippet from Tcl to Python without modifying what it does.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Write the same algorithm in Go as shown in this Tcl implementation.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Ensure the translated Go code behaves exactly like the original Tcl snippet.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Rewrite the snippet below in PHP so it works the same as the original Rust code.
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Change the following Rust code into PHP without altering its purpose.
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Maintain the same structure and functionality when rewriting this code in PHP.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Produce a language-to-language conversion: from Ada to PHP, same semantics.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert the following code from Arturo to PHP, ensuring the logic remains intact.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Please provide an equivalent version of this Arturo code in PHP.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Keep all operations the same but rewrite the snippet in PHP.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Please provide an equivalent version of this AutoHotKey code in PHP.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert this BBC_Basic snippet to PHP and keep its semantics consistent.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Keep all operations the same but rewrite the snippet in PHP.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert this Common_Lisp snippet to PHP and keep its semantics consistent.
(defun sha1-hash (data) (let ((sha1 (ironclad:make-digest 'ironclad:sha1)) (bin-data (ironclad:ascii-string-to-byte-array data))) (ironclad:update-digest sha1 bin-data) (ironclad:byte-array-to-hex-string (ironclad:produce-digest sha1))))
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Generate an equivalent PHP version of this Common_Lisp code.
(defun sha1-hash (data) (let ((sha1 (ironclad:make-digest 'ironclad:sha1)) (bin-data (ironclad:ascii-string-to-byte-array data))) (ironclad:update-digest sha1 bin-data) (ironclad:byte-array-to-hex-string (ironclad:produce-digest sha1))))
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Port the provided D code into PHP while preserving the original functionality.
void main() { import std.stdio, std.digest.sha; writefln("%-(%02x%)", "Ars longa, vita brevis".sha1Of); }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert this D snippet to PHP and keep its semantics consistent.
void main() { import std.stdio, std.digest.sha; writefln("%-(%02x%)", "Ars longa, vita brevis".sha1Of); }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Change the following Delphi code into PHP without altering its purpose.
program Sha_1; uses System.SysUtils, DCPsha1; function SHA1(const Str: string): string; var HashDigest: array of byte; d: Byte; begin Result := ''; with TDCP_sha1.Create(nil) do begin Init; UpdateStr(Str); SetLength(HashDigest, GetHashSize div 8); final(HashDigest[0]); for d in Has...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Please provide an equivalent version of this Delphi code in PHP.
program Sha_1; uses System.SysUtils, DCPsha1; function SHA1(const Str: string): string; var HashDigest: array of byte; d: Byte; begin Result := ''; with TDCP_sha1.Create(nil) do begin Init; UpdateStr(Str); SetLength(HashDigest, GetHashSize div 8); final(HashDigest[0]); for d in Has...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Change the programming language of this snippet from Elixir to PHP without modifying what it does.
iex(1)> :crypto.hash(:sha, "A string") <<110, 185, 174, 8, 151, 66, 9, 104, 174, 225, 10, 43, 9, 92, 82, 190, 197, 150, 224, 92>>
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert the following code from Elixir to PHP, ensuring the logic remains intact.
iex(1)> :crypto.hash(:sha, "A string") <<110, 185, 174, 8, 151, 66, 9, 104, 174, 225, 10, 43, 9, 92, 82, 190, 197, 150, 224, 92>>
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Translate this program into PHP but keep the logic exactly as in F#.
let n = System.Security.Cryptography.SHA1.Create() Array.iter (printf "%x ") (n.ComputeHash "Rosetta Code"B)
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Change the programming language of this snippet from F# to PHP without modifying what it does.
let n = System.Security.Cryptography.SHA1.Create() Array.iter (printf "%x ") (n.ComputeHash "Rosetta Code"B)
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Please provide an equivalent version of this Fortran code in PHP.
module sha1_mod use kernel32 use advapi32 implicit none integer, parameter :: SHA1LEN = 20 contains subroutine sha1hash(name, hash, dwStatus, filesize) implicit none character(*) :: name integer, parameter :: BUFLEN = 32768 integer(HANDLE) :: hFile, hProv, hHash ...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Port the following code from Fortran to PHP with equivalent syntax and logic.
module sha1_mod use kernel32 use advapi32 implicit none integer, parameter :: SHA1LEN = 20 contains subroutine sha1hash(name, hash, dwStatus, filesize) implicit none character(*) :: name integer, parameter :: BUFLEN = 32768 integer(HANDLE) :: hFile, hProv, hHash ...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert this Haskell snippet to PHP and keep its semantics consistent.
module Digestor where import Data.Digest.Pure.SHA import qualified Data.ByteString.Lazy as B convertString :: String -> B.ByteString convertString phrase = B.pack $ map ( fromIntegral . fromEnum ) phrase convertToSHA1 :: String -> String convertToSHA1 word = showDigest $ sha1 $ convertString word main = do p...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Write the same algorithm in PHP as shown in this Haskell implementation.
module Digestor where import Data.Digest.Pure.SHA import qualified Data.ByteString.Lazy as B convertString :: String -> B.ByteString convertString phrase = B.pack $ map ( fromIntegral . fromEnum ) phrase convertToSHA1 :: String -> String convertToSHA1 word = showDigest $ sha1 $ convertString word main = do p...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Change the following J code into PHP without altering its purpose.
require '~addons/ide/qt/qt.ijs' getsha1=: 'sha1'&gethash_jqtide_ getsha1 'Rosetta Code' 48c98f7e5a6e736d790ab740dfc3f51a61abe2b5
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Port the following code from J to PHP with equivalent syntax and logic.
require '~addons/ide/qt/qt.ijs' getsha1=: 'sha1'&gethash_jqtide_ getsha1 'Rosetta Code' 48c98f7e5a6e736d790ab740dfc3f51a61abe2b5
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Preserve the algorithm and functionality while converting the code from Julia to PHP.
using Nettle testdict = Dict("abc" => "a9993e364706816aba3e25717850c26c9cd0d89d", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" => "84983e441c3bd26ebaae4aa1f95129e5e54670f1", "a" ^ 1_000_000 => "34aa973cd4c4daa4f61eeb2bdbad27316534016f",) for (text, exp...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert the following code from Julia to PHP, ensuring the logic remains intact.
using Nettle testdict = Dict("abc" => "a9993e364706816aba3e25717850c26c9cd0d89d", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" => "84983e441c3bd26ebaae4aa1f95129e5e54670f1", "a" ^ 1_000_000 => "34aa973cd4c4daa4f61eeb2bdbad27316534016f",) for (text, exp...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Port the provided Lua code into PHP while preserving the original functionality.
#!/usr/bin/lua local sha1 = require "sha1" for i, str in ipairs{"Rosetta code", "Rosetta Code"} do print(string.format("SHA-1(%q) = %s", str, sha1(str))) end
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Write a version of this Lua function in PHP with identical behavior.
#!/usr/bin/lua local sha1 = require "sha1" for i, str in ipairs{"Rosetta code", "Rosetta Code"} do print(string.format("SHA-1(%q) = %s", str, sha1(str))) end
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Port the provided Nim code into PHP while preserving the original functionality.
import std/sha1 echo secureHash("Rosetta Code")
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Please provide an equivalent version of this Nim code in PHP.
import std/sha1 echo secureHash("Rosetta Code")
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Write the same algorithm in PHP as shown in this OCaml implementation.
$ ocaml -I +sha sha1.cma Objective Caml version 3.12.1 # Sha1.to_hex (Sha1.string "Rosetta Code") ;; - : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Rewrite the snippet below in PHP so it works the same as the original OCaml code.
$ ocaml -I +sha sha1.cma Objective Caml version 3.12.1 # Sha1.to_hex (Sha1.string "Rosetta Code") ;; - : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Maintain the same structure and functionality when rewriting this code in PHP.
program RosettaSha1; uses sha1; var d: TSHA1Digest; begin d:=SHA1String('Rosetta Code'); WriteLn(SHA1Print(d)); end.
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert the following code from Pascal to PHP, ensuring the logic remains intact.
program RosettaSha1; uses sha1; var d: TSHA1Digest; begin d:=SHA1String('Rosetta Code'); WriteLn(SHA1Print(d)); end.
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Maintain the same structure and functionality when rewriting this code in PHP.
use Digest::SHA qw(sha1_hex); print sha1_hex('Rosetta Code'), "\n";
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Rewrite this program in PHP while keeping its functionality equivalent to the Perl version.
use Digest::SHA qw(sha1_hex); print sha1_hex('Rosetta Code'), "\n";
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Write a version of this PowerShell function in PHP with identical behavior.
Function Calculate-SHA1( $String ){ $Enc = [system.Text.Encoding]::UTF8 $Data = $enc.GetBytes($String) $Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider $Result = $sha.ComputeHash($Data) [System.Convert]::ToBase64String($Result) }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert the following code from PowerShell to PHP, ensuring the logic remains intact.
Function Calculate-SHA1( $String ){ $Enc = [system.Text.Encoding]::UTF8 $Data = $enc.GetBytes($String) $Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider $Result = $sha.ComputeHash($Data) [System.Convert]::ToBase64String($Result) }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Write the same code in PHP as shown below in Racket.
#lang racket (require file/sha1) (sha1 (open-input-string "Rosetta Code"))
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Ensure the translated PHP code behaves exactly like the original Racket snippet.
#lang racket (require file/sha1) (sha1 (open-input-string "Rosetta Code"))
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Write a version of this REXX function in PHP with identical behavior.
options replace format comments java crossref savelog symbols binary import java.security.MessageDigest SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5') return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method SHA1(messageText, verifyCheck) public static alg...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Keep all operations the same but rewrite the snippet in PHP.
options replace format comments java crossref savelog symbols binary import java.security.MessageDigest SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5') return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method SHA1(messageText, verifyCheck) public static alg...
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Produce a functionally identical PHP code for the snippet given in Ruby.
require "openssl" puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Generate an equivalent PHP version of this Ruby code.
require "openssl" puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Produce a language-to-language conversion: from Scala to PHP, same semantics.
import java.security.MessageDigest fun main(args: Array<String>) { val text = "Rosetta Code" val bytes = text.toByteArray() val md = MessageDigest.getInstance("SHA-1") val digest = md.digest(bytes) for (byte in digest) print("%02x".format(byte)) println() }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Generate a PHP translation of this Scala snippet without changing its computational steps.
import java.security.MessageDigest fun main(args: Array<String>) { val text = "Rosetta Code" val bytes = text.toByteArray() val md = MessageDigest.getInstance("SHA-1") val digest = md.digest(bytes) for (byte in digest) print("%02x".format(byte)) println() }
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Maintain the same structure and functionality when rewriting this code in PHP.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Port the provided Tcl code into PHP while preserving the original functionality.
package require sha1 puts [sha1::sha1 "Rosetta Code"]
<?php $string = 'Rosetta Code'; echo sha1( $string ), "\n"; ?>
Convert this C snippet to Rust and keep its semantics consistent.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Write a version of this C++ function in Rust with identical behavior.
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Translate this program into Rust but keep the logic exactly as in C++.
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Write the same algorithm in Rust as shown in this C# implementation.
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Change the programming language of this snippet from C# to Rust without modifying what it does.
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Rewrite this program in Rust while keeping its functionality equivalent to the Go version.
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Maintain the same structure and functionality when rewriting this code in Rust.
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Rewrite the snippet below in Python so it works the same as the original Rust code.
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Port the provided Rust code into Python while preserving the original functionality.
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Write the same algorithm in Rust as shown in this C implementation.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
Write a version of this Ada function in C# with identical behavior.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
using System; using System.Collections.Generic; namespace SubsetSum { class Item { public Item(string word, int weight) { Word = word; Weight = weight; } public string Word { get; set; } public int Weight { get; set; } public override string ToStrin...
Generate an equivalent C# version of this Ada code.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
using System; using System.Collections.Generic; namespace SubsetSum { class Item { public Item(string word, int weight) { Word = word; Weight = weight; } public string Word { get; set; } public int Weight { get; set; } public override string ToStrin...
Can you help me rewrite this code in C instead of Ada, keeping it the same logically?
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...
Translate this program into C but keep the logic exactly as in Ada.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...
Port the provided Ada code into C++ while preserving the original functionality.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
#include <iostream> #include <vector> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::vector<std::pair<std::string, int>> items{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", ...
Produce a functionally identical C++ code for the snippet given in Ada.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
#include <iostream> #include <vector> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::vector<std::pair<std::string, int>> items{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", ...
Maintain the same structure and functionality when rewriting this code in Go.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
package main import "fmt" type ww struct { word string weight int } var input = []*ww{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {"covariate", 590}, {"departure", 952}, {"deploy", 44...
Change the programming language of this snippet from Ada to Go without modifying what it does.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
package main import "fmt" type ww struct { word string weight int } var input = []*ww{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {"covariate", 590}, {"departure", 952}, {"deploy", 44...
Keep all operations the same but rewrite the snippet in Java.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
public class SubsetSum { private static class Item { private String word; private int weight; public Item(String word, int weight) { this.word = word; this.weight = weight; } @Override public String toString() { return String.form...
Write the same code in Java as shown below in Ada.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
public class SubsetSum { private static class Item { private String word; private int weight; public Item(String word, int weight) { this.word = word; this.weight = weight; } @Override public String toString() { return String.form...
Transform the following Ada implementation into Python, maintaining the same output and logic.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
words = { "alliance": -624, "archbishop": -925, "balm": 397, "bonnet": 452, "brute": 870, "centipede": -658, "cobol": 362, "covariate": 590, "departure": 952, "deploy": 44, "diophantine": 645, "efferent": 54, "elysee": -326, "eradicate": 376, "escritoire": 856, "exorcism": -983, "fiat": 170, "filmy": -874,...
Ensure the translated Python code behaves exactly like the original Ada snippet.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure SubsetSum is function "+"(S:String) return Unbounded_String renames To_Unbounded_String; type Point is record str : Unbounded_String; num : Integer; end record; type Points is array (Natural range...
words = { "alliance": -624, "archbishop": -925, "balm": 397, "bonnet": 452, "brute": 870, "centipede": -658, "cobol": 362, "covariate": 590, "departure": 952, "deploy": 44, "diophantine": 645, "efferent": 54, "elysee": -326, "eradicate": 376, "escritoire": 856, "exorcism": -983, "fiat": 170, "filmy": -874,...
Transform the following D implementation into C, maintaining the same output and logic.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...
Keep all operations the same but rewrite the snippet in C.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...
Convert this D block to C#, preserving its control flow and logic.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
using System; using System.Collections.Generic; namespace SubsetSum { class Item { public Item(string word, int weight) { Word = word; Weight = weight; } public string Word { get; set; } public int Weight { get; set; } public override string ToStrin...
Convert this D snippet to C# and keep its semantics consistent.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
using System; using System.Collections.Generic; namespace SubsetSum { class Item { public Item(string word, int weight) { Word = word; Weight = weight; } public string Word { get; set; } public int Weight { get; set; } public override string ToStrin...
Please provide an equivalent version of this D code in C++.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
#include <iostream> #include <vector> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::vector<std::pair<std::string, int>> items{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", ...
Please provide an equivalent version of this D code in C++.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
#include <iostream> #include <vector> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::vector<std::pair<std::string, int>> items{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", ...
Translate the given D code snippet into Java without altering its behavior.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
public class SubsetSum { private static class Item { private String word; private int weight; public Item(String word, int weight) { this.word = word; this.weight = weight; } @Override public String toString() { return String.form...
Convert this D block to Python, preserving its control flow and logic.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
words = { "alliance": -624, "archbishop": -925, "balm": 397, "bonnet": 452, "brute": 870, "centipede": -658, "cobol": 362, "covariate": 590, "departure": 952, "deploy": 44, "diophantine": 645, "efferent": 54, "elysee": -326, "eradicate": 376, "escritoire": 856, "exorcism": -983, "fiat": 170, "filmy": -874,...
Produce a language-to-language conversion: from D to Python, same semantics.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
words = { "alliance": -624, "archbishop": -925, "balm": 397, "bonnet": 452, "brute": 870, "centipede": -658, "cobol": 362, "covariate": 590, "departure": 952, "deploy": 44, "diophantine": 645, "efferent": 54, "elysee": -326, "eradicate": 376, "escritoire": 856, "exorcism": -983, "fiat": 170, "filmy": -874,...
Convert this D block to Go, preserving its control flow and logic.
void main() { import std.stdio, std.algorithm, std.typecons, combinations3; alias P = tuple; immutable items = [ P("alliance", -624), P("archbishop", -915), P("balm", 397), P("bonnet", 452), P("brute", 870), P("centipede", -658), P("cobol", 362), P("covariate", 590), P("d...
package main import "fmt" type ww struct { word string weight int } var input = []*ww{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {"covariate", 590}, {"departure", 952}, {"deploy", 44...
Convert this Haskell block to C, preserving its control flow and logic.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...
Generate a C translation of this Haskell snippet without changing its computational steps.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...
Produce a functionally identical C# code for the snippet given in Haskell.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
using System; using System.Collections.Generic; namespace SubsetSum { class Item { public Item(string word, int weight) { Word = word; Weight = weight; } public string Word { get; set; } public int Weight { get; set; } public override string ToStrin...
Rewrite the snippet below in C++ so it works the same as the original Haskell code.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
#include <iostream> #include <vector> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::vector<std::pair<std::string, int>> items{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", ...
Translate the given Haskell code snippet into C++ without altering its behavior.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
#include <iostream> #include <vector> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::vector<std::pair<std::string, int>> items{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", ...
Port the provided Haskell code into Java while preserving the original functionality.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
public class SubsetSum { private static class Item { private String word; private int weight; public Item(String word, int weight) { this.word = word; this.weight = weight; } @Override public String toString() { return String.form...
Can you help me rewrite this code in Java instead of Haskell, keeping it the same logically?
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
public class SubsetSum { private static class Item { private String word; private int weight; public Item(String word, int weight) { this.word = word; this.weight = weight; } @Override public String toString() { return String.form...
Transform the following Haskell implementation into Python, maintaining the same output and logic.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
words = { "alliance": -624, "archbishop": -925, "balm": 397, "bonnet": 452, "brute": 870, "centipede": -658, "cobol": 362, "covariate": 590, "departure": 952, "deploy": 44, "diophantine": 645, "efferent": 54, "elysee": -326, "eradicate": 376, "escritoire": 856, "exorcism": -983, "fiat": 170, "filmy": -874,...
Maintain the same structure and functionality when rewriting this code in Python.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
words = { "alliance": -624, "archbishop": -925, "balm": 397, "bonnet": 452, "brute": 870, "centipede": -658, "cobol": 362, "covariate": 590, "departure": 952, "deploy": 44, "diophantine": 645, "efferent": 54, "elysee": -326, "eradicate": 376, "escritoire": 856, "exorcism": -983, "fiat": 170, "filmy": -874,...
Convert this Haskell snippet to Go and keep its semantics consistent.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
package main import "fmt" type ww struct { word string weight int } var input = []*ww{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {"covariate", 590}, {"departure", 952}, {"deploy", 44...
Translate the given Haskell code snippet into Go without altering its behavior.
combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] combinations _ [] = [] combinations k (x:xs) = map (x:) (combinations (k - 1) xs) ++ combinations k xs data W = W { word :: String, weight :: Int } solver :: [W] -> [[W]] solver it = [comb | n <- [1 .. length...
package main import "fmt" type ww struct { word string weight int } var input = []*ww{ {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {"covariate", 590}, {"departure", 952}, {"deploy", 44...
Convert this Icon block to C, preserving its control flow and logic.
link printf,lists procedure main() BruteZeroSubset(string2table( "alliance/-624/archbishop/-915/balm/397/bonnet/452/brute/870/_ centipede/-658/cobol/362/covariate/590/departure/952/deploy/44/_ diophantine/645/efferent/54/elysee/-326/eradicate/376/escritoire/856/_ ...
#include <stdio.h> #include <stdlib.h> typedef struct { char *word; int weight; } item_t; item_t items[] = { {"alliance", -624}, {"archbishop", -915}, {"balm", 397}, {"bonnet", 452}, {"brute", 870}, {"centipede", -658}, {"cobol", 362}, {...