Skip to content

Instantly share code, notes, and snippets.

View pinglunliao's full-sized avatar

pinglunliao pinglunliao

View GitHub Profile
import random;
unsortData = random.sample(range(100), 10)
def bubble_sort(List):
for j in range(len(List)-1,0,-1):
flag = True
for i in range(0, j):
if List[i] > List[i+1]:
flag = False
List[i], List[i+1] = List[i+1], List[i]
import random;
unsortData = random.sample(range(100), 10)
def selection_sort(L):
N = len(L)
exchanges_count = 0
for i in range(N-1):
min_index = i
for j in range(i+1, N):
if L[min_index] > L[j]:
import random;
unsortData = random.sample(range(100), 10)
def insertion_sort(lst):
if len(lst) == 1:
return lst
for i in range(1, len(lst)):
temp = lst[i]
j = i - 1
@pinglunliao
pinglunliao / WifiCar.ino
Created April 1, 2017 07:20
Controlling a Wifi Car via web page
/*
* WifiCar.ino
*
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsServer.h>
int redColor = 0, greenColor = 0, blueColor = 0; // 三色LED燈顏色數值
int rLedPin = 9, gLedPin = 10, bLedPin = 11; // 三色燈在Nano上的數位腳位
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(rLedPin, OUTPUT);
pinMode(gLedPin, OUTPUT);
pinMode(bLedPin, OUTPUT);
package holan.tw;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
/*
* 程式碼參考來源 https://github.com/SJHOne/MintDuino-Repeat-After-Me-Game
*/
#define BUTTON_BASE 2 // 按鈕腳位 2 ~ 4
#define BUZZER_PIN 6 // 蜂鳴器腳位 6
#define LED_BASE 7 // LED 腳位 7 ~ 9
#define WINSTATE 12 // 在一回合中,最多需要回答 12 次的聲音頻率,須為 4 的倍數
#define RESPONSETIME 3000 // 每回合中,回答每個聲音頻率之間的等待時間
package holan.tw;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
#include <SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial CAR_BT(11,12); //定義 PIN11 及 PIN12 分別為 RX 及 TX 腳位
/* Input for leftMotor:
IN1 IN2 Action
LOW LOW Stop
HIGH LOW Forward
LOW HIGH Backward