set up jupyter notebook for R

First install anaconda whatever

https://www.continuum.io/blog/developer/jupyter-and-conda-r

 

in the command window

Once you have conda, you may install “R Essentials” into the current environment:

conda install -c r r-essentials
Bash

or create a new environment just for “R essentials”:

conda create -n my-r-env -c r r-essentials

Jupyter

Jupyter provides a great notebook interface to write your analysis and share it with your peers. Open a shell and run this command to start the Jupyter notebook interface in your browser:

jupyter notebook
Bash

Start a new R notebook:

create an R notebook with jupyter

Algorithms

Algorithms

Simple Array Sum

a='1 2 3 4 10 11'
arr = map(int,a.strip().split(' '))
print arr

#!/bin/python

import sys


n = int(raw_input().strip())
arr = map(int,raw_input().strip().split(' '))
print arr

 

Compare the Triplets

#!/bin/python

import sys


a0,a1,a2 = raw_input().strip().split(' ')
a0,a1,a2 = [int(a0),int(a1),int(a2)]
b0,b1,b2 = raw_input().strip().split(' ')
b0,b1,b2 = [int(b0),int(b1),int(b2)]

x=0;y=0

def je(m,n):
    global x,y
    if m>n:
        x+=1
    elif m<n:    
        y+=1

je(a0,b0)
je(a1,b1)
je(a2,b2)
print x,y

 

Diagonal Difference

Sample Input

3
11 2 4
4 5 6
10 8 -12

Sample Output

15

 

Explanation

The primary diagonal is:
11
5
-12

Sum across the primary diagonal: 11 + 5 – 12 = 4

The secondary diagonal is:
4
5
10
Sum across the secondary diagonal: 4 + 5 + 10 = 19
Difference: |4 – 19| = 15

#!/bin/python

import sys


n = int(raw_input().strip())
a = []
for a_i in xrange(n):
    a_temp = map(int,raw_input().strip().split(' '))
    a.append(a_temp)

l=0
r=0
for i in range(len(a)):
    l+=a[i][i]
    r+=a[::-1][i][i]
print abs(l-r)

 

 staircase

n = int(input())
for i in range(1,n+1):
 print(('#'*i).rjust(n,' '))

OR

n = int(raw_input())
for i in range(1,n+1):
    print " "*(n-i) + "#"*i

OR

#!/bin/python

import sys


n = int(raw_input().strip())

for i in range(n,0,-1):
    print ' '*(i-1)+'#'*(n-(i-1))

 

Time Conversion

#!/bin/python

import sys


time = raw_input().strip()

if time[-2:]=='PM':
    if int(time[:2])==12:
        h='12'+time[2:-2]
    else:
        h=str(int(time[:2])+12)+time[2:-2]
if time[-2:]=='AM':
    if int(time[:2])==12:
        h='00'+time[2:-2]
    else:
        h=str(int(time[:2]))+time[2:-2]
        
    
print h



#!/bin/python

from time import strptime, strftime

print strftime("%H:%M:%S", strptime(raw_input(), "%I:%M:%S%p"))

 

 Circular Array Rotation

#!/bin/python

import sys


n,k,m = raw_input().strip().split(' ')
n,k,m = [int(n),int(k),int(m)]
arr = map(int,raw_input().strip().split(' '))



k %= n
arr = arr[-k:] + arr[:-k]
for i in range(m):
    print(arr[int(input())])