You are on page 1of 10

1.

DICE CODE
Dice code in java 8

static int[] calc(int ar[],int f,int m) {


int n = ar.length;
int den = n + f,sum=0;
for(int i=0;i<n;i++) {
sum += ar[i];
}
int rhs = m * den;
int c=0,maxSum = 6 * f;
rhs -= sum;
int ans[] = {0};
if(rhs > maxSum || rhs < 0) {
return ans;
}
int chi[] = new int[f];
while(rhs!=0) {
if(rhs >= 5+f) {
chi[c] = 6;
rhs-=6;
f--;
c++;
}
else {
rhs-=(f-1);
chi[c++] = rhs;
f--;
while(f!=0) {
chi[c++] = 1;
f--;
}
break;
}
}
return chi;
}
Dice in python
2.Biggest of x

Biggest of x python code


Biggest of x python code

Biggest of x java code


3. Balloon code
Balloon code python

Balloon code python 2


4. Robot code

Robot c++ code


#include<bits/stdc++.h>
using namespace std;

unordered_map<string, bool> visited;


unordered_set<string> st;
vector<string> grid;

void dfs(int i, int j, int dir) {


int m = grid.size();
int n = grid[0].size();
if(i == m || i == -1 || j == n || j == -1) {
if(i == m) dfs(i-1, j, 2);
else if(i == -1) dfs(i+1, j, 0);
else if(j == n) dfs(i, j-1, 1);
else if(j == -1) dfs(i, j+1, 3);
return;
}
string key = to_string(i) + "_" + to_string(j) + "_" + to_string(dir);
if(visited.find(key) != visited.end()) return;

visited[key] = true;
if(grid[i][j] != 'X') {
string k = to_string(i) + "_" + to_string(j);
st.insert(k);
if(dir == 0) dfs(i, j+1, 0);
else if(dir == 1) dfs(i+1, j, 1);
else if(dir == 2) dfs(i, j-1, 2);
else if(dir == 3) dfs(i-1, j, 3);
}
else {
if(dir == 0) dfs(i, j-1, 1);
else if(dir == 1) dfs(i-1, j, 2);
else if(dir == 2) dfs(i, j+1, 3);
else if(dir == 3) dfs(i+1, j, 0);
}
return;
}

int solution (vector<string> &R) {


grid=R;
dfs(0, 0, 0);
return st.size();
}
Robot code java

You might also like