First 10 rows of php
| uuidstring | contentstring | content_formatstring | raw_contentstring | taskstring | analysisstring | solutionstring | teststring | full_contentstring | full_content_formatstring |
|---|---|---|---|---|---|---|---|---|---|
| 3729644e-1a96-4a8f-a3cd-a5683ed76a72 | /* Write a PHP function `computeDiff(array $fromLines, array $toLines): array` that compares two arrays of strings line-by-line and returns an array of edit operation objects. Each edit operation must be one of the following classes: `CopyOp` (with a `lines` property containing u… | code comment | <?php /** * Class used internally by Text_Diff to actually compute the diffs. * * This class is implemented using native PHP code. * * The algorithm used here is mostly lifted from the perl module * Algorithm::Diff (version 1.06) by Ned Konz, which is available at: * http:… |
| Write a PHP function `computeDiff(array $fromLines, array $toLines): array` that compares two arrays of strings line-by-line and returns an array of edit operation objects. Each edit operation must be one of the following classes: `CopyOp` (with a `lines` property containing unch… |
| The core of the solution is computing the LCS of two arrays of strings. The classic dynamic programming approach uses a 2D table where `$dp[$i][$j]` represents the length of the LCS of the first `$i` elements of `$fromLines` and the first `$j` elements of `$toLines` (0-indexed th… |
| <?php declare(strict_types=1); class CopyOp { public array $lines; public function __construct(array $lines) { $this->lines = $lines; } } class DeleteOp { public array $lines; public function __construct(array $lines) { $this->lines = $lines; } } class AddOp {… |
| function assertCondition(bool $condition): void { if (!$condition) { throw new RuntimeException('Assertion failed.'); } } // Helper to convert edit operations into a simple description for comparison. function describeEdits(array $edits): array { $result = []… |
| /* Write a PHP function `computeDiff(array $fromLines, array $toLines): array` that compares two arrays of strings line-by-line and returns an array of edit operation objects. Each edit operation must be one of the following classes: `CopyOp` (with a `lines` property containing u… |
| solution-first order |
| eb8f0e9d-426a-49aa-a89f-0569405938b2 | Create a PHP class named `FieldPoint` that represents a point on an elliptic curve in projective coordinates using three field element objects. The class must: (1) have three public properties named `X`, `Y`, and `Z`, each of type `FieldElement`; (2) accept three optional `FieldE… | markdown | <?php if (class_exists('ParagonIE_Sodium_Core32_Curve25519_Ge_P2', false)) { return; } /** * Class ParagonIE_Sodium_Core32_Curve25519_Ge_P2 */ class ParagonIE_Sodium_Core32_Curve25519_Ge_P2 { /** * @var ParagonIE_Sodium_Core32_Curve25519_Fe */ public $X;… | Create a PHP class named `FieldPoint` that represents a point on an elliptic curve in projective coordinates using three field element objects. The class must: (1) have three public properties named `X`, `Y`, and `Z`, each of type `FieldElement`; (2) accept three optional `FieldE… | The solution requires two classes. The `FieldElement` class is a minimal container: it declares a public property `$value` of type `int`, and a constructor with an optional `int $value = 0` that assigns it. The `FieldPoint` class follows the pattern from the given snippet: three … | <?php declare(strict_types=1); /** * Simple field element with an integer value. */ class FieldElement { public int $value; /** * @param int $value */ public function __construct(int $value = 0) { $this->value = $value; } } /** * Point… | function assertCondition(bool $condition): void { if (!$condition) { throw new RuntimeException('Assertion failed.'); } } // Test default construction: all three properties are new FieldElement with value 0 $p1 = new FieldPoint(); assertCondition($p1->X instanceo… | /* Create a PHP class named `FieldPoint` that represents a point on an elliptic curve in projective coordinates using three field element objects. The class must: (1) have three public properties named `X`, `Y`, and `Z`, each of type `FieldElement`; (2) accept three optional `Fie… | solution-first order |
| feb6977e-ecb6-4255-83f1-2d39f0687e91 | Write a PHP function called `reduceArray` that takes an array of integers and a string indicating the reduction operation (`'sum'`, `'product'`, or `'concat'`) as parameters, along with an optional initial value (defaulting to `0` for sum, `1` for product, and `''` for concat). T… | markdown | <?php function sum($carry, $item){ $carry += $item; return $carry; } function product($carry, $item){ $carry *= $item; return $carry; } $a = array(1,2,3,4,5); $x = array(); var_dump(array_reduce($a,"sum")); var_d… | Write a PHP function called `reduceArray` that takes an array of integers and a string indicating the reduction operation (`'sum'`, `'product'`, or `'concat'`) as parameters, along with an optional initial value (defaulting to `0` for sum, `1` for product, and `''` for concat). T… | The solution uses a simple iterative approach: we start with the initial value, then loop through each element of the array and apply the required operation to update an accumulator. For `'sum'`, we add each element to the accumulator; for `'product'`, we multiply; for `'concat'`… | <?php declare(strict_types=1); /** * Reduces an array of integers using a specified operation. * * @param array<int, int> $numbers Array of integers to reduce. * @param string $operation Operation: 'sum', 'product', or 'concat'. * @param int|string $initial Initial accumul… | function assertCondition(bool $condition): void { if (!$condition) { throw new RuntimeException('Assertion failed.'); } } // Basic sum and product assertCondition(reduceArray([1, 2, 3, 4, 5], 'sum') === 15); assertCondition(reduceArray([1, 2, 3, 4, 5], 'product',… | // Write a PHP function called `reduceArray` that takes an array of integers and a string indicating the reduction operation (`'sum'`, `'product'`, or `'concat'`) as parameters, along with an optional initial value (defaulting to `0` for sum, `1` for product, and `''` for concat)… | commented standard order |
| 9cd829ce-3dc2-420c-a9a5-f8f34c4c93c9 | /* Create a standalone PHP function that implements a simplified version of Excel's FLOOR function. The function should accept two numeric parameters: `$number` (the value to round) and `$significance` (the multiple to which rounding occurs), with `$significance` defaulting to 1 … | code comment | <?php /** PHPExcel root directory */ if (!defined('PHPEXCEL_ROOT')) { /** * @ignore */ define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); } /** * PHPExcel_Calculation_MathTrig * * Copyright (c) 20… | Create a standalone PHP function that implements a simplified version of Excel's FLOOR function. The function should accept two numeric parameters: `$number` (the value to round) and `$significance` (the multiple to which rounding occurs), with `$significance` defaulting to 1 if … | The solution approach is straightforward: first normalize the inputs by validating they are numeric using `is_numeric`, which rejects strings (though numeric strings could be allowed, the spec says non-numeric including strings, so use `is_numeric` to also reject numeric strings … | <?php declare(strict_types=1); /** * Round a number down toward zero to the nearest multiple of significance. * Returns INF for zero significance, NAN for sign mismatch or invalid input. */ function excelFloor(float|int $number, float|int $significance = 1): float { // V… | function assertCondition(bool $condition): void { if (!$condition) { throw new RuntimeException('Assertion failed.'); } } // Basic positive cases assertCondition(excelFloor(4.5, 1) === 4.0); assertCondition(excelFloor(4.5, 2) === 4.0); assertCondition(excelFloor(… | Create a standalone PHP function that implements a simplified version of Excel's FLOOR function. The function should accept two numeric parameters: `$number` (the value to round) and `$significance` (the multiple to which rounding occurs), with `$significance` defaulting to 1 if … | commented standard order |
| 769bb998-c1ab-428d-aca4-9c87debbae6f | Write a PHP function `ed25519KeypairFromSeed(string $seed): array` that takes a 32-byte binary seed string and returns an associative array with string keys `'secret_key'` and `'public_key'`. The secret key must be exactly 64 bytes long and consist of the original 32-byte seed co… | markdown | <?php if (class_exists('ParagonIE_Sodium_Core_Ed25519', false)) { return; } /** * Class ParagonIE_Sodium_Core_Ed25519 */ abstract class ParagonIE_Sodium_Core_Ed25519 extends ParagonIE_Sodium_Core_Curve25519 { const KEYPAIR_BYTES = 96; const SEED_BYTES = 32; co… | Write a PHP function `ed25519KeypairFromSeed(string $seed): array` that takes a 32-byte binary seed string and returns an associative array with string keys `'secret_key'` and `'public_key'`. The secret key must be exactly 64 bytes long and consist of the original 32-byte seed co… | The core algorithm follows the Ed25519 key generation process but with a simplified public-key derivation step to keep the task self-contained and independent of a full elliptic-curve library. The main steps are: (1) validate the seed length, (2) compute SHA-512 of the seed, (3) … | <?php declare(strict_types=1); /** * Generate an Ed25519 keypair from a 32-byte seed. * * @param string $seed Exactly 32 binary bytes. * @return array{secret_key: string, public_key: string} 64-byte secret key and 32-byte public key. * @throws RangeException If seed length… | function assertCondition(bool $condition): void { if (!$condition) { throw new RuntimeException('Assertion failed.'); } } // Test 1: Valid seed produces correct lengths $result = ed25519KeypairFromSeed(str_repeat("\x01", 32)); assertCondition(strlen($result['secr… | Write a PHP function `ed25519KeypairFromSeed(string $seed): array` that takes a 32-byte binary seed string and returns an associative array with string keys `'secret_key'` and `'public_key'`. The secret key must be exactly 64 bytes long and consist of the original 32-byte seed co… | test-first order |
| 8709704e-6415-413e-b183-4973bc868ec4 | /* Write a PHP function that parses an XML declaration string (the part that begins with `<?xml` and ends with `?>`) and extracts three attributes: `version`, `encoding`, and `standalone`. The function should accept the full declaration string (including the enclosing `<?xml ... … | code comment | <?php /** * SimplePie * * A PHP-Based RSS and Atom Feed Framework. * Takes the hard work out of managing a complete RSS/Atom solution. * * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors * All rights reserved. * * Redistribution and u… | Write a PHP function that parses an XML declaration string (the part that begins with `<?xml` and ends with `?>`) and extracts three attributes: `version`, `encoding`, and `standalone`. The function should accept the full declaration string (including the enclosing `<?xml ... ?>`… | The solution implements a deterministic finite-state machine with states corresponding to each parsing phase: before version name, version name, version equals, version value, then optionally encoding, then optionally standalone, and finally emit. The parser maintains a position … | <?php declare(strict_types=1); // Parse an XML declaration string and extract version, encoding, and standalone attributes. function parseXmlDeclaration(string $declaration): array { $data = trim($declaration); // Check for the opening <?xml and closing ?> if (… | function assertCondition(bool $condition): void { if (!$condition) { throw new RuntimeException('Assertion failed.'); } } // Test full valid declaration with all attributes $result = parseXmlDeclaration('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'); … | Write a PHP function that parses an XML declaration string (the part that begins with `<?xml` and ends with `?>`) and extracts three attributes: `version`, `encoding`, and `standalone`. The function should accept the full declaration string (including the enclosing `<?xml ... ?>`… | standard order |
| f8014ada-c363-4b3f-9fea-9b2dfffa17ba | "Write a PHP function `findSmallestHouseWithSufficientPresents(int $presentsNeeded, int $presentsPer | no fence | "<?php\n$limit = 36000000;\n\nfor ($house = 1; presents($house, 10) < $limit; $house++);\necho \"Par | "Write a PHP function `findSmallestHouseWithSufficientPresents(int $presentsNeeded, int $presentsPer | "The core problem is computing the total presents for each house in increasing order until the requi | "<?php\n\ndeclare(strict_types=1);\n\n// Find the smallest house number whose total presents meet or | "function assertCondition(bool $condition): void\n{\n if (!$condition) {\n throw new Runti | "Write a PHP function `findSmallestHouseWithSufficientPresents(int $presentsNeeded, int $presentsPer | standard order |
| a79cf527-a557-48dc-96fe-c04854fc5c51 | "/*\nWrite a PHP function `parseXmlDeclaration(string $input): array` that parses an XML declaration | code comment | "<?php\n/**\n * SimplePie\n *\n * A PHP-Based RSS and Atom Feed Framework.\n * Takes the hard work o | "Write a PHP function `parseXmlDeclaration(string $input): array` that parses an XML declaration str | "The solution uses a finite state machine with explicit states for each parsing step: initial whites | "<?php\n\ndeclare(strict_types=1);\n\n// Parse an XML declaration without surrounding delimiters, re | "function assertCondition(bool $condition): void\n{\n if (!$condition) {\n throw new Runti | "Write a PHP function `parseXmlDeclaration(string $input): array` that parses an XML declaration str | commented standard order |
| 3d72c78f-07d2-42ae-8147-926b01e76962 | "Write a PHP function called `poly1305Mac` that implements the Poly1305 one-time authenticator algor | markdown | "<?php\n\nif (class_exists('ParagonIE_Sodium_Core_Poly1305_State', false)) {\n return;\n}\n\n/**\ | "Write a PHP function called `poly1305Mac` that implements the Poly1305 one-time authenticator algor | "The Poly1305 algorithm processes a message in 16-byte blocks. The key is split into two parts: the | "<?php\n\ndeclare(strict_types=1);\n\n/**\n * Compute the Poly1305 MAC for a message using a 32-byte | "function assertCondition(bool $condition): void\n{\n if (!$condition) {\n throw new Runti | "// Write a PHP function called `poly1305Mac` that implements the Poly1305 one-time authenticator al | test-first order |
| b9298f1d-372e-4eaf-9cae-9d479825c2fe | "/*\nCreate a PHP function that implements BLAKE2b initialization and finalization without the full | code comment | "<?php\n\nif (class_exists('ParagonIE_Sodium_Core_BLAKE2b', false)) {\n return;\n}\n\n/**\n * Cla | "Create a PHP function that implements BLAKE2b initialization and finalization without the full comp | "The solution implements a simplified BLAKE2b that focuses on the initialization, update, and finali | "<?php\n\ndeclare(strict_types=1);\n\n// Initialize BLAKE2b state and process input to produce a has | "function assertCondition(bool $condition): void\n{\n if (!$condition) {\n throw new Runti | "/*\nCreate a PHP function that implements BLAKE2b initialization and finalization without the full | solution-first order |