How to fix ‘sudo: no tty present and no askpass program specified’ error?

  1. Use NOPASSWD line for all commands, I mean:
    jenkins ALL=(ALL) NOPASSWD: ALL
    
  2. Put the line after all other lines in the sudoers file.

Adventures in Elm

2017-03-19 11_30_53-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_32_58-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_33_50-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_34_13-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_35_14-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_36_25-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_37_32-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_38_15-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_40_16-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_43_29-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_43_59-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_44_31-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player

2017-03-19 11_47_45-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_45_39-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 11_48_41-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player

2017-03-19 11_49_16-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player

You can write your first elm code online here: http://elm-lang.org/examples/hello-html

Your first hello word code will look like this:

import Html 

main =
 Html.text "Hello, World!!"

Your index.html  will look like this:

Hello, World!!

You can also div as follows:

import Html 

main =
 Html.div [] [
 Html.text "Hello, World!!"]

Output will remain the same, but if you inspect the webpage, you can see the following in the source code:

2017-03-19 12_04_08-example_hello-html.png

You can convert your html code to elm here: https://mbylstra.github.io/html-to-elm/

2017-03-19 12_08_33-Photos.png

You can also add a view function

import Html 

main = view

view : Html.Html Never
view = 
 Html.div [] [
 Html.text "Hello, World!!"]

Your output will remain the same.

If you want to output your mouse position your code will look like:

import Html 
import Mouse
import Programmator

main : Program {}
main = {

init = { x=0, y=0 },
input = Mouse.moves,
view = view
} |> Programmator.viewFromOneInput

view : Mouse.Position -> Html.Html Mouse.Position
view { x , y }= 
 Html.div [] [
 Html.text ("x= "++ (toString x) ++ ", y= " ++ (toString y))]

 

2017-03-19 12_40_06-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 12_40_17-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player2017-03-19 12_40_47-GOTO2016•Advent-Download-From-YTPak.com.mp4 - VLC media player

Java 8 coding challenge : Jarvis and Seven Segments

All over the world, peoples are working on energy solution. It would be a tough time for our next generation to survive if we don’t think about solution. Tony stark is working on a new project and wants to display his project using “seven segment display – concept”. Tony Stark gave Jarvis a task to find a number from his Favorite list of number for which the energy consumption is lowest.

(Assuming that for a digit to represent Tony stark is using 7 bulbs and only those bulbs light up which are required to represent a number and rest other would be completely off.)

Help Jarvis and conserve energy.

Seven segment display – https://en.wikipedia.org/wiki/Seven-segment_display

enter image description here

Input:
First line will contain the number of test cases and for every test case first line will contain length of favorite list and the second line for a test case will contain n numbers

Output:
For every test case print the answer. If there exist more than 1 numbers for which same number of bulbs are required than output the number which occurs first in the Favorite list.

Constraints:
Test cases< 10
A[i] < 10^6
Size of list < 10^5

SAMPLE INPUT
1
5
1 2 3 4 5
SAMPLE OUTPUT
1
Explanation

Number 1 needs only two bulbs to represent.

Code:

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
 
 
 
 
public class Solution {
 
 
 public static void main(String args[]) throws IOException{
 InputReader in=new InputReader(System.in);
 PrintWriter out=new PrintWriter(System.out);
 int T=in.readInt();
 
 while(T-->0){
 long N=in.readLong();
 long min=222222222;
 long minnum=0;
 while(N-->0){
 long num=in.readCount();
 long count=in.getcount();
 if(count<min){
 min=count;
 minnum=num;
 }
 }
 out.println(minnum);
 out.flush();
 
 }
 
 out.close();
 
 }
}
 
class InputReader{
 InputStream in;
 int[] segment={6,2,5,5,4,5,6,3,7,6};
 long count=0;
 InputReader(InputStream in){
 this.in=in;
 }
 
 public long getcount(){
 return count;
 }
 private int read() throws IOException{
 return in.read();
 }
 
 
 
 public char readChar() throws IOException{
 int n=read();
 while(isWhiteSpace(n)){
 n=read();
 }
 return (char)n;
 }
 
 public int readInt() throws IOException{
 int number=0;
 int n=read();
 while(isWhiteSpace(n)){
 n=read();
 }
 while(!isWhiteSpace(n)){
 int integer=n-'0';
 number*=10;
 number+=integer;
 n=read();
 }
 return number;
 }
 
 public long readCount() throws IOException{
 long number=0;
 count=0;
 int n=read();
 while(isWhiteSpace(n)){
 n=read();
 }
 while(!isWhiteSpace(n)){
 int integer=n-'0';
 count+=segment[integer];
 number*=10;
 number+=integer;
 n=read();
 }
 return number;
 }
 
 
 public long readLong() throws IOException{
 long number=0;
 int n=read();
 while(isWhiteSpace(n)){
 n=read();
 }
 while(!isWhiteSpace(n)){
 int integer=n-'0';
 number*=10;
 number+=integer;
 n=read();
 }
 return number;
 }
 
 private boolean isWhiteSpace(int n){
 if(n=='\n'||n=='\r'||n=='\t'||n==' '||n==-1){
 return true;
 }else{
 return false;
 }
 
 }
 }

Java 8 coding challenge: Addition ain’t simple

Jack is awesome. His friends call him little Einstein. To test him, his friends gave him a string. They told him to add the string with its reverse string and follow these rules:

  1. Every ith character of string will be added to every ith character of reverse string.
  2. Both string will contain only lower case alphabets(a-z).
  3. Eg:- a+a=b,a+c=d,z+a=a (Refer to sample test cases for more details)

Input:

First line contains a value N denoting number of test cases. Next N lines contains string str.

Output:

For every string str output the string that Jack’s friends wants from him.

Constraints

1 <= N <= 10

1 <= str <= 10^5

SAMPLE INPUT
4
hello
codeapocalypse
programming
world
SAMPLE OUTPUT
wqxqw
hhtdmqrrqmdthh
wfxtebetxfw
aajaa

Code:

import java.io.*;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
 

public class AdditionAintSimple {
 static class Print {
 private final BufferedWriter bw;
 
 public Print() {
 this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
 }
 
 public void print(Object object) throws IOException {
 bw.append("" + object);
 }
 
 public void println(Object object) throws IOException {
 print(object);
 bw.append("\n");
 }
 
 public void close() throws IOException {
 bw.close();
 }
 }
 
 static class Reader
 {
 final private int BUFFER_SIZE = 1 << 16;
 private DataInputStream din;
 private byte[] buffer;
 private int bufferPointer, bytesRead;
 
 public Reader()
 {
 din = new DataInputStream(System.in);
 buffer = new byte[BUFFER_SIZE];
 bufferPointer = bytesRead = 0;
 }
 
 public Reader(String file_name) throws IOException
 {
 din = new DataInputStream(new FileInputStream(file_name));
 buffer = new byte[BUFFER_SIZE];
 bufferPointer = bytesRead = 0;
 }
 
 public String readLine() throws IOException
 {
 byte[] buf = new byte[100000]; // line length
 int cnt = 0, c;
 while ((c = read()) != -1)
 {
 if (c == '\n')
 break;
 buf[cnt++] = (byte) c;
 }
 return new String(buf, 0, cnt);
 }
 
 public int nextInt() throws IOException
 {
 int ret = 0;
 byte c = read();
 while (c <= ' ')
 c = read();
 boolean neg = (c == '-');
 if (neg)
 c = read();
 do
 {
 ret = ret * 10 + c - '0';
 } while ((c = read()) >= '0' && c <= '9');
 
 if (neg)
 return -ret;
 return ret;
 }
 
 public long nextLong() throws IOException
 {
 long ret = 0;
 byte c = read();
 while (c <= ' ')
 c = read();
 boolean neg = (c == '-');
 if (neg)
 c = read();
 do {
 ret = ret * 10 + c - '0';
 }
 while ((c = read()) >= '0' && c <= '9');
 if (neg)
 return -ret;
 return ret;
 }
 
 public double nextDouble() throws IOException
 {
 double ret = 0, div = 1;
 byte c = read();
 while (c <= ' ')
 c = read();
 boolean neg = (c == '-');
 if (neg)
 c = read();
 
 do {
 ret = ret * 10 + c - '0';
 }
 while ((c = read()) >= '0' && c <= '9');
 
 if (c == '.')
 {
 while ((c = read()) >= '0' && c <= '9')
 {
 ret += (c - '0') / (div *= 10);
 }
 }
 
 if (neg)
 return -ret;
 return ret;
 }
 
 private void fillBuffer() throws IOException
 {
 bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
 if (bytesRead == -1)
 buffer[0] = -1;
 }
 
 private byte read() throws IOException
 {
 if (bufferPointer == bytesRead)
 fillBuffer();
 return buffer[bufferPointer++];
 }
 
 public void close() throws IOException
 {
 if (din == null)
 return;
 din.close();
 }
 }
 
 public static void main(String[] args) throws Exception{
 Reader rd = new Reader();
 Print pr = new Print();
 
 int t = rd.nextInt();
 String ip;
 
 
 int len;
 
 while(t-->0) {
 ip = rd.readLine();
 len = ip.length();
 char op[] = new char[len];
 
 for (int i = 0; i < len; i++) {
 op[i] = (char) ((( ip.charAt(i) + ip.charAt(len - i - 1) - 193) % 26)+97);
 }
 pr.println(String.valueOf(op));
 }
 pr.close();
 }
}

Java 8 Coding challenge: Factorial!

Problem:

You have been given a positive integer N. You need to find and print the Factorial of this number. The Factorial of a positive integer N refers to the product of all number in the range from 1 to N.

Input Format:
The first and only line of the input contains a single integer N denoting the number whose factorial you need to find.

Output Format
Output a single line denoting the factorial of the number N.

Constraints
1≤N≤101≤N≤10
SAMPLE INPUT
2
SAMPLE OUTPUT
2

Code:

import java.util.*;
 
 
class TestClass {
 public static void main(String args[] ) throws Exception {
 
 try (Scanner input = new Scanner(System.in)) {
 
 int fatorial = input.nextInt();
 
 int total=fatorial;
 
 for(int i=fatorial-1;i>=1;i--){
 total = total * i;
 }
 
 System.out.println(total);
 
 
 } catch (Throwable e) {
 e.printStackTrace();
 }
 
 }
}

 

Java

A one-dimensional array is, essentially, a list of like-typed variables. To create an array, you first
must create an array variable of the desired type. The general form of a one-dimensional
array declaration is
type var-name[ ];
Here, type declares the element type (also called the base type) of the array.

Although this declaration establishes the fact that month_days is an array variable, no
array actually exists. To link month_days with an actual, physical array of integers, you must
allocate one using new and assign it to month_days. new is a special operator that allocates
memory.
You will look more closely at new in a later chapter, but you need to use it now to
allocate memory for arrays. The general form of new as it applies to one-dimensional
arrays appears as follows:
array-var = new type [size];

The elements
in the array allocated by new will automatically be initialized to zero (for numeric types), false
(for boolean), or null (for reference types, which are described in a later chapter).

Let’s review: Obtaining an array is a two-step process. First, you must declare a variable
of the desired array type. Second, you must allocate the memory that will hold the array,
using new, and assign it to the array variable. Thus, in Java all arrays are dynamically
allocated.

int month_days[] = new int[12];

int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int twoD[][] = new int[4][];
twoD[0] = new int[5];
twoD[1] = new int[5];
twoD[2] = new int[5];
twoD[3] = new int[5];

//differing 2nd dimension

int twoD[][] = new int[4][];
twoD[0] = new int[1];
twoD[1] = new int[2];
twoD[2] = new int[3];
twoD[3] = new int[4];

double m[][] = {
{ 0*0, 1*0, 2*0, 3*0 },
{ 0*1, 1*1, 2*1, 3*1 },
{ 0*2, 1*2, 2*2, 3*2 },
{ 0*3, 1*3, 2*3, 3*3 }};

For example, the following two declarations are equivalent:
int al[] = new int[3];
int[] a2 = new int[3];
The following declarations are also equivalent:
char twod1[][] = new char[3][4];
char[][] twod2 = new char[3][4];

The reason for this is simple: Java does not support or allow pointers. (Or more properly, Java
does not support pointers that can be accessed and/or modified by the programmer.) Java
cannot allow pointers, because doing so would allow Java programs to breach the firewall
between the Java execution environment and the host computer. (Remember, a pointer can
be given any address in memory—even addresses that might be outside the Java run-time
system.) Since C/C++ make extensive use of pointers, you might be thinking that their loss
is a significant disadvantage to Java. However, this is not true. Java is designed in such a way
that as long as you stay within the confines of the execution environment, you will never
need to use a pointer, nor would there be any benefit in using one.

var op= expression;
The compound assignment operators provide two benefits. First, they save you a bit
of typing, because they are “shorthand” for their equivalent long forms. Second, in some
cases they are more efficient than are their equivalent long forms. For these reasons, you
will often see the compound assignment operators used in professionally written Java
programs.

These operators are unique in that they can appear both in postfix form, where they
follow the operand as just shown, and prefix form, where they precede the operand. In the
foregoing examples, there is no difference between the prefix and postfix forms. However,
when the increment and/or decrement operators are part of a larger expression, then a
subtle, yet powerful, difference between these two forms appears. In the prefix form,
the operand is incremented or decremented before the value is obtained for use in the
expression. In postfix form, the previous value is obtained for use in the expression, and
then the operand is modified. For example:
x = 42;
y = ++x;
In this case, y is set to 43 as you would expect, because the increment occurs before x is
assigned to y. Thus, the line y = ++x; is the equivalent of these two statements:
x = x + 1;
y = x;
However, when written like this,
x = 42;
y = x++;
the value of x is obtained before the increment operator is executed, so the value of y is 42.
Of course, in both cases x is set to 43. Here, the line y = x++; is the equivalent of these two
statements:
y = x;
x = x + 1;

Operator Result
~ Bitwise unary NOT
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
>> Shift right
>>> Shift right zero fill
<< Shift left
&= Bitwise AND assignment
|= Bitwise OR assignment
^= Bitwise exclusive OR assignment
>>= Shift right assignment
>>>= Shift right zero fill assignment
<<= Shift left assignment

All of the integer types (except char) are signed integers. This means that they can
represent negative values as well as positive ones. Java uses an encoding known as two’s
complement, which means that negative numbers are represented by inverting (changing 1’s
to 0’s and vice versa) all of the bits in a value, then adding 1 to the result. For example, –42
is represented by inverting all of the bits in 42, or 00101010, which yields 11010101, then
adding 1, which results in 11010110, or –42. To decode a negative number, first invert all of the bits, then add 1. For example, –42, or 11010110 inverted, yields 00101001, or 41, so
when you add 1 you get 42.

Because Java uses two’s complement to store negative numbers—and because all
integers are signed values in Java—applying the bitwise operators can easily produce
unexpected results. For example, turning on the high-order bit will cause the resulting
value to be interpreted as a negative number, whether this is what you intended or not. To
avoid unpleasant surprises, just remember that the high-order bit determines the sign of an
integer no matter how that high-order bit gets set.

The XOR operator, ^, combines bits such that if exactly one operand is 1, then the result
is 1.

The left shift operator, <<, shifts all of the bits in a value to the left a specified number of
times. It has this general form:
value << num
Here, num specifies the number of positions to left-shift the value in value. That is, the
<< moves all of the bits in the specified value to the left by the number of bit positions
specified by num. For each shift left, the high-order bit is shifted out (and lost), and a zero
is brought in on the right. This means that when a left shift is applied to an int operand,
bits are lost once they are shifted past bit position 31. If the operand is a long, then bits are
lost after bit position 63.
Java’s automatic type promotions produce unexpected results when you are shifting
byte and short values. As you know, byte and short values are promoted to int when an
expression is evaluated. Furthermore, the result of such an expression is also an int. This
means that the outcome of a left shift on a byte or short value will be an int, and the bits
shifted left will not be lost until they shift past bit position 31. Furthermore, a negative byte
or short value will be sign-extended when it is promoted to int. Thus, the high-order bits
will be filled with 1’s. For these reasons, to perform a left shift on a byte or short implies
that you must discard the high-order bytes of the int result. For example, if you left-shift a
byte value, that value will first be promoted to int and then shifted. This means that you
must discard the top three bytes of the result if what you want is the result of a shifted byte
value. The easiest way to do this is to simply cast the result back into a byte.

The right shift operator, >>, shifts all of the bits in a value to the right a specified number of
times. Its general form is shown here:
value >> num
Here, num specifies the number of positions to right-shift the value in value. That is, the >>
moves all of the bits in the specified value to the right the number of bit positions specified
by num.

Java

Here is an example of the way that the ? is employed:
ratio = denom == 0 ? 0 : num / denom;
When Java evaluates this assignment expression, it first looks at the expression to the left of
the question mark. If denom equals zero, then the expression between the question mark
and the colon is evaluated and used as the value of the entire ? expression. If denom does
not equal zero, then the expression after the colon is evaluated and used for the value of the
entire ? expression. The result produced by the ? operator is then assigned to ratio.

The switch statement works like this: The value of the expression is compared with each of
the values in the case statements. If a match is found, the code sequence following that case
statement is executed. If none of the constants matches the value of the expression, then the
default statement is executed. However, the default statement is optional. If no case matches
and no default is present, then no further action is taken.
The break statement is used inside the switch to terminate a statement sequence. When a
break statement is encountered, execution branches to the first line of code that follows the
entire switch statement. This has the effect of “jumping out” of the switch.

class MissingBreak {
public static void main(String args[]) {
for(int i=0; i<12; i++)
switch(i) {
case 0:
case 1:
case 2:
case 3:
case 4:
System.out.println(“i is less than 5”);
break;
case 5:
case 6:
case 7:
case 8:
case 9:
System.out.println(“i is less than 10”);
break;
default:
System.out.println(“i is 10 or more”);
}
}
}

switch(count) {
case 1:
switch(target) { // nested switch
case 0:
System.out.println(“target is zero”);
break;
case 1: // no conflicts with outer switch
System.out.println(“target is one”);
break;
}
break;