31 May 2022

Python Test

Sample program TIC TAC TOE di Python

import random

class TicTacToe:
    def __init__(self):
        self.board = []

    def create_board(self):
        for i in range(3):
            row = []
            for j in range(3):
                row.append('-')
            self.board.append(row)

    def get_random_first_player(self):
        return random.randint(0, 1)

    def fix_spot(self, row, col, player):
        self.board[row][col] = player

    def is_player_win(self, player):
        win = None

        n = len(self.board)

        # checking rows
        for i in range(n):
            win = True
            for j in range(n):
                if self.board[i][j] != player:
                    win = False
                    break
            if win:
                return win

        # checking columns
        for i in range(n):
            win = True
            for j in range(n):
                if self.board[j][i] != player:
                    win = False
                    break
            if win:
                return win

        # checking diagonals
        win = True
        for i in range(n):
            if self.board[i][i] != player:
                win = False
                break
        if win:
            return win

        win = True
        for i in range(n):
            if self.board[i][n - 1 - i] != player:
                win = False
                break
        if win:
            return win
        return False

        for row in self.board:
            for item in row:
                if item == '-':
                    return False
        return True

    def is_board_filled(self):
        for row in self.board:
            for item in row:
                if item == '-':
                    return False
        return True

    def swap_player_turn(self, player):
        return 'X' if player == 'O' else 'O'

    def show_board(self):
        for row in self.board:
            for item in row:
                print(item, end=" ")
            print()

    def start(self):
        self.create_board()

        player = 'X' if self.get_random_first_player() == 1 else 'O'
        while True:
            print(f"Player {player} turn")

            self.show_board()

            # taking user input
            row, col = list(
                map(int, input("Enter row and column numbers to fix spot: ").split()))
            print()

            # fixing the spot
            self.fix_spot(row - 1, col - 1, player)

            # checking whether current player is won or not
            if self.is_player_win(player):
                print(f"Player {player} wins the game!")
                break

            # checking whether the game is draw or not
            if self.is_board_filled():
                print("Match Draw!")
                break

            # swapping the turn
            player = self.swap_player_turn(player)

        # showing the final view of board
        print()
        self.show_board()


# starting the game
tic_tac_toe = TicTacToe()
tic_tac_toe.start()


Check out the sample output of the code.

$ python tic_tac_toe.py 
Player X turn
- - -
- - -
- - -
Enter row and column numbers to fix spot: 1 1

Player O turn
X - -
- - -
- - -
Enter row and column numbers to fix spot: 2 1

Player X turn
X - -
O - -
- - -
Enter row and column numbers to fix spot: 1 2

Player O turn
X X -
O - -
- - -
Enter row and column numbers to fix spot: 1 3

Player X turn
X X O
O - -
- - -
Enter row and column numbers to fix spot: 2 2

Player O turn
X X O
O X -
- - -
Enter row and column numbers to fix spot: 3 3

Player X turn
X X O        
O X -        
- - O
Enter row and column numbers to fix spot: 3 2

Player X wins the game!

X X O
O X -
- X O

20 May 2022

Blogger jadi aneh solved

Sudah lama tidak buka blogger dan sepertinya disusupi malware, soalnya ngelink ke web promosi lain dan ada tampilan-tampilan tambahan yang gak ada di theme dan tidak merasa modif juga.
Tangan udah gatel pengen "set to factory default", tapi nanti malah jadi kerjaan tambahan
Sekarang sudah "berasa" normal, caranya save template. Set ke theme lain save, trus set to theme yang sekarang save refresh, kemudian set lagin theme yang sekarang save refresh

29 July 2021

Antri di BCA selama pandemi, hack the queue

Sebenarnya sudah lama ingin ke BCA karena:

1. Token BCA batre-nya sudah habis, 

2. Kartu ATM terblokir, 

3. Aktifin M-BCA juga plus ganti buku tabungan karena udah kumel 


Datang ke BCA jam 7:45, sengaja biar dapat antrian awal

Karena tidak tahu sistem antriannya seperti apa, saya tanya ke pak Satpam yang jaga

"Pak sudah buka?"

"belum"

"Ada nomor antrian?"

"belum ada juga"

Berjalannya waktu saya akhirnya tahu sistem antriannya, jika ingin dapat nomor awal harus segera ambil posisi duduk di dekat pintu masuk.

nanti satpam akan memberikan nomor sesuai urutan dari deket pintu, terus ke antrian yang di tangga


Setelah itu satpam juga akan mengecek suhu tubuh, sehingga lebih cepat, jadi saat petugas BCA sudah siap hanya tinggal masuk dan menunggu di dalam sesuai nomor yang dipanggil

Saya mendapat nomor antrian B0002 (CS antrian ke-dua), masih termasuk kloter pertama karena CS ada lebih dari 2


Pengalaman hari ini:

"Jadi orang PD aja, langsung naik tangga, tanya satpam, langsung duduk di antrian no1, kayak cewek yang baru dateng itu.. kucluk2 naik langsung duduk padahal ada beberapa yang udah antri dari tadi di bawah .. hadeh"

21 November 2019

Connect raspberry Pi without monitor, keyboard, mouse and hub

Connect raspberry Pi without monitor, keyboard, mouse and hub, connect with LAN cable directly


1. Image install Choose image that you want to install, and click flash button

2. After installing image to micro sd, you need make a file ssh without extension in root directory

3. connect cable between raspberry and your computer, I am using straight cable but actually you can use cross cable 

4. setting computer to automatic ip (DHCP) and ICS enable In this case I using windows 10, so if you using different OS maybe some setting maybe different too Setting Automatic IP (DHCP) Choose obtain ipaddress automatically

Setting internet connection sharing Click wifi network and choose properties. Wifi connect to internet via wifi router, or you can using tethering from your handphone
5. Scanning ip addres for raspberry-pi Scan you network with ip scanner tool, and you will see raspberry using ip 192.168.137.7

6. Connect to raspberry via SSH, enter password : raspberry

Connected Yeah… 7. connect raspberry pi via wifi through wifi router Connect to raspberry via lan cable and then write command Sudo raspi-config

8. Scan open port 22 (ssh) on whole network with ip scanner We found ip 192.168.8.104, this is raspi ip address

9. connect via ssh Success

10. Change ethernet static ip Using command sudo nano /etc/dhcpcd.conf

28 August 2018

testing syntax

 <script type='text/javascript'>
//<![CDATA[
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=App-ID";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
//]]>
</script>