-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
143 lines (107 loc) · 3.58 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
include "vendor/autoload.php";
$sandBoxFactory = new \SandboxRE\Factory\SandboxFactory();
$phpSandBox = $sandBoxFactory->make("php");
$javascriptSandBox = $sandBoxFactory->make("javascript");
$objectiveCSandBox = $sandBoxFactory->make("objectiveC");
$javaSandBox = $sandBoxFactory->make("java");
echo $javaSandBox->execute('
public class Main
{
public static void main(String[] args) {
System.out.println(\'Hello World!\');
}
}
') . PHP_EOL;
echo $objectiveCSandBox->execute('
#import <Foundation/Foundation.h>
int main ()
{
printf("%d\n", 10);
return 0;
}
') . PHP_EOL;
echo $objectiveCSandBox->execute('
#import <Foundation/Foundation.h>
@interface SampleClass:NSObject
/* method declaration */
- (int)max:(int)num1 andNum2:(int)num2;
@end
@implementation SampleClass
/* method returning the max between two numbers */
- (int)max:(int)num1 andNum2:(int)num2{
/* local variable declaration */
int result;
if (num1 > num2)
{
result = num1;
}
else
{
result = num2;
}
return result;
}
@end
int main ()
{
/* local variable definition */
int a = 300;
int b = 500;
int ret;
SampleClass *sampleClass = [[SampleClass alloc]init];
/* calling a method to get max value */
ret = [sampleClass max:a andNum2:b];
printf("%d\n", ret );
return 0;
}
') . PHP_EOL;
echo $javascriptSandBox->execute('
calculate(120, 130, [15, 17, 18, 18, 19]);
function calculate(k, jump, styles) {
var distDifference = jump - k;
var startPoints = 60;
var distPoints = distDifference > 0 ? (startPoints + 2 * distDifference) : (startPoints + distDifference);
var max = Math.max(...styles);
var min = Math.min(...styles);
styles.splice(styles.indexOf(max), 1);
styles.splice(styles.indexOf(min), 1);
var stylesSum = 0;
for (var i = 0; i < styles.length; i++) {
stylesSum += styles[i];
}
return stylesSum + distPoints;
}
') . PHP_EOL;
echo $phpSandBox->execute('
function mostlyUsed($numbers)
{
$operatorsCount = [
"Operator A" => 0,
"Operator B" => 0,
"Operator C" => 0
];
foreach ($numbers as $number) {
if( in_array($number[0].$number[1].$number[2], ["070", "071", "072"])) {
$operatorsCount["Operator A"]++;
continue;
}
if( in_array($number[0].$number[1].$number[2], ["075", "076"])) {
$operatorsCount["Operator B"]++;
continue;
}
if( in_array($number[0].$number[1].$number[2], ["077", "078"])) {
$operatorsCount["Operator C"]++;
continue;
}
}
return array_keys($operatorsCount, max($operatorsCount))[0];
}
echo mostlyUsed(["071222-333", "077111-222", "072123-123", "075321-321"]); // Operator A
'). PHP_EOL;
echo $phpSandBox->execute('
function add($a, $b) {
return $a + $b;
}
echo add(10, 5);
'). PHP_EOL;