I made a risky die with Ruby

I tried to make a risky dice that appears in Hunter Hunter by practicing ruby. There are numbers from 1 to 20, and 20 is a villain.

def risky_daice
  array = []
  puts 'How many times should i shake'
  stop = gets.to_i
  puts 'I'll roll the dice'
  while true
    deme = rand(1..20)
    num = array.push deme
    if deme == 20
      puts deme
      puts 'Ah, it came out'
      p "#{num.count}The villain came out at the second time"
      break
    elsif num.count == stop
      puts deme
      puts 'Stop there'
      p "#{num.count}It shook. Please challenge again"
      break
    else
      puts deme
    end
  end
end
risky_daice
-> % ruby risky_daice.rb

How many times should i shake
20
I'll roll the dice
16
12
4
1
12
8
18
19
15
2
16
5
3
5
5
3
20
Ah, it came out
"The 17th time was a terrible disaster"

Is it good to shake it before the performance?

Recommended Posts

I made a risky die with Ruby
I made a portfolio with Ruby On Rails
Ruby: I made a FizzBuzz program!
I made a GUI with Swing
[Ruby] I made a simple Ping client
I made a rock-paper-scissors app with kotlin
I made a rock-paper-scissors app with android
04. I made a front end with SpringBoot + Thymeleaf
I made a mosaic art with Pokemon images
I made a gender selection column with enum
I made blackjack with Ruby (I tried using minitest)
I made a Ruby extension library in C
I made a LINE bot with Rails + heroku
I tried DI with Ruby
I made a development environment with rails6 + docker + postgreSQL + Materialize.
I made an interpreter (compiler?) With about 80 lines in Ruby.
I made a plugin to execute jextract with Gradle task
I updated my own blackjack made with Ruby for my portfolio
I searched for a web framework with Gem in Ruby
I made a mod that instantly calls a vehicle with Minecraft
I made a shopify app @java
I made a simple recommendation function.
I made a matching app (Android app)
I made a package.xml generation tool.
[Android] I made a pedometer app.
Make a typing game with ruby
I made a command line interface with WinMerge Plugin using JD-Core
[Rails] I made a simple calendar mini app with customized specifications.
I want to add a browsing function with ruby on rails
I made a Ruby container image and moved the Lambda function
I tried a calendar problem in Ruby
I made various Fibonacci sequence functions (Ruby)
I made an eco server with scala
Let's make a smart home with Ruby!
I tried playing with BottomNavigationView a little ①
Extract a part of a string with Ruby
I made a plugin for IntelliJ IDEA
I made a calculator app on Android
I made a new Java deployment tool
I made a bulletin board using Docker 1
I made an app to scribble with PencilKit on a PDF file
[LINE BOT] I made a ramen BOT with Java (Maven) + Heroku + Spring Boot (1)
I made a site that summarizes information on carbohydrate restriction with Vue.js
I made a primality test program in Java
AtCoder Beginner Contest 169 A, B, C with ruby
Creating a browser automation tool with Ruby + Selenium
I made StringUtils.isBlank
I started Ruby
I implemented Ruby with Ruby (and C) (I played with builtin)
Publish the app made with ruby on rails
[Ruby] I want to do a method jump!
I made a rock-paper-scissors game in Java (CLI)
I made a viewer app that displays a PDF
I made a Docker container to run Maven
[Rails] I made a draft function using enum
I built a Code Pipeline with AWS CDK.
Learn Java with Progate → I will explain because I made a basic game myself
I tried to break a block with java (1)
A story that I was really into when I did triple DES with ruby
I checked the number of taxis with Ruby
I made a lock pattern using the volume key with the Android app. Fragment edition