Skip to content

Instantly share code, notes, and snippets.

View junk0612's full-sized avatar
😃

Junichi Kobayashi junk0612

😃
  • ESM, Inc.
  • Saitama, Japan
  • 18:20 (UTC +09:00)
  • X @junk0612
View GitHub Profile
%%
program :
top_compstmt
;
top_compstmt : top_stmts opt_terms
;
top_stmts : none
| top_stmt
%%
program : {
SET_LEX_STATE(EXPR_BEG);
local_push(p, ifndef_ripper(1)+0);
}
top_compstmt
{
/*%%%*/
if ($2 && !compile_for_eval) {
NODE *node = $2;
@junk0612
junk0612 / main.rb
Last active December 4, 2021 09:50
# 以下の BNF で表される数式が書かれたファイルを受け取り、数式をパースし、抽象構文木をJSON形式でファイルに出力します。
#
# expression ::= term | term "+" expression | term "-" expression
# term ::= factor | factor "*" term | factor "/" term
# factor ::= number | "(" expression ")"
# number ::= ("0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9")+
#
# Usage:
# $ ruby main.rb src.txt dst.json
FIELD = [
['G', 'D', 'B', 'A', '', '', ''],
['N', 'K', 'H', 'E', 'C', '', ''],
['U', 'R', 'O', 'L', 'I', 'F', ''],
['2', 'Y', 'V', 'S', 'P', 'M', 'J'],
['', '6', '3', 'Z', 'W', 'T', 'Q'],
['', '', '9', '7', '4', '1', 'X'],
['', '', '', '@', '0', '8', '5']
]
FIELD = [
['A', 'B', 'C', 'D', 'E', 'F'],
['G', 'H', 'I', 'J', 'K', 'L'],
['M', 'N', 'O', 'P', 'Q', 'R'],
['S', 'T', 'U', 'V', 'W', 'X'],
['Y', 'Z', '1', '2', '3', '4'],
['5', '6', '7', '8', '9', '0']
]
DIRECTIONS = [
module Parser
class Parser
def parse(input)
expression(input)
end
private
def expression(input)
node = factor(input)
defmodule Doukaku do
def test(input, expected), do: _judge(expected, _solve(input))
defp _judge(expected, actual) when expected == actual, do: IO.puts("AC")
defp _judge(expected, actual), do: IO.puts("WA(expected: #{expected}, actual: #{actual})")
defp _solve(input), do: _binarise(input) |> _decode |> _calc |> _encode
defp _binarise(input) do
[limit, encoded_input] = String.splitter(input, ":") |> Enum.to_list
package main
import (
"fmt"
"os"
"os/exec"
"github.com/codegangsta/cli"
)
@junk0612
junk0612 / main.rb
Last active January 11, 2017 11:38
def shuffle(num_of_deck, shuffle_procedure)
deck = (0...num_of_deck).to_a
shuffle_procedure.each do |step|
deck = cut(deck, step[0], step[1])
end
deck[0]
end
# デッキをカットする
# draw_begin から draw_end までを引き抜き、逆にして元の位置に差し込む
import java.util.Set;
import java.util.HashSet;
import java.util.TreeSet;
public class Main {
public String solve(String input) {
String[] inputs = input.split(":");
char c = inputs[1].charAt(0);
Set<Character> set = new HashSet<>();
for (char s: inputs[0].toCharArray()) {