Nova postagem

Pesquisar

Discussão
· Maio 15, 2024

【Coding Puzzle】 "Esthetic Numbers"

Hello,

I would like you to propose this challenge.

It has been created by the CodeWars community here: https://www.codewars.com/kata/6523a71df7666800170a1954/python

I will copy and paste the description:

 

🔡🟢 DESCRIPTION:

A number is Esthetic if, in any base from base2 up to base10, the absolute difference between every pair of its adjacent digits is constantly equal to 1.

num = 441 (base10)
// Adjacent pairs of digits:
// |4, 4|, |4, 1|
// The absolute difference is not constant
// 441 is not Esthetic in base10

441 in base4 = 12321
// Adjacent pairs of digits:
// |1, 2|, |2, 3|, |3, 2|, |2, 1|
// The absolute difference is constant and is equal to 1
// 441 is Esthetic in base4

Given a positive integer num, implement a function that returns an array containing the bases (as integers from 2 up to 10) in which num results to be Esthetic, or an empty array [] if no base makes num Esthetic.

Examples

10 ➞ [2, 3, 8, 10]
// 10 in base2 = 1010
// 10 in base3 = 101
// 10 in base8 = 12
// 10 in base10 = 10

23 ➞ [3, 5, 7, 10]
// 23 in base3 = 212
// 23 in base5 = 43
// 23 in base7 = 32
// 23 in base10 = 23

666 ➞ [8]
// 666 in base8 = 1232

 

The initial Python code is just:

def esthetic(num):
    pass

 

And the Unit Tests are:

import codewars_test as test
from solution import esthetic

@test.describe("Fixed tests")
def fixed_tests():
    @test.it('Basic test Cases')
    def basic_test_cases():
        test.assert_equals(esthetic(10), [2, 3, 8, 10], "Example #1")
        test.assert_equals(esthetic(23), [3, 5, 7, 10], "Example #2")
        test.assert_equals(esthetic(666), [8], "Example #3")
        test.assert_equals(esthetic(13), [5, 6])
        test.assert_equals(esthetic(1), [2, 3, 4, 5, 6, 7, 8, 9, 10])
        test.assert_equals(esthetic(9), [4, 7, 9, 10])
        test.assert_equals(esthetic(74), [])
        test.assert_equals(esthetic(740), [4, 6, 9])
        test.assert_equals(esthetic(928), [])
        test.assert_equals(esthetic(259259), [9])
        test.assert_equals(esthetic(883271), [])
        test.assert_equals(esthetic(1080898), [7])
        test.assert_equals(esthetic(1080899), [])

 

 

 

 

My solution was:

def esthetic(num):
    def to_base(n, base):
        """Convert number n to a given base and return the digits as a list."""
        digits = []
        while n:
            digits.append(n % base)
            n //= base
        return digits[::-1]  # reverse the list to get the correct order

    def is_esthetic_in_base(digits):
        """Check if the given list of digits is esthetic."""
        for i in range(1, len(digits)):
            if abs(digits[i] - digits[i - 1]) != 1:
                return False
        return True

    esthetic_bases = []

    for base in range(2, 11):
        digits = to_base(num, base)
        if is_esthetic_in_base(digits):
            esthetic_bases.append(base)

    return esthetic_bases

 

 

How would you like to solve it using ObjectScript or any other prefered programming language?

4 Comments
Discussão (4)1
Entre ou crie uma conta para continuar
Artigo
· Maio 15, 2024 2min de leitura

Retrieve images using vector search (1)

Hi Community,

In this article, I will introduce my application iris-image-vector-search.
The image vector retrieval demo uses IRIS Embedded Python and OpenAI CLIP model to convert images into 512 dimensional vector data. Through the new feature of Vector Search, VECTOR-COSINE is used to calculate similarity and display high similarity images.

Application direction of image retrieval  

Image retrieval has important application scenarios in the medical field, and using image retrieval can greatly improve work efficiency. Image retrieval can also be applied in the following fields, such as:

 

  • Image retrieval systems can be used to search for medical image data related to their research topic, for data analysis, pattern recognition, and research, accelerating the process of scientific research.
  • The images in the medical imaging database can be used for the education and training of medical students. Through image retrieval, students can search and compare different types of cases, deepening their understanding of disease characteristics and diagnostic methods.
  •  Image retrieval can be used to assist doctors in diagnosis. By comparing medical imaging data of patients (such as X-rays, CT scans, MRI, etc.) and providing reference images of similar cases through a knowledge base, doctors can quickly obtain relevant information and improve diagnostic accuracy.  

How to use it

Prerequisites

Make sure you have git and Docker desktop installed.

Installation

  • Clone/git pull the repo into any local directory

git clone https://github.com/yueshan239/iris-image-vector-search.git
  • Open the terminal in this directory and run

docker-compose build

    This process will take some time

 

  • Run the IRIS container

docker-compose up -d

 

  • Open the terminal in `vue` directory and run

docker-compose build

  • Run the nginx container

docker-compose up -d

 Visit the address below

http://localhost:8080/

Accessing this page indicates that we have successfully run it.

Discussão (0)1
Entre ou crie uma conta para continuar
Discussão (0)0
Entre ou crie uma conta para continuar
Anúncio
· Maio 15, 2024

Documentation New Look

The InterSystems documentation new look is pretty awesome. The integrated pervious release documentation are single page is really useful.

Dark mode and collapse the side bar option is cool!

 

Discussão (0)1
Entre ou crie uma conta para continuar
Artigo
· Maio 14, 2024 11min de leitura

Q&A Chatbot with IRIS and langchain

TL;DR

This article introduces using the langchain framework supported by IRIS for implementing a Q&A chatbot, focusing on Retrieval Augmented Generation (RAG). It explores how IRIS Vector Search within langchain-iris facilitates storage, retrieval, and semantic search of data, enabling precise and up-to-date responses to user queries. Through seamless integration and processes like indexing and retrieval/generation, RAG applications powered by IRIS enable the capabilities of GenAI systems for InterSystems developers.

3 Comments
Discussão (3)2
Entre ou crie uma conta para continuar