Skip to content

Instantly share code, notes, and snippets.

@tenifni
tenifni / 21sticks_ver2.java
Last active August 17, 2016 20:10
[Game] 21 Sticks (with Player distinction). Rules of game: start with 21 sticks, and two players take turns either taking one or two sticks. The player who takes the last stick loses. [simplified: no mis-numbering prevention] \
import java.util.Scanner;
//Player recognizable; Wrong number protection
public class Practive{
public static void main(String[] args){
int remain = 21;
Scanner scan = new Scanner(System.in);
System.out.println("The rules of this game are simple. You start with 21 sticks, then two players take turns alternatively");
System.out.println("either taking one or two sticks. The player who takes the last stick loses.");
System.out.println();
@tenifni
tenifni / 21sticks_ver1.java
Last active August 29, 2015 14:27
[Game] 21 Sticks. Rules of game: start with 21 sticks, and two players take turns either taking one or two sticks. The player who takes the last stick loses. [simplified: no mis-numbering prevention; no player distinction]
import java.util.Scanner;
public class Practive{
public static void main(String[] args){
int remain = 21;
Scanner scan = new Scanner(System.in);
while (remain >1){
System.out.println("Take 1 or 2 sticks");
int input = scan.nextInt();
remain = remain -input;
@tenifni
tenifni / guessinggame.java
Last active August 29, 2015 14:27
[Game] Java Guessing Game. Randomly creates an integer between 1~1000. User tries to guess the number.
import java.util.Random;
import java.util.Scanner;
public class Practive{
public static void main (String[] args){
Random rand = new Random();
int numberToGuess = rand.nextInt(1000);
int numberOfTries = 0;
Scanner input = new Scanner (System.in);
int guess;
@tenifni
tenifni / musicplayer_blogspot.html
Last active August 29, 2015 14:27
Music player on Blogspot
<span style="color:#808080;"><h4><a href="http://scarlettyusj.blogspot.com/2015/01/music-benvenutowelcome-by-premio-sciacca.html">Benvenuto (Premiosciacca) </a></h4> </span>
<p>
<audio controls>
<source src="https://sites.google.com/site/indecisivefin/home/Track2.mp3?revision=1" type="audio/ogg">
<source src="https://sites.google.com/site/indecisivefin/home/Track2.mp3?revision=1" type="audio/mpeg">
</source></source></audio></p>
@tenifni
tenifni / 3WaysToReverse.java
Last active August 29, 2015 14:27
3 ways to reverse array in Java
import java.util.Arrays;
public class Practive{
public static void main (String[] args)
{
int [] array = new int[] {23,45,34,54,67,78};
System.out.println("Original array:");
System.out.println(Arrays.toString(array));
//reverse method 1:
int i =0;
while ( i< (array.length)/2){
@tenifni
tenifni / ntBufferedReader.java
Last active August 29, 2015 14:27
Note on BufferedReader and length()
import java.io.*;
public class Practive{
public static void main (String[] args){
strmanip();
}
static void strmanip(){
String name ="";
String password="";
try{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
@tenifni
tenifni / sps_arduinomaze.cpp
Last active November 28, 2016 08:04
SPS Arduino Code
//©UCLA-SPS 2016
START
{
Boolean rand1;
Boolean rand2;
Boolean rand3;
Boolean rand4;
Boolean rand5;
Boolean ip1==false;
Boolean ip2==false;
START
{
Boolean rand1;
Boolean rand2;
Boolean rand3;
Boolean rand4;
Boolean rand5;
Boolean ip1==false;
Boolean ip2==false;
Boolean ip3==false;